/
LocalStateFunctions.cpp
3232 lines (3004 loc) · 100 KB
/
LocalStateFunctions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2007 Dave Griffiths
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <assert.h>
#include "SchemeHelper.h"
#include "Engine.h"
#include "LocalStateFunctions.h"
#include "Renderer.h"
#include "ShaderCache.h"
using namespace LocalStateFunctions;
using namespace SchemeHelper;
using namespace Fluxus;
// StartSectionDoc-en
// local-state
// The local state functions control rendering either for the current state - or the state of
// the current primitive. In fluxus state means the way that things are displayed,
// either turning on and off rendering features, changing the style of different features, or altering
// the current transform.
// Example:
// EndSectionDoc
// StartSectionDoc-pt
// estado-local
// As funções de estado local controlam a renderização ou do estado
// corrente - ou do estado da primitiva correntemente
// pega(grabbed). Em Fluxus estado significa significa a forma que as
// coisas são mostradas, tanto ligando/desligando opções de render,
// mudando o estilo de diferentes opções, ou alterando a transformação
// corrente.
// Exemplo:
// EndSectionDoc
// StartFunctionDoc-en
// push
// Returns: void
// Description:
// Pushes a copy of the current drawing state to the top of the stack. The drawing state
// contains information about things like the current colour, transformation and hints.
// This function has been superseded by (with-state).
// Example:
// (colour (vector 1 0 0)) ; set current colour to red
// (push) ; copy and push drawing state
// (colour (vector 0 1 0)) ; set current colour to green
// (draw-cube) ; draws a green cube
// (pop) ; forget old drawing state
// ; current colour is now red again
// EndFunctionDoc
// StartFunctionDoc-pt
// push
// Retorna: void
// Descrição:
// Empurra uma cópia do estado corrente de desenho para o topo da
// pilha. O estado de desenho contém informação sobre coisas como
// cor corrente, transformação e dicas(hints).
// Exemplo:
// (colour (vector 1 0 0)) ; aplica cor corrente pra vermelho
// (push) ; copia e empurra estado de desenho
// (colour (vector 0 1 0)) ; aplica cor corrente pra verde
// (draw-cube) ; desenha um cubo verde
// (pop) ; esquece estado de desenho antigo
// ; cor corrente é vermelha de novo.
// EndFunctionDoc
Scheme_Object *push(int argc, Scheme_Object **argv)
{
// record the push on the grabstack too - this means we can combine them
Engine::Get()->PushGrab(0);
Engine::Get()->Renderer()->PushState();
return scheme_void;
}
// StartFunctionDoc-en
// pop
// Returns: void
// Description:
// Destroys the current drawing state, and sets the current one to be the previously pushed
// one in the stack. The drawing state contains information about things like the current
// colour, transformation and hints.
// This function has been superseded by (with-state).
// Example:
// (colour (vector 1 0 0)) ; set current colour to red
// (push) ; copy and push drawing state
// (colour (vector 0 1 0)) ; set current colour to green
// (draw-cube) ; draws a green cube
// (pop) ; forget old drawing state
// ; current colour is now red again
// EndFunctionDoc
// StartFunctionDoc-pt
// pop
// Retorna: void
// Descrição:
// Destrói o estado de desenho corrente, e aplica para o estado
// corrente o antigo anteriormente empurrado na pilha. O estado
// de desenho contém informação sobre coisas como cor corrente,
// transformação e dicas(hints).
// Exemplo:
// (colour (vector 1 0 0)) ; aplica cor corrente pra vermelho
// (push) ; copia e empurra estado de desenho
// (colour (vector 0 1 0)) ; aplica cor corrente pra verde
// (draw-cube) ; desenha um cubo verde
// (pop) ; esquece estado de desenho antigo
// ; cor corrente é vermelha de novo.
// EndFunctionDoc
Scheme_Object *pop(int argc, Scheme_Object **argv)
{
Engine::Get()->PopGrab();
Engine::Get()->Renderer()->PopState();
return scheme_void;
}
// StartFunctionDoc-en
// grab object-id
// Returns: void
// Description:
// Grabs the specified object. Once an object has grabbed it's state can be modified using
// the same commands used to set the current drawing state. (ungrab) needs to be used to
// return to the normal drawing state. Grabbing can also be stacked, in which case ungrab
// pops to the last grabbed primitive.
// This function has been superseded by (with-primitive).
// Example:
// (colour (vector 1 0 0)) ; set the current colour to red
// (define mycube (build-cube)) ; makes a red cube
// (grab mycube)
// (colour (vector 0 1 0)) ; sets the cubes colour to green
// (ungrab) ; return to normal state
// EndFunctionDoc
// StartFunctionDoc-pt
// grab id-do-objeto
// Retorna: void
// Descrição:
// Pega o objeto especificado. Uma vez que o objeto foi pego seu
// estado pode ser modificado usando os mesmos comandos usados pra
// ajustar o estado de desenho atual. (ungrab) precisa ser usado para
// retornar ao estado de desenho normal. "grabbing" também pode ser
// "pilhado", neste caso (ungrab) pula para a próxima primitiva pega.
// Exemplo:
// (colour (vector 1 0 0)) ; aplica a cor atual para vermelho
// (define mycube (build-cube)) ; faz um cubo vermelho
// (grab mycube)
// (colour (vector 0 1 0)) ; aplica a cor do cubo como verde
// (ungrab) ; retorna ao estado normal
// EndFunctionDoc
Scheme_Object *grab(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("grab", "i", argc, argv);
Engine::Get()->PushGrab(IntFromScheme(argv[0]));
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// ungrab
// Returns: void
// Description:
// Ungrabs the current object, and either returns to the normal drawing state,
// or pops to the last grabbed primitive.
// This function has been superseded by (with-primitive).
// Example:
// (colour (vector 1 0 0)) ; set the current colour to red
// (define mycube (build-cube)) ; makes a red cube
// (grab mycube)
// (colour (vector 0 1 0)) ; sets the cubes colour to green
// (ungrab) ; return to normal state
// EndFunctionDoc
// StartFunctionDoc-pt
// ungrab
// Retorna: void
// Descrição:
// Solta o objeto pego atualmente, e ou retorna ao estado de desenho
// normal, ou tira a ultima primitiva pega do topo da pilha.
// Exemplo:
// (colour (vector 1 0 0)) ; aplica a cor atual para vermelho
// (define mycube (build-cube)) ; faz um cubo vermelho
// (grab mycube)
// (colour (vector 0 1 0)) ; aplica a cor verde ao cubo
// (ungrab) ; retorna ao estado normal
// EndFunctionDoc
Scheme_Object *ungrab(int argc, Scheme_Object **argv)
{
Engine::Get()->PopGrab();
return scheme_void;
}
// StartFunctionDoc-en
// apply-transform optional-object-id
// Returns: void
// Description:
// Applies the current object transform to the vertex positions of the current object and
// sets it's transform to identity. Will also use the optional id passed in for the aniquated
// version of this command
// Example:
// (rotate (vector 45 0 0))
// (define mycube (build-cube)) ; makes a cube with a rotation
// (with-primitive mycube (apply-transform)) ; applies the rotation to the points of the cube
// EndFunctionDoc
// StartFunctionDoc-pt
// apply-transform id-do-objeto
// Retorna: void
// Descrição:
// Aplica a transformação corrente às posições dos vértices do objeto
// dado e ajusta sua tranformação para identidade.
// Exemplo:
// (rotate (vector 45 0 0))
// (define mycube (build-cube)) ; faz um cubo com uma rotação
// (with-primitive mycube (apply-transform)) ; aplica a rotação aos pontos do cubo
// EndFunctionDoc
Scheme_Object *apply(int argc, Scheme_Object **argv)
{
DECL_ARGV();
if (argc==1)
{
ArgCheck("apply-transform", "i", argc, argv);
Engine::Get()->Renderer()->GetPrimitive(IntFromScheme(argv[0]))->ApplyTransform();
}
else
{
if (Engine::Get()->Grabbed())
{
Engine::Get()->Grabbed()->ApplyTransform();
}
}
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// opacity value
// Returns: void
// Description:
// Sets the opacity of the current drawing state, or the current primitive.
// Example:
// (opacity 0.5)
// (define mycube (build-cube)) ; makes a half transparent cube
// EndFunctionDoc
// StartFunctionDoc-pt
// opacity valor
// Retorna: void
// Descrição:
// Ajusta a opacidade do estado de desenho atual, ou da primitiva pega
// atualmente.
// Exemplo:
// (opacity 0.5)
// (define mycube (build-cube)) ; faz um cubo semi-transparente.
// EndFunctionDoc
Scheme_Object *opacity(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("opacity", "f", argc, argv);
Engine::Get()->State()->Opacity=FloatFromScheme(argv[0]);
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// wire-opacity value
// Returns: void
// Description:
// Sets the wireframe opacity of the current drawing state, or the current primitive.
// Example:
// (hint-none)
// (hint-wire)
// (backfacecull 0)
// (line-width 5)
// (wire-colour (vector 1 1 1))
// (wire-opacity 0.5)
// (build-cube) ; makes a half transparent wireframe cube
// EndFunctionDoc
// StartFunctionDoc-pt
// wire-opacity valor
// Retorna: void
// Descrição:
// Ajusta a opacidade das beiradas da malha no estado ou da primitiva atual.
// Exemplo:
// (hint-none)
// (hint-wire)
// (backfacecull 0)
// (line-width 5)
// (wire-colour (vector 1 1 1))
// (wire-opacity 0.5)
// (build-cube) ; makes a half transparent wireframe cube
// EndFunctionDoc
Scheme_Object *wire_opacity(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("wire-opacity", "f", argc, argv);
Engine::Get()->State()->WireOpacity=FloatFromScheme(argv[0]);
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// shinyness value
// Returns: void
// Description:
// Sets the shinyness of the current drawing state, or the current primitive.
// This value sets the tightness of the specular highlight.
// Example:
// (shinyness 100)
// (specular (vector 1 1 1)) ; sets the specular colour
// (define mysphere (build-sphere 10 10)) ; makes a shiny cube
// EndFunctionDoc
// StartFunctionDoc-pt
// shinyness valor
// Retorna: void
// Descrição:
// Ajusta o brilho do estado atual de desenho, ou da primitiva
// atualmente pega. Esse valor ajusta a densidade do brilho
// especular.
// Exemplo:
// (shinyness 100)
// (specular (vector 1 1 1)) ; ajusta a cor especular
// (define mysphere (build-sphere 10 10)) ; makes a shiny cube
// EndFunctionDoc
Scheme_Object *shinyness(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("shinyness", "f", argc, argv);
Engine::Get()->State()->Shinyness=FloatFromScheme(argv[0]);
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// colour colour-vector
// Returns: void
// Description:
// Sets the colour of the current drawing state, or the current primitive.
// Example:
// (colour (vector 1 0.5 0.1)) ; mmm orange...
// (define mycube (build-cube)) ; makes an orange cube
// EndFunctionDoc
// StartFunctionDoc-pt
// colour vetor-cor
// Retorna: void
// Descrição:
// Ajusta a cor do estado de desenho atual, ou a primitiva atualmente pega.
// Exemplo:
// (colour (vector 1 0.5 0.1)) ; mmm laranja...
// (define mycube (build-cube)) ; faz um cubo laranja
// EndFunctionDoc
Scheme_Object *colour(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("colour", "c", argc, argv);
dColour c=ColourFromScheme(argv[0], Engine::Get()->State()->ColourMode);
Engine::Get()->State()->Colour=c;
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// colour-mode mode
// Returns: void
// Description:
// Changes the way Fluxus interprets colour data for the current drawing
// state, or the current primitive.
// Colourmode symbols can consist of: rgb hsv
// Example:
// (clear)
// (colour-mode 'hsv)
//
// (for ((x (in-range 0 10)))
// (translate (vector 1 0 0))
// (colour (vector (/ x 10) 1 1))
// (build-cube))
// EndFunctionDoc
// StartFunctionDoc-pt
// colour-mode modo
// Returns: void
// Description:
// Muda a forma como Fluxus interpreta dados de cor para o estado de
// desenho ou da primitiva atual.
// Os simbolos dos modos de cor são: rgb hsv
// Exemplo:
// (clear)
// (colour-mode 'hsv)
//
// (for ((x (in-range 0 10)))
// (translate (vector 1 0 0))
// (colour (vector (/ x 10) 1 1))
// (build-cube))
// EndFunctionDoc
Scheme_Object *colour_mode(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("colour-mode", "S", argc, argv);
string mode=SymbolName(argv[0]);
if (mode=="rgb") Engine::Get()->State()->ColourMode=MODE_RGB;
else if (mode=="hsv") Engine::Get()->State()->ColourMode=MODE_HSV;
else Trace::Stream<<"colour mode not recognised: "<<mode<<endl;
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// rgb->hsv colour-vector
// Returns: vector
// Description:
// Converts the RGB colour to HSV.
// Example:
// (rgb->hsv (vector 1 0.5 0.1))
// EndFunctionDoc
// StartFunctionDoc-pt
// rgb->hsv vetor-cor
// Retorna: vetor
// Descrição:
// Converte a cor RGB para HSV.
// Exemplo:
// (rgb->hsv (vector 1 0.5 0.1))
// EndFunctionDoc
Scheme_Object *rgbtohsv(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("rgb->hsv", "v", argc, argv);
float rgb[4], hsv[4];
int vec_size = SCHEME_VEC_SIZE(argv[0]);
FloatsFromScheme(argv[0], rgb, vec_size);
dColour::RGBtoHSV(rgb[0], rgb[1], rgb[2], hsv);
hsv[3] = rgb[3];
MZ_GC_UNREG();
return FloatsToScheme(hsv, vec_size);
}
// StartFunctionDoc-en
// hsv->rgb colour-vector
// Returns: vector
// Description:
// Converts the HSV colour to RGB.
// Example:
// (clear)
// (for* ((x (in-range 0 10)) ; builds a 10x10 HSV colour pattern
// (y (in-range 0 10)))
// (identity)
// (translate (vector x y 0))
// (colour (hsv->rgb (vector (/ x 10) (/ y 10) 1)))
// (build-cube))
// EndFunctionDoc
// StartFunctionDoc-pt
// hsv->rgb vetor-cor
// Retorna: vetor
// Descrição:
// Converte a cor HSV para RGB
// Exemplo:
// (clear)
// (for* ((x (in-range 0 10)) ; builds a 10x10 HSV colour pattern
// (y (in-range 0 10)))
// (identity)
// (translate (vector x y 0))
// (colour (hsv->rgb (vector (/ x 10) (/ y 10) 1)))
// (build-cube))
// EndFunctionDoc
Scheme_Object *hsvtorgb(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("hsv->rgb", "v", argc, argv);
float hsv[4], rgb[4];
int vec_size = SCHEME_VEC_SIZE(argv[0]);
FloatsFromScheme(argv[0], hsv, vec_size);
dColour::HSVtoRGB(hsv[0], hsv[1], hsv[2], rgb);
rgb[3] = hsv[3];
MZ_GC_UNREG();
return FloatsToScheme(rgb, vec_size);
}
// StartFunctionDoc-en
// wire-colour colour-vector
// Returns: void
// Description:
// Sets the wire frame colour of the current drawing state, or the current
// primitive. Visible with (hint-wire) on most primitives.
// Example:
// (wire-colour (vector 1 1 0)) ; set yellow as current wire colour
// (hint-wire)
// (define mycube (build-cube)) ; makes a cube with yellow wireframe
// EndFunctionDoc
// StartFunctionDoc-pt
// wire-colour vetor-cor
// Retorna: void
// Descrição:
// Ajusta a cor do "wire frame" do estado de desenho atual, ou a
// primitiva atualmente pega. Visível com (hint-wire) na maioria das
// primitivas.
// Exemplo:
// (wire-colour (vector 1 1 0)) ; ajusta a cor do fio como amarelo
// (hint-wire)
// (define mycube (build-cube)) ; faz um cubo com wireframe amarelo
// EndFunctionDoc
Scheme_Object *wire_colour(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("wire-colour", "c", argc, argv);
dColour c=ColourFromScheme(argv[0], Engine::Get()->State()->ColourMode);
Engine::Get()->State()->WireColour=c;
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// normal-colour colour-vector
// Returns: void
// Description:
// Sets the normals frame colour of the current drawing state, or the current
// primitive. Visible with (hint-normal) on most primitives.
// Example:
// (normal-colour (vector 1 1 0)) ; set yellow as current normals colour
// (hint-normal)
// (define mycube (build-cube)) ; makes a cube with yellow wireframe
// EndFunctionDoc
Scheme_Object *normal_colour(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("normal-colour", "c", argc, argv);
dColour c=ColourFromScheme(argv[0], Engine::Get()->State()->ColourMode);
Engine::Get()->State()->NormalColour=c;
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// specular colour-vector
// Returns: void
// Description:
// Sets the specular colour of the current drawing state, or the current
// primitive.
// Example:
// (specular (vector 0 0 1)) ; set blue as specular colour
// (define mysphere (build-sphere 10 10)) ; makes a shiny blue sphere
// EndFunctionDoc
// StartFunctionDoc-pt
// specular vetor-cor
// Retorna: void
// Descrição:
// Ajusta a cor especular do estado de desenho corrente, ou o objeto
// atualmente pego.
// Exemplo:
// (specular (vector 0 0 1)) ; ajusta azul como a cor especular
// (define mysphere (build-sphere 10 10)) ; faz uma esfera azul brilhante.
// EndFunctionDoc
Scheme_Object *specular(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("specular", "c", argc, argv);
Engine::Get()->State()->Specular=ColourFromScheme(argv[0]);
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// ambient colour-vector
// Returns: void
// Description:
// Sets the ambient colour of the current drawing state, or the current
// primitive.
// Example:
// (ambient (vector 0 0 1)) ; set blue as ambient colour
// (define mysphere (build-sphere 10 10)) ; makes a boringly blue sphere
// EndFunctionDoc
// StartFunctionDoc-pt
// ambient vetor-cor
// Retorna: void
// Descrição:
// Ajusta a cor ambiente do estado de desenho corrente, ou a primitiva
// atualmente pega.
// Exemplo:
// (ambient (vector 0 0 1)) ; ajusta a cor ambiente como azul
// (define mysphere (build-sphere 10 10)) ; faz uma chata esfera azul
// EndFunctionDoc
Scheme_Object *ambient(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("ambient", "c", argc, argv);
Engine::Get()->State()->Ambient=ColourFromScheme(argv[0]);
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// emissive value
// Returns: void
// Description:
// Sets the emissive colour of the current drawing state, or the current
// primitive.
// Example:
// (emissive (vector 0 0 1)) ; set blue as emissive colour
// (define mysphere (build-sphere 10 10)) ; makes an bright blue sphere
// EndFunctionDoc
// StartFunctionDoc-pt
// emissive valor
// Retorna: void
// Descrição:
// Ajusta a cor emissiva do estado de desenho atual, ou da primitiva
// atualmente pega.
// Exemplo:
// (emissive (vector 0 0 1)) ; ajusta a cor emissiva para azul
// (define mysphere (build-sphere 10 10)) ; faz uma esfera azul brilhante
// EndFunctionDoc
Scheme_Object *emissive(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("emissive", "c", argc, argv);
Engine::Get()->State()->Emissive=ColourFromScheme(argv[0]);
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// identity
// Returns: void
// Description:
// Sets the drawing state transform to identity, on the state stack, or the current primitive.
// Example:
// (define mycube (with-state
// (scale (vector 2 2 2)) ; set the current scale to double in each dimension
// (build-cube))) ; make a scaled cube
//
// (with-primitive mycube
// (identity)) ; erases the transform and puts the cube back to its original state
// EndFunctionDoc
// StartFunctionDoc-pt
// identity
// Retorna: void
// Descrição:
// Ajusta a transformação do estado de desenho para identidade, no
// estado da pilha, ou a primitiva atualmente pega.
// Exemplo:
// (define mycube (with-state
// (scale (vector 2 2 2)) ; ajusta o tamanho atual pro dobro em cada dimensão
// (build-cube))) ; faz um cubo aumentado
//
// (with-primitive mycube
// (identity)) ; apaga a transformação e coloca o cubo de volta ao seu
// ; estado original
// EndFunctionDoc
Scheme_Object *flux_identity(int argc, Scheme_Object **argv)
{
Engine::Get()->State()->Transform.init();
return scheme_void;
}
// StartFunctionDoc-en
// concat matrix
// Returns: void
// Description:
// Concatenates (multiplies) a matrix on to the current drawing state or current primitive.
// Example:
// (define mymatrix (mrotate (vector 0 45 0))) ; make a matrix
// (concat mymatrix) ; concat it into the current state
// (build-cube) ; make a cube with this rotation
// EndFunctionDoc
// StartFunctionDoc-pt
// concat matrix
// Retorna: void
// Descrição:
// Concatena (multiplica) uma matriz para o estado de desenho atual ou
// primitiva pega.
// Exemplo:
// (define mymatrix (mrotate (vector 0 45 0))) ; faz uma matriz
// (concat mymatrix) ; concat ela no estado atual
// (build-cube) ; faz um cubo com esta rotação
// EndFunctionDoc
Scheme_Object *concat(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("concat", "m", argc, argv);
dMatrix m;
FloatsFromScheme(argv[0],m.arr(),16);
Engine::Get()->State()->Transform*=m;
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// translate vector
// Returns: void
// Description:
// Applies a translation to the current drawing state transform or current primitive.
// Example:
// (translate (vector 0 1.4 0)) ; translates the current transform up a bit
// (build-cube) ; build a cube with this transform
// EndFunctionDoc
// StartFunctionDoc-pt
// translate vetor
// Retorna: void
// Descrição:
// Aplica uma translação ao estado de desenho atual ou primitiva pega
// Exemplo:
// (translate (vector 0 1.4 0)) ; translada a transformação atual pra
// ; cima um pouco
// (build-cube) ; constrói um cubo com esta transformação
// EndFunctionDoc
Scheme_Object *translate(int argc, Scheme_Object **argv)
{
DECL_ARGV();
ArgCheck("translate", "v", argc, argv);
dVector t;
FloatsFromScheme(argv[0],t.arr(),3);
Engine::Get()->State()->Transform.translate(t.x,t.y,t.z);
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// rotate vector-or-quaternion
// Returns: void
// Description:
// Applies a rotation to the current drawing state transform or current primitive.
// Example:
// (rotate (vector 0 45 0)) ; turns 45 degrees in the Y axis
// (build-cube) ; build a cube with this transform
// EndFunctionDoc
// StartFunctionDoc-pt
// rotate vetor-ou-quaternion
// Retorna: void
// Descrição:
// Aplica uma rotação ao estado de desenho atual ou primitiva pega.
// Exemplo:
// (rotate (vector 0 45 0)) ; vira 45 graus no eixo Y
// (build-cube) ; constrói um cubo com esta transformação
// EndFunctionDoc
Scheme_Object *rotate(int argc, Scheme_Object **argv)
{
DECL_ARGV();
if (!SCHEME_VECTORP(argv[0])) scheme_wrong_type("rotate", "vector", 0, argc, argv);
if (SCHEME_VEC_SIZE(argv[0])==3)
{
// euler angles
float rot[3];
FloatsFromScheme(argv[0],rot,3);
Engine::Get()->State()->Transform.rotxyz(rot[0],rot[1],rot[2]);
}
else if (SCHEME_VEC_SIZE(argv[0])==4)
{
// quaternion
dQuat a;
FloatsFromScheme(argv[0],a.arr(),4);
dMatrix m=a.toMatrix();
Engine::Get()->State()->Transform*=m;
}
else
{
Trace::Stream<<"rotate - wrong number of elements in vector"<<endl;
}
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// scale vector
// Returns: void
// Description:
// Applies a scale to the current drawing state transform or current primitive.
// Example:
// (scale (vector 0.5 0.5 0.5)) ; scales the current transform to half the size
// (build-cube) ; build a cube with this transform
// EndFunctionDoc
// StartFunctionDoc-pt
// scale vetor
// Retorna: void
// Descrição:
// Aplica uma escalagem ao estado de desenho atual ou primitiva pega.
// Exemplo:
// (scale (vector 0.5 0.5 0.5)) ; escala a tranformação atual para
// ; metade do tamanho
// (build-cube) ; constrói um cubo com esta transformação
// EndFunctionDoc
Scheme_Object *scale(int argc, Scheme_Object **argv)
{
DECL_ARGV();
if ((!SCHEME_VECTORP(argv[0]) || (SCHEME_VEC_SIZE(argv[0])!=3))
&& (!SCHEME_NUMBERP(argv[0])))
scheme_wrong_type("scale", "vector size 3 or number", 0, argc, argv);
if (SCHEME_VECTORP(argv[0]))
{
dVector t;
FloatsFromScheme(argv[0],t.arr(),3);
Engine::Get()->State()->Transform.scale(t.x,t.y,t.z);
}
else
{
float t=FloatFromScheme(argv[0]);
Engine::Get()->State()->Transform.scale(t,t,t);
}
MZ_GC_UNREG();
return scheme_void;
}
// StartFunctionDoc-en
// get-transform
// Returns: matrix-vector
// Description:
// Returns a matrix representing the current state transform or for the
// current primitive.
// Example:
// (clear)
// ; build a hierarchy
// (define a
// (with-state
// (colour (vector 1 0.5 0.5))
// (build-cube)))
// (define b (with-state
// (colour (vector 0.5 1 0.5))
// (parent a)
// (translate (vector 2 0 0))
// (build-cube)))
// (define c (with-state
// (colour (vector 0.5 0.5 1))
// (parent b)
// (translate (vector 2 0 0))
// (build-cube)))
//
// (define (animate)
// ; animate the heirarchy
// (with-primitive a (rotate (vector 0 0 (sin (time)))))
// (with-primitive b (rotate (vector 0 0 (sin (time)))))
// (with-primitive c (rotate (vector 0 0 (sin (time)))))
//
// ; position a yellow sphere with c's local transform
// (with-state
// (concat (with-primitive c (get-transform)))
// (opacity 0.5)
// (colour (vector 1 1 0))
// (draw-sphere))
//
// ; position a purple sphere with c's global transform
// (with-state
// (concat (with-primitive c (get-global-transform)))
// (opacity 0.5)
// (colour (vector 1 0 1))
// (draw-sphere)))
//
// (every-frame (animate))
// EndFunctionDoc
// StartFunctionDoc-pt
// get-transform
// Retorna: vetor-matriz
// Descrição:
// Retorna uma matriz representando o estado de tranformação corrente
// ou para a primitiva pega.
// Exemplo:
// (clear)
// ; build a hierarchy
// (define a
// (with-state
// (colour (vector 1 0.5 0.5))
// (build-cube)))
// (define b (with-state
// (colour (vector 0.5 1 0.5))
// (parent a)
// (translate (vector 2 0 0))
// (build-cube)))
// (define c (with-state
// (colour (vector 0.5 0.5 1))
// (parent b)
// (translate (vector 2 0 0))
// (build-cube)))
//
// (define (animate)
// ; animate the heirarchy
// (with-primitive a (rotate (vector 0 0 (sin (time)))))
// (with-primitive b (rotate (vector 0 0 (sin (time)))))
// (with-primitive c (rotate (vector 0 0 (sin (time)))))
//
// ; position a yellow sphere with c's local transform
// (with-state
// (concat (with-primitive c (get-transform)))
// (opacity 0.5)
// (colour (vector 1 1 0))
// (draw-sphere))
//
// ; position a purple sphere with c's global transform
// (with-state
// (concat (with-primitive c (get-global-transform)))
// (opacity 0.5)
// (colour (vector 1 0 1))
// (draw-sphere)))
//
// (every-frame (animate))
// EndFunctionDoc
Scheme_Object *get_transform(int argc, Scheme_Object **argv)
{
return FloatsToScheme(Engine::Get()->State()->Transform.arr(),16);
}
// StartFunctionDoc-en
// get-global-transform
// Returns: matrix-vector
// Description:
// Returns a matrix representing the current global transform for the
// current primitive.
// Example:
// (clear)
// ; build a hierarchy
// (define a
// (with-state
// (colour (vector 1 0.5 0.5))
// (build-cube)))
// (define b (with-state
// (colour (vector 0.5 1 0.5))
// (parent a)
// (translate (vector 2 0 0))
// (build-cube)))
// (define c (with-state
// (colour (vector 0.5 0.5 1))
// (parent b)
// (translate (vector 2 0 0))
// (build-cube)))
//
// (define (animate)
// ; animate the heirarchy
// (with-primitive a (rotate (vector 0 0 (sin (time)))))
// (with-primitive b (rotate (vector 0 0 (sin (time)))))
// (with-primitive c (rotate (vector 0 0 (sin (time)))))
//
// ; position a yellow sphere with c's local transform
// (with-state
// (concat (with-primitive c (get-transform)))
// (opacity 0.5)
// (colour (vector 1 1 0))
// (draw-sphere))
//
// ; position a purple sphere with c's global transform
// (with-state
// (concat (with-primitive c (get-global-transform)))
// (opacity 0.5)
// (colour (vector 1 0 1))
// (draw-sphere)))
//
// (every-frame (animate))
// EndFunctionDoc
// StartFunctionDoc-pt
// get-global-transform
// Retorna: matriz-vetor
// Descrição:
// Retorna uma matriz representando a transformação global atual para
// a primitiva atual