-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderMod.f90
2432 lines (2275 loc) · 92.9 KB
/
renderMod.f90
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
! vim:fdm=marker
! requires lineParse.f90
! requires quaternion.f90
! DATE: the same as for the 'view' programs
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!80
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!80
module renderMod
type object
character(80) :: name
integer :: np !number of points
integer :: nt !number of triangles
integer :: nvn !number of vertex normals
character(5) :: mode !(point|wire|solid)
real(4) :: mass, radius, stiffness, poisson, friction
logical :: transparency ! flag for certain point-wise plotting
real(4), allocatable, dimension(:,:) :: point,ip,rp,sp
real(4), allocatable, dimension(:,:) :: vertnorm, ivn, rvn
integer, allocatable, dimension(:,:) :: color, connect
integer, allocatable, dimension(:) :: smooth !average normals or not
integer, allocatable, dimension(:,:) :: tri
integer, allocatable, dimension(:) :: sortID !sorted list of IDs
! changable values
real(4), dimension(3) :: po !position offset wrt global coordinates
real(4), dimension(3) :: velocity !changes the offset position
real(4), dimension(4) :: orient !orientation quaternion
real(4), dimension(4) :: spin !local rotation rate (changes orientation)
integer :: collidedWithObjID !what object did this object collide with?
contains
procedure :: ene => objectEnergy
procedure :: momentum => objectMomentum
procedure :: scale => objectScale
procedure :: reallocate => objectReallocate
procedure :: addPoint => objectAddPoint
procedure :: findVertexNormal
procedure :: findTriangleNormal
procedure :: closestTriangle
procedure :: mkconnections
procedure :: sortNodes !only populates 'sortID'
end type object
type screen
character(80) :: fbpath, tmpdir, dumpName
integer :: width, height, line, timeout, sr_x, sr_y
real(4) :: FOVx, FOVy
integer, dimension(2,2) :: sr
real(4) :: dt, dtheta, ds
! real(4), dimension(3) :: camera_p, camera_vel
real(4), dimension(4) :: globalrotor !, camerarotor, camera_spin
logical :: interactive
integer :: centerObj, centerTri, centerNode, seed(1)
! virtual universe data
character(10) :: UniGeom !sphere or box or null
logical :: periodic !fold positions or rebound
real(4), dimension(3) :: UniParms ! parameters (r for sphere, L(x,y,z) for box)
character(4) :: bgpx
end type
! this module also has these variables
type(object), dimension(:), allocatable :: o
type(object) :: cam !camera object, not part of all other objects
type(screen) :: scr
integer :: ObjectBufferSize, Nobjects
!!!!!!!!!!!!!!!!!
! must first call loadScreenData
! this allocates necessary arrays and initialized variables
!!!!!!!!!!!!!!!!!!!
contains
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!80
subroutine loadObject( FD, fl, obj ) !{{{
! read an object from file descriptor FD and file name fl
use lineParse
use quaternion
implicit none
character(*) :: fl
character(80) :: line, word, tmp
integer :: FD, err, i, ln, id, sm, c(3)
real(4) :: p(3), q1(4), q2(4)
type(object), intent(inout) :: obj
obj%name = "Object_Name"
obj%mode = "point"
obj%po(:) = 0.0
obj%velocity(:) = 0.0
obj%orient(:) = 0.0; obj%orient(2:4) = 1.0
obj%spin(:) = 0.0; obj%spin(2:4) = 1.0
! for contact
obj%mass = 1.0
obj%radius = 1.0
! for hertzian contact
obj%stiffness = 1.0
obj%poisson = 0.3
obj%friction = 1.0
open(FD,file=trim(fl),iostat=err)
if (err.ne.0) then
STOP "some problem opening object file:"//trim(fl)
endif
do
line = getLine( FD, ln, err )
if (err.ne.0) exit
word = s_get_word(1, line)
select case (trim(word))
case ("name"); obj%name = s_get_word(2, line)
case ("mode"); obj%mode = trim(s_get_word(2, line))
case ("mass"); call s_get_val(2, line, obj%mass )
case ("radius"); call s_get_val(2, line, obj%radius )
case ("stiffness"); call s_get_val(2, line, obj%stiffness )
case ("poisson"); call s_get_val(2, line, obj%poisson )
case ("friction"); call s_get_val(2, line, obj%friction )
case ("offset");
call s_get_val(2, line, obj%po(1) )
call s_get_val(3, line, obj%po(2) )
call s_get_val(4, line, obj%po(3) )
case ("velocity");
call s_get_val(2, line, obj%velocity(1) )
call s_get_val(3, line, obj%velocity(2) )
call s_get_val(4, line, obj%velocity(3) )
case ("orient");
call s_get_val(2, line, obj%orient(1) )
call s_get_val(3, line, obj%orient(2) )
call s_get_val(4, line, obj%orient(3) )
call s_get_val(5, line, obj%orient(4) )
q1(1) = 0.0; q1(2:4) = obj%orient(2:4) !axis portion
call quatrotor( q1, obj%orient(1), q2 )
obj%orient = q2
case ("spin");
call s_get_val(2, line, obj%spin(1) )
call s_get_val(3, line, obj%spin(2) )
call s_get_val(4, line, obj%spin(3) )
call s_get_val(5, line, obj%spin(4) )
q1(1) = 0.0; q1(2:4) = obj%spin(2:4) !axis portion
call quatrotor( q1, obj%spin(1), q2 )
obj%spin = q2
case ("points");
call s_get_val(2, line, obj%np )
allocate( obj%point(3,obj%np), obj%color(3,obj%np), obj%smooth(obj%np) )
allocate( obj%ip(3,obj%np), obj%rp(3,obj%np), obj%sp(3,obj%np) )
do i = 1, obj%np
read(FD,*,iostat=err) id, p(1:3), c(1:3), sm
if (IS_IOSTAT_EOR(err)) then
STOP "ERROR: premature End of Record reading point data"
elseif (IS_IOSTAT_END(err)) then
STOP "ERROR: premature End of File reading point data"
endif
obj%point(1:3,id) = p(1:3)
obj%color(1:3,id) = c(1:3)
obj%smooth(id) = sm !zero is sharp (no averaging), one will average normals
! obj%ip(:,i) = obj%point(:,i) +obj%po(:) !global coordinates
enddo
case ("triangles"); tmp = s_get_word(2, line); read(tmp,*) obj%nt
allocate( obj%tri(3,obj%nt) )
do i = 1, obj%nt
read(FD,*,iostat=err) c(1:3)
if (IS_IOSTAT_EOR(err)) then
STOP "ERROR: premature End of Record reading triangle data"
elseif (IS_IOSTAT_END(err)) then
STOP "ERROR: premature End of File reading triangle data"
endif
obj%tri(1:3,i) = c(1:3)
enddo
case ("VertexNormals");
call s_get_val(2, line, obj%nvn )
allocate( obj%vertnorm(3,obj%np), obj%ivn(3,obj%np), obj%rvn(3,obj%np) ) !allocate for all points, usually all or none are smooth.
do i = 1, obj%nvn
read(FD,*,iostat=err) id, p(1:3)
if (IS_IOSTAT_EOR(err)) then
STOP "ERROR: premature End of Record reading VertexNormals data"
elseif (IS_IOSTAT_END(err)) then
STOP "ERROR: premature End of File reading VertexNormals data"
endif
if (obj%smooth(id).eq.1) then !zero is sharp (no averaging), one will average normals
obj%vertnorm(1:3,id) = p(1:3)
else
write(0,*) "WARNING: Vertex Normal line:",i," ID:",id," not flagged for smoothing"
endif
enddo
case default !ignores lines that don't match anything
end select
enddo
close(FD)
! if object has a local rotation WRT global, apply it here.
do i = 1, obj%np
obj%ip(:,i) = obj%point(:,i) +obj%po(:) !global coordinates
enddo
end subroutine loadObject !}}}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!80
subroutine xyz2Object( FD, fl, obj, npts ) !{{{
! read an object from file descriptor FD and file name fl
! col : column array from file corresponding to
! col(1:3) x,y,z columns
! col(4) point radius
! col(5) pseudo transparency (current color)*(t)+(point color)*(1-t)
! col(6:8) either RGB or HSV columns
! rng(2,8) min and max limits for each column value in col(:)
! if min=max & col(i)=0 then do not read a column, but use the rng value
! if min=max=0.0 & col(i)>0 then auto calculate range to fit
! set mode either sphere or circle or fcircle (filled circle)
!use lineParse
use quaternion
use inputShareMod ! for col, rng, h
use fbMod !only HSV2RGB
implicit none
character(*) :: fl
!integer, intent(in) :: col(8)
!real(4), intent(in) :: rng(2,8)
type(object), intent(inout) :: obj
!logical, intent(in) :: h ! is the input color columns for HSV?
! internal
character(80) :: line
integer :: FD, err, i, j, ln, c(4), r(3), skip
real(4) :: p(4), mr(2,8), q1(4), q2(4)
real(4), allocatable, dimension(:) :: dum
integer, optional :: npts
! allocate dummy for max needed columns
allocate( dum( maxval(col) ) )
obj%name = trim(fl)
obj%mode = trim(md)
obj%po(:) = 0.0
obj%velocity(:) = 0.0
!obj%orient(:) = 0.0; obj%orient(2:4) = 1.0
q1(1) = 0.0; q1(2:4) = 1.0 !obj%orient(2:4) !axis portion
call quatrotor( q1, 0.0, q2 )
obj%orient = q2
!obj%spin(:) = 0.0; obj%spin(2:4) = 1.0
q1(1) = 0.0; q1(2:4) = 1.0 !obj%orient(2:4) !axis portion
call quatrotor( q1, 0.0, q2 )
obj%spin = q2
! for contact
obj%mass = 1.0
obj%radius = 1.0
! for hertzian contact
obj%stiffness = 1.0
obj%poisson = 0.3
obj%friction = 1.0
!
obj%nt = 0 ! no triangle data
open(FD,file=trim(fl),iostat=err)
if (err.ne.0) then
STOP "some problem opening xyz file:"//trim(fl)
endif
! first word on first line is number of points
!read(FD,*,iostat=err) obj%np
!if (err.ne.0) exit
!read(FD,*,iostat=err) ! empty line or comments
skip = 0
if (.not.present(npts)) then
! scan the file to get number of points
i = 0
do
read(FD,'(A)',iostat=err) line
if (IS_IOSTAT_END(err)) exit
if (line(1:1).eq."#") then; skip = skip + 1; cycle; endif
i = i + 1
enddo
obj%np = i
write(6,*) "Read xyz file. comments:", skip, " lines:", i
write(6,*) "rereading..."
rewind(FD)
do i = 1, skip; read(FD,*); enddo ! skip the commented header
else
obj%np = npts
endif
allocate( obj%point(3,obj%np), obj%color(3,obj%np), obj%smooth(obj%np), stat=err )
if (err.ne.0) STOP "ERROR: allocating points color smooth from data file"
allocate( obj%ip(3,obj%np), obj%rp(3,obj%np), obj%sp(3,obj%np), stat=err )
if (err.ne.0) STOP "ERROR: allocating ip rp sp from data file"
obj%nvn = obj%np ! just make nvn=np to have a float number
allocate( obj%vertnorm(3,obj%np), stat=err )
if (err.ne.0) STOP "ERROR: allocating vertnorm from data file"
mr = rng ! copy this here since 'mr' gets updated
ln = skip
do i = 1, obj%np
ln = ln+1
read(FD,*,iostat=err) dum(:)
if (err.ne.0) then
if (IS_IOSTAT_EOR(err)) then
write(0,*) "ERROR: premature End of Record reading point data in xyz file, line:", ln
elseif (IS_IOSTAT_END(err)) then
write(0,*) "ERROR: premature End of File reading point data in xyz file, line:", ln
else
write(0,*) "ERROR: reading point data in xyz file, line: ", ln
endif
STOP
endif
obj%point(1,i) = dum(col(1))
obj%point(2,i) = dum(col(2))
obj%point(3,i) = dum(col(3))
!obj%smooth(i) = 1 !must be flagged otherwise vertex normals won't save in obj file
obj%smooth(i) = 0 !must be zero so that dynamics don't rotate the normals
if (col(4).eq.0) then
obj%vertnorm(1,i) = rng(1,4)
else
obj%vertnorm(1,i) = abs(dum(col(4))) ! point radius
endif
if (col(5).eq.0) then
obj%vertnorm(2,i) = rng(1,5) ! point transparency
else
obj%vertnorm(2,i) = abs(dum(col(5))) ! point transparency
endif
obj%vertnorm(3,i) = 0.0
if (col(6).eq.0) then
obj%rp(1,i) = rng(1,6)
else
obj%rp(1,i) = (dum(col(6))) ! color
endif
if (col(7).eq.0) then
obj%rp(2,i) = rng(1,7)
else
obj%rp(2,i) = (dum(col(7))) ! color
endif
if (col(8).eq.0) then
obj%rp(3,i) = rng(1,8)
else
obj%rp(3,i) = (dum(col(8))) ! color
endif
! calculate mins and maxes from the data
do j = 1, 8
if (col(j).le.0) cycle
if (i.eq.1) mr(:,j) = dum(col(j)) ! initialize
if (dum(col(j)).lt.mr(1,j)) mr(1,j) = dum(col(j))
if (dum(col(j)).gt.mr(2,j)) mr(2,j) = dum(col(j))
enddo
enddo
close(FD)
! set global ranges if not specified in 'rng'
do j = 1, 8
if (col(j).le.0) cycle ! it is set to a value
if (abs(rng(1,j)-rng(2,j)).lt.1.e-12) then ! it needs to be set
rng(:,j) = mr(:,j)
endif
enddo
! if reading transparency values from file column or if it's set to nonzero.
if (col(5).ne.0 .or. abs(rng(1,5)-rng(2,5)).gt.1.e-12) then
obj%transparency = .true.
endif
write(6,'(a)') "dataRanges read from file if not specified:"
write(6,*) "x: ",rng(:,1); write(6,*) "y: ",rng(:,2)
write(6,*) "z: ",rng(:,3); write(6,*) "r: ",rng(:,4)
write(6,*) "t: ",rng(:,5); write(6,*) "R,h: ",rng(:,6)
write(6,*) "G,s: ",rng(:,7); write(6,*) "B,v: ",rng(:,8)
!rewind(FD)
!do i = 1, skip; read(FD,*); enddo ! skip the commented header
! if object has a local rotation WRT global, apply it here.
do i = 1, obj%np
obj%ip(:,i) = obj%point(:,i) +obj%po(:) !global coordinates
!read(FD,*,iostat=err) dum(:)
! color stuff
! normalize column value to color range
j = 1
if (col(j+4).eq.0.or.abs(rng(1,j+4)-rng(2,j+4)).lt.1.e-12) then
p(j) = rng(1,j+4)
c(j) = nint(p(j))
else
if (rng(1,4+j).lt.rng(2,4+j)) then
!p(j) = max( min(dum(col(4+j)),rng(2,4+j)) ,rng(1,4+j)) ! fit the value within the range
p(j) = max( min( obj%vertnorm(2,i) ,rng(2,4+j)) ,rng(1,4+j)) ! fit the value within the range
else
!p(j) = max( min(dum(col(4+j)),rng(1,4+j)) ,rng(2,4+j)) ! fit the value within the range
p(j) = max( min( obj%vertnorm(2,i) ,rng(1,4+j)) ,rng(2,4+j)) ! fit the value within the range
endif
p(j) = (p(j)-rng(1,4+j))/(rng(2,4+j)-rng(1,4+j)) ! fraction within the range
c(j) = nint(p(j)*255.0)
endif
do j = 2, 4
if (col(j+4).eq.0.or.abs(rng(1,j+4)-rng(2,j+4)).lt.1.e-12) then
p(j) = rng(1,j+4)
c(j) = nint(p(j))
else
if (rng(1,4+j).lt.rng(2,4+j)) then
!p(j) = max( min(dum(col(4+j)),rng(2,4+j)) ,rng(1,4+j)) ! fit the value within the range
p(j) = max( min( obj%rp(j-1,i) ,rng(2,4+j)) ,rng(1,4+j)) ! fit the value within the range
else
!p(j) = max( min(dum(col(4+j)),rng(1,4+j)) ,rng(2,4+j)) ! fit the value within the range
p(j) = max( min( obj%rp(j-1,i) ,rng(1,4+j)) ,rng(2,4+j)) ! fit the value within the range
endif
p(j) = (p(j)-rng(1,4+j))/(rng(2,4+j)-rng(1,4+j)) ! fraction within the range
c(j) = nint(p(j)*255.0)
endif
enddo ! j
if (h) then ! provided as HSV values, need them in RGB
call HSV2RGB( c(2),c(3),c(4), r(1),r(2),r(3) )
obj%color(1:3,i) = r(1:3)
else ! they are already in RGB
obj%color(1:3,i) = c(2:4)
endif
obj%vertnorm(2,i) = real(c(1))
enddo
end subroutine xyz2Object !}}}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!80
subroutine saveObject( FD, fl, i ) !{{{
use quaternion
implicit none
integer, intent(in) :: FD, i
character(*) :: fl
integer :: err, j
real(4), dimension(4) :: q
open(FD,file=trim(fl),iostat=err)
if (err.ne.0) then
STOP "some problem opening output file:"//trim(fl)
endif
write(FD,'(A)') "name "//o(i)%name
write(FD,'(A)') "mode "//o(i)%mode
write(FD,'(A,E12.5)') "mass ",o(i)%mass
write(FD,'(A,E12.5)') "radius ",o(i)%radius
write(FD,'(A,E12.5)') "stiffness ",o(i)%stiffness
write(FD,'(A,E12.5)') "poisson ",o(i)%poisson
write(FD,'(A,E12.5)') "friction ",o(i)%friction
write(FD,'(A,3E12.5)') "offset ",o(i)%po
write(FD,'(A,3E12.5)') "velocity ",o(i)%velocity
! convert back to angle axis notiation from rotor
call rotoraxis( o(i)%orient, q )
write(FD,'(A,4E12.5)') "orient ",q
call rotoraxis( o(i)%spin, q )
write(FD,'(A,4E12.5)') "spin ",q
! write points
write(FD,'(A)') "points"
do j = 1, o(i)%np
write(FD,*,iostat=err) j, o(i)%point(1:3,j), o(i)%color(1:3,j), o(i)%smooth(j)
if (err.ne.0) then
write(0,*) "ERROR writing points in object file"
return
endif
enddo
! write triangles
write(FD,'(A)') "triangles"
do j = 1, o(i)%nt
write(FD,*,iostat=err) o(i)%tri(1:3,j)
if (err.ne.0) then
write(0,*) "ERROR writing triangles in object file"
return
endif
enddo
! write Vertex Normals
write(FD,'(A)') "VertexNormals"
do j = 1, o(i)%np
if (o(i)%smooth(j).eq.1) then !write it
write(FD,*,iostat=err) j, o(i)%vertnorm(1:3,j)
if (err.ne.0) then
write(0,*) "ERROR writing vertex normals in object file"
return
endif
endif
enddo
close(FD)
end subroutine saveObject !}}}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!80
!subroutine loadScreenData( FD, fl )
subroutine initVars !{{{
! read screen data from file descriptor FD and file name fl
use lineParse
use quaternion
!use starMod, only : starfilename, Nstars
use controlMod
use inputShareMod !for col, rng, h, md
implicit none
!character(80) :: fl !, line
!integer :: FD !, err, ln
real(4) :: q1(4), q2(4)
scr%fbpath = "/dev/fb0"
scr%tmpdir = "/tmp"
scr%width = 1440 !these three are just copied into the framebuffer object
scr%height = 900
scr%line = 1472
scr%FOVx = 1.74533 ! field of view (radians)
scr%FOVy = 1.5708
scr%sr(1,:) = (/200, 700/) ! local screen position for the rendering
scr%sr(2,:) = (/100, 550/)
scr%dt = 0.01 !time step
scr%dtheta = 0.261799 ! angular increment for movement
scr%ds = 1.0 ! spatial increment for movement
scr%interactive = .false.
scr%dumpName = "_"
scr%timeout = 0 !stop program after this many time steps
! universe data
scr%UniGeom = "NULL" !no virtual position boundaries
scr%periodic = .false. !not periodic (would rebound if geom set
scr%UniParms(:) = 0.0
scr%seed(1) = 123456789
scr%globalrotor = (/ 0.0, 1.0, 1.0, 1.0 /) !initial angle-axis notation
scr%bgpx = char(0)//char(0)//char(0)//char(0)
! camera object data
cam%name = "Camera"
cam%po = (/ -10.0, 0.0, 0.0 /) !default camera position
cam%velocity = (/ 0.0, 0.0, 0.0 /) ! yoru personal velocity
cam%orient = (/ 0.0, 1.0, 1.0, 1.0 /) !initial angle-axis notation
cam%spin = (/ 0.0, 1.0, 1.0, 1.0 /) !initial angle-axis notation
q1(1) = 0.0; q1(2:4) = cam%orient(2:4) !axis portion
call quatrotor( q1, cam%orient(1), q2 )
cam%orient = q2
q1(1) = 0.0; q1(2:4) = cam%spin(2:4) !axis portion
call quatrotor( q1, cam%spin(1), q2 )
cam%spin = q2
! for camera contact
cam%mass = 1.0
cam%radius = 1.0
! for hertzian camera contact
cam%stiffness = 1.0
cam%poisson = 0.3
cam%friction = 1.0
ObjectBufferSize = 1 ! load only one object by default
Nobjects = 0 ! everytime LoadObject is called, this will increment
impulseControl = .false. !control is spatial rather than rate modulating
Ofollow = 0 ! object to follow, zero for no follow
contact = .false. !contact detection off by default
cameraContact = .false. !objects don't interact with camera by default
!starfilename = "stars.dat"
!Nstars = 300
record = .false. ! dump PPM files every frame?
scrot = .false. ! single screen shot flag
! stuff that persists in input file only used for plotting
col(:) = 0
rng(:,:) = 0.0
rng(:,4) = 1.0 ! radius
h = .true.
md = "point"
!open(FD,file=trim(fl),iostat=err)
!if (err.ne.0) then
! STOP "ERROR opening scene file:"//trim(fl)
!endif
!ln = 0
!do
! line = getLine( FD, ln, err )
!!write(6,'(i3,x,A)') ln,trim(line) !echo the read line
! if (err.ne.0) then ; err=0; exit ; endif
! if (len(trim(line)).le.0) cycle
! call interpretLine( line, err )
! if (err.gt.0) then
! write(0,*) "ERROR: interpreting line: ",ln," of file:"//trim(fl)
! exit
! endif
! if (err.lt.0) exit !user defined exit
!enddo
!close(FD)
!call flush(0)
!call flush(6)
!if (err.ne.0) STOP "done reading input config."
!if (.not.allocated(o)) allocate( o(ObjectBufferSize) )
!end subroutine loadScreenData
end subroutine initVars !}}}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!80
subroutine interpretLine( s, error ) !{{{
! this routine could be used to set variables or perform complex things that a
! single input character can't
use lineParse
use quaternion
use fbMod
!use starMod, only : starfilename, Nstars
use controlMod
use inputShareMod !for col, rng, h, md
implicit none
integer :: wc
integer, intent(out) :: error
character(*) :: s
character(80) :: word, tmp, word2
integer :: i, j, k, c(4), mo, mj
real(4) :: p(3), scl, pi
real(4) :: q1(4), q2(4), val(8)
character :: CR, LF
CR = achar(13)
LF = achar(10)
pi = 4.0*ATAN2(1.0,1.0) !=log(-1.0)/i
error = 0 !positive errors are fatal and kill the program, negative are warnings
wc = s_word_count( s )
word = s_get_word( 1, s )
select case(trim(word))
case ("help"); call commandHelp; run=.false.
case ("q","exit","quit"); error=-1 ! this will flag as error and kill program
case ("echo"); write(6,'(A)') s(6:); call flush(6)
case ("exec"); call execute_command_line( s(6:), WAIT=.true. )
case ("fbpath"); if (wc>1) then; scr%fbpath = s_get_word(2, s)
else; write(6,*) trim(scr%fbpath); run=.false.; endif
case ("dumpFile"); if (wc>1) then; scr%dumpName = s_get_word(2, s)
else; write(6,*) trim(scr%dumpName); run=.false.; endif
! case ("starFile","starfile"); if (wc>1) then; starfilename = s_get_word(2, s)
! else; write(6,*) trim(starfilename); run=.false.; endif
case ("tmpdir"); if (wc>1) then; scr%tmpdir = s_get_word(2, s)
else; write(6,*) trim(scr%tmpdir); run=.false.; endif
case ("interactive"); scr%interactive = .true.
case ("FOV"); if (wc>1) then
call s_get_val(2, s, scr%FOVx )
call s_get_val(3, s, scr%FOVy )
else; write(6,*) scr%FOVx, scr%FOVy; run=.false.; endif
case ("subscreen"); if (wc>1) then
call s_get_val(2, s, scr%sr(2,1) )
call s_get_val(3, s, scr%sr(1,1) )
call s_get_val(4, s, scr%sr(2,2) )
call s_get_val(5, s, scr%sr(1,2) )
scr%sr_x = scr%sr(1,2)-scr%sr(1,1) ! x width for 3d screen
scr%sr_y = scr%sr(2,2)-scr%sr(2,1) ! y width
else; write(6,*) scr%sr(2,1), scr%sr(1,1), scr%sr(2,2), scr%sr(1,2); run=.false.; endif
case ("timestep"); if (wc>1) then; call s_get_val(2, s, scr%dt )
else; write(6,*) scr%dt; run=.false.; endif
! case ("Nstars"); if (wc>1) then; call s_get_val(2, s, Nstars )
! else; write(6,*) Nstars; run=.false.; endif
case ("dtheta"); if (wc>1) then; call s_get_val(2, s, scr%dtheta )
else; write(6,*) scr%dtheta; run=.false.; endif
case ("dspace"); if (wc>1) then; call s_get_val(2, s, scr%ds )
else; write(6,*) scr%ds; run=.false.; endif
case ("width"); if (wc>1) then; call s_get_val(2, s, scr%width )
else; write(6,*) scr%width; run=.false.; endif
case ("height"); if (wc>1) then; call s_get_val(2, s, scr%height )
else; write(6,*) scr%height; run=.false.; endif
case ("timeout"); if (wc>1) then; call s_get_val(2, s, scr%timeout )
else; write(6,*) scr%timeout; run=.false.; endif
case ("linelength"); if (wc>1) then; call s_get_val(2, s, scr%line )
else; write(6,*) scr%line; run=.false.; endif
case ("NobjectBuff"); if (wc>1) then; call s_get_val(2, s, ObjectBufferSize )
if (.not.allocated(o)) then; allocate( o(0:ObjectBufferSize) )
o(0)%np = 0 !no background object
else; deallocate(o); allocate( o(0:ObjectBufferSize) ); endif
else; write(6,*) ObjectBufferSize; run=.false.; endif
case ("contact"); if (wc>1) then; call s_get_val(2, s, contactType )
if (contactType.gt.0) then; contact=.true.
else; contact=.false.; endif
if (wc>2) call s_get_val(3, s, cameraContact )
else; write(6,*) "Contact Type:",contactType; run=.false.; endif
!!!! Load data !!!!
case ("dataColumns","dataCols")
if (wc==1) then; write(6,'(a,8i3)') "dataColumns (xyzrthsv):",col
run=.false.
return; endif
do i = 2, wc
call s_get_vali( i, s, col(i-1) ); enddo
case ("dataRange","dataRanges")
if (wc==1) then; write(6,'(a)') "dataRanges:"
write(6,*) "x: ",rng(:,1); write(6,*) "y: ",rng(:,2)
write(6,*) "z: ",rng(:,3); write(6,*) "r: ",rng(:,4)
write(6,*) "t: ",rng(:,5); write(6,*) "R,h: ",rng(:,6)
write(6,*) "G,s: ",rng(:,7); write(6,*) "B,v: ",rng(:,8)
run=.false.
return; endif
tmp = s_get_word(2, s)
if (trim(tmp).eq."1".or.trim(tmp).eq."x") then
call s_get_valr4( 3, s, rng(1,1) ); call s_get_valr4( 4, s, rng(2,1) )
elseif (trim(tmp).eq."2".or.trim(tmp).eq."y") then
call s_get_valr4( 3, s, rng(1,2) ); call s_get_valr4( 4, s, rng(2,2) )
elseif (trim(tmp).eq."3".or.trim(tmp).eq."z") then
call s_get_valr4( 3, s, rng(1,3) ); call s_get_valr4( 4, s, rng(2,3) )
elseif (trim(tmp).eq."4".or.trim(tmp).eq."r") then
call s_get_valr4( 3, s, rng(1,4) ); call s_get_valr4( 4, s, rng(2,4) )
elseif (trim(tmp).eq."5".or.trim(tmp).eq."t") then
call s_get_valr4( 3, s, rng(1,5) ); call s_get_valr4( 4, s, rng(2,5) )
elseif (trim(tmp).eq."6".or.trim(tmp).eq."h".or.trim(tmp).eq."R") then
call s_get_valr4( 3, s, rng(1,6) ); call s_get_valr4( 4, s, rng(2,6) )
elseif (trim(tmp).eq."7".or.trim(tmp).eq."s".or.trim(tmp).eq."G") then
call s_get_valr4( 3, s, rng(1,7) ); call s_get_valr4( 4, s, rng(2,7) )
elseif (trim(tmp).eq."8".or.trim(tmp).eq."v".or.trim(tmp).eq."B") then
call s_get_valr4( 3, s, rng(1,8) ); call s_get_valr4( 4, s, rng(2,8) )
endif
case ("dataColorHSV"); h = .true.
case ("dataColorRGB"); h = .false.
case ("dataPoint"); md = trim(s_get_word(2, s))
case ("LoadObject","LoadData");
if (wc==1) then; write(6,*) "Nobjects:",Nobjects; run=.false.; return; endif
Nobjects = Nobjects + 1
if (Nobjects.gt.ObjectBufferSize) then
write(0,*) "ERROR: not loading this object as there is no more space in object buffer"
error=1; return; endif
if (.not.allocated(o)) then
write(0,*) "ERROR: must allocate object buffer before loading object, see directive: NobjectBuff"
error=1; return; endif
tmp = s_get_word(2, s)
if (trim(word).eq."LoadObject") then
call loadObject( 12, trim(tmp), o(Nobjects) )
elseif (trim(word).eq."LoadData") then
! this requires col, rng, h, md to be set
if (maxval(col).le.1) then
write(0,*) "ERROR: Please set 'dataColumns' to read from the data file"
error=1; return; endif
if (wc.eq.3) then
word2 = s_get_word(3,s); read(word2,*) k ! get line count
call xyz2Object( 12, trim(tmp), o(Nobjects), k )
else
call xyz2Object( 12, trim(tmp), o(Nobjects) )
endif
endif
case ("LoadBackground");
if (.not.allocated(o)) then
write(0,*) "ERROR: must allocate object buffer before loading object, see directive: NobjectBuff"
error=1; return
endif
tmp = s_get_word(2, s)
call loadObject( 12, trim(tmp), o(0) )
! local points rotation to global coordinates
! if it's not spinning, this wouldbe fine to do once
do i = 1, o(0)%np
q1(1) = 0.0; q1(2:4) = o(0)%point(1:3,i)
call quatrotate( q1, o(0)%orient, q2)
o(0)%ip(:,i) = q2(2:4) +o(0)%po(:)
! background objects don't use shading so no need to rotate vertex normals
enddo
!!!!!!!!!!!!!!!!!!!!!!!!!
case ("camera_pos");
!if (wc==1) then; write(6,*) scr%camera_p; run=.false.; return; endif
!call s_get_val(2, s, scr%camera_p(1) )
!call s_get_val(3, s, scr%camera_p(2) )
!call s_get_val(4, s, scr%camera_p(3) )
if (wc==1) then; write(6,*) cam%po; run=.false.; return; endif
call s_get_val(2, s, cam%po(1) )
call s_get_val(3, s, cam%po(2) )
call s_get_val(4, s, cam%po(3) )
case ("camera_orient");
if (wc==1) then; write(6,*) scr%globalrotor; run=.false.; return; endif
call s_get_val(2, s, scr%globalrotor(1) )
call s_get_val(3, s, scr%globalrotor(2) )
call s_get_val(4, s, scr%globalrotor(3) )
call s_get_val(5, s, scr%globalrotor(4) )
q1(1) = 0.0; q1(2:4) = scr%globalrotor(2:4) !axis portion
call quatrotor( q1, scr%globalrotor(1), q2 )
scr%globalrotor = q2
case("dynamics") ; call objectDynamics
case("draw") ; call drawObjects
case("bgColor") ; c=0; if (wc>1) call s_get_val(2, s, c(3))
if (wc>2) call s_get_val(3, s, c(2))
if (wc>3) call s_get_val(4, s, c(1))
if (wc.eq.1) then; write(6,*) c(3),c(2),c(1), " ", c(4); endif
if (wc>1) scr%bgpx = char(c(1))//char(c(2))//char(c(3))//char(c(4))
case("fbinit") ; call fb%fbinit(10,scr%fbpath, scr%width, scr%height, scr%line, .true. )
case("universe") ; scr%UniGeom = trim(s_get_word(2, s))
if (trim(scr%UniGeom).eq."sphere") then
call s_get_val(3, s, scr%UniParms(1))
elseif (trim(scr%UniGeom).eq."box") then
call s_get_val(3, s, scr%UniParms(1))
call s_get_val(4, s, scr%UniParms(2))
call s_get_val(5, s, scr%UniParms(3))
endif
case ("seed"); if (wc>1) then; call s_get_val(2, s, scr%seed(1) )
else; write(6,*) scr%seed(1); run=.false.; endif
case ("follow"); if (wc>1) then; call s_get_val(2, s, Ofollow )
if (Ofollow.gt.0) call o(Ofollow)%mkconnections
else; write(6,*) Ofollow; run=.false.; endif
case("periodic"); scr%periodic=.true. !set universe to be periodic
case("fbclear") ; call fb%clear !clear the fb%pxbuff and fb%zbuff
case("pause"); run=.false. !stop animation
case("run"); run=.true. !stop animation
case("record"); if (record) then; record=.false.; else; record = .true.; endif
case("picture","scrot"); scrot=.true. !record every frame
if (.not.scr%interactive.and.wc.ge.2) then
tmp = s_get_word(2, s)
call fb%save(trim(tmp),2)
scrot=.false.
endif
case("impulseControl"); impulseControl=.true.
case("spatialControl"); impulseControl=.false.
case("redraw"); call fb%display !redraw the screen based on current and last rendering
case("cpo"); !copy object to empty objects
call s_get_val(2, s, mo)
call s_get_val(3, s, j)
k = j
if (wc.eq.4) call s_get_val(4, s, k) !specify range to copy to
if (k>Nobjects) Nobjects=k
if (Nobjects>ObjectBufferSize) then
write(0,*) CR//"Warning: copied objects exceed object buffer size"
k = ObjectBufferSize
Nobjects = ObjectBufferSize
endif
do i = j, k
o(i) = o(mo) ! simple copy object
enddo
case("orand"); !randomize object range properties
tmp = s_get_word( 2, s )
call s_get_val( 3, s, i)
call s_get_val( 4, s, j)
do k = 5, wc
call s_get_val( k, s, val(k-4))
enddo
call ObjectRandom( tmp, i, j, val )
case("nearest","closest"); !report which object is closest
scl = o(1)%sp(1,1) !min point location
mo = 1 !object with min point location
mj = 1
do i = 1, Nobjects; do j = 1, o(i)%np
if (o(i)%sp(1,j).lt.scl) then; mo = i; mj = j; scl = o(i)%sp(1,j); endif
enddo; enddo
write(6,*) CR//trim(word)//" object,vertex ID:",mo,",",mj
write(6,*) CR//" relPos (dx, dy, dz):",o(mo)%rp(:,mj)
write(6,*) CR//" sphPos (dist, phi/pi, theta/pi):",o(mo)%sp(1,mj),o(mo)%sp(2:3,mj)/pi
run=.false.; return
case("underAim"); !report object ID and node ID being aimed at.
write(6,*) CR//" Aiming upon object ID:",scr%centerObj, &
& " triangle ID:",scr%centerTri," vertex ID:",scr%centerNode
if (scr%centerObj.gt.0) then
write(6,*) CR//" sphPos (dist, phi/pi, theta/pi):", &
& o(scr%centerObj)%sp(1,scr%centerNode), &
& o(scr%centerObj)%sp(2:3,scr%centerNode)/pi
write(6,*) CR//" color:",o(scr%centerObj)%color(:,scr%centerNode)
endif
run=.false.; return
case ("saveObject","saveObj"); ! save this object as a separate object file
if (wc==1) then; write(6,*) "Must specify an object ID number to save"
run=.false.; return; endif
call s_get_val( 2, s, i)
if (wc==2) then; call saveObject( 20, "objectDump.obj", i )
elseif (wc==3) then; call saveObject( 20, s_get_word(3,s), i ); endif
case("cam","camera"); ! regarding the camera object
if (wc==1) then
write(6,*) CR//"name:"//trim( cam%name )
write(6,*) CR//"mass:", cam%mass
write(6,*) CR//"radius:", cam%radius
write(6,*) CR//"stiffness:", cam%stiffness
write(6,*) CR//"poisson:", cam%poisson
write(6,*) CR//"friction:", cam%friction
!write(6,*) CR//"Npoints:", cam%np !number of points
!write(6,*) CR//"Ntriangles:", cam%nt !number of triangles
!write(6,*) CR//"mode:"//trim( cam%mode ) !(point|wire|solid)
write(6,*) CR//"offset:", cam%po !position offset wrt global coordinates
write(6,*) CR//"velocity:", cam%velocity !changes the offset position wtf global
write(6,*) CR//"orientation:",scr%globalrotor !orientation quaternion
write(6,*) CR//"spin:", cam%spin !local rotation rate (changes orientation)
run=.false.; return
endif
word2 = s_get_word(2, s)
select case(trim(word2)) !{{{
case ("name"); cam%name = s_get_word(3, s)
case ("mass"); call s_get_val(3, s, cam%mass )
case ("radius"); call s_get_val(3, s, cam%radius )
case ("stiffness"); call s_get_val(3, s, cam%stiffness )
case ("poisson"); call s_get_val(3, s, cam%poisson )
case ("friction"); call s_get_val(3, s, cam%friction )
case ("offset","pos","position");
if (wc==1) then; write(6,*) cam%po; run=.false.; return; endif
call s_get_val(3, s, cam%po(1) )
call s_get_val(4, s, cam%po(2) )
call s_get_val(5, s, cam%po(3) )
case ("velocity","vel");
if (wc==1) then; write(6,*) cam%velocity; run=.false.; return; endif
call s_get_val(3, s, cam%velocity(1) )
call s_get_val(4, s, cam%velocity(2) )
call s_get_val(5, s, cam%velocity(3) )
case ("orient"); !cam%orient should be constant, only globablrotor changes
if (wc==1) then; write(6,*) scr%globalrotor; run=.false.; return; endif
call s_get_val(3, s, scr%globalrotor(1) )
call s_get_val(4, s, scr%globalrotor(2) )
call s_get_val(5, s, scr%globalrotor(3) )
call s_get_val(6, s, scr%globalrotor(4) )
q1(1) = 0.0; q1(2:4) = scr%globalrotor(2:4) !axis portion
call quatrotor( q1, scr%globalrotor(1), q2 )
scr%globalrotor = q2
! call s_get_val(4, s, cam%orient(1) )
! call s_get_val(5, s, cam%orient(2) )
! call s_get_val(6, s, cam%orient(3) )
! call s_get_val(7, s, cam%orient(4) )
! q1(1) = 0.0; q1(2:4) = cam%orient(2:4) !axis portion
! call quatunit( q1, q2 )
! call quatrotor( q2, cam%orient(1), q1 )
! cam%orient = q1
case ("spin");
if (wc==1) then; write(6,*) cam%spin; run=.false.; return; endif
call s_get_val(3, s, cam%spin(1) )
call s_get_val(4, s, cam%spin(2) )
call s_get_val(5, s, cam%spin(3) )
call s_get_val(6, s, cam%spin(4) )
q1(1) = 0.0; q1(2:4) = cam%spin(2:4) !axis portion
call quatunit( q1, q2 )
call quatrotor( q2, cam%spin(1), q1 )
cam%spin = q1
end select !}}}
case("o"); ! regarding an object
if (wc==1) then; write(6,*) "Nobjects:",Nobjects; run=.false.; return; endif
call s_get_val(2, s, i) !object ID
if (wc==2) then
write(6,*) CR//"name:"//trim( o(i)%name )
write(6,*) CR//"mass:", o(i)%mass
write(6,*) CR//"radius:", o(i)%radius
write(6,*) CR//"stiffness:", o(i)%stiffness
write(6,*) CR//"poisson:", o(i)%poisson
write(6,*) CR//"friction:", o(i)%friction
write(6,*) CR//"Npoints:", o(i)%np !number of points
write(6,*) CR//"Ntriangles:", o(i)%nt !number of triangles
write(6,*) CR//"mode:"//trim( o(i)%mode ) !(point|wire|solid)
write(6,*) CR//"offset:", o(i)%po !position offset wrt global coordinates
!write(6,*) CR//"localPos:", o(i)%point !initial position wrt local coordinates
!write(6,*) CR//"initPos:", o(i)%ip !initial position wrt global coordinates
!write(6,*) CR//"relPos:", o(i)%rp !relative position wrt camera
!write(6,*) CR//"sphPos:", o(i)%sp/pi !relative spherical position wrt camera
write(6,*) CR//"velocity:", o(i)%velocity !changes the offset position wtf global
write(6,*) CR//"orientation:",o(i)%orient !orientation quaternion
write(6,*) CR//"spin:", o(i)%spin !local rotation rate (changes orientation)
run=.false.; return
endif
word2 = s_get_word(3, s)
select case(trim(word2)) !{{{
case ("save"); ! save this object as a separate object file
if (wc==3) then; call saveObject( 20, "objectDump.obj", i )
elseif (wc==4) then; call saveObject( 20, s_get_word(4,s), i ); endif
case ("name"); o(i)%name = s_get_word(4, s)
case ("mode"); o(i)%mode = trim(s_get_word(4, s))
case ("mass"); call s_get_val(4, s, o(i)%mass )
case ("radius"); call s_get_val(4, s, o(i)%radius )
case ("stiffness"); call s_get_val(4, s, o(i)%stiffness )
case ("poisson"); call s_get_val(4, s, o(i)%poisson )
case ("friction"); call s_get_val(4, s, o(i)%friction )
case ("offset","pos","position");
call s_get_val(4, s, o(i)%po(1) )
call s_get_val(5, s, o(i)%po(2) )
call s_get_val(6, s, o(i)%po(3) )
case ("velocity","vel");
call s_get_val(4, s, o(i)%velocity(1) )
call s_get_val(5, s, o(i)%velocity(2) )
call s_get_val(6, s, o(i)%velocity(3) )
case ("orient");
call s_get_val(4, s, o(i)%orient(1) )
call s_get_val(5, s, o(i)%orient(2) )
call s_get_val(6, s, o(i)%orient(3) )
call s_get_val(7, s, o(i)%orient(4) )
q1(1) = 0.0; q1(2:4) = o(i)%orient(2:4) !axis portion
call quatunit( q1, q2 )
call quatrotor( q2, o(i)%orient(1), q1 )
o(i)%orient = q1
case ("spin");
call s_get_val(4, s, o(i)%spin(1) )
call s_get_val(5, s, o(i)%spin(2) )
call s_get_val(6, s, o(i)%spin(3) )
call s_get_val(7, s, o(i)%spin(4) )
q1(1) = 0.0; q1(2:4) = o(i)%spin(2:4) !axis portion
call quatunit( q1, q2 )
call quatrotor( q2, o(i)%spin(1), q1 )
o(i)%spin = q1
case ("scale"); !scale all object positions
call s_get_val(4, s, scl )
call o(i)%scale( scl )
!do j = 1, o(i)%np
! o(i)%point(:,j) = o(i)%point(:,j)*scl
!enddo
!! also scale radius and mass (assuming constant density)
!o(i)%radius = o(i)%radius*scl
!o(i)%mass = o(i)%mass*scl*scl*scl
case ("add"); !add a new point to triangle under AIM or ID specified
if (wc==4) then !specified a triangle ID
call s_get_val(4, s, j ) !point ID
else ! try for the triangle under AIM
j = scr%centerTri
if (j.le.0) write(6,'(A)') CR//"no triangle under aim. Please specify triangle ID."
endif
if (j.le.o(i)%nt) then; call o(i)%addPoint( j )
else; write(6,'(A)') CR//"triangle ID too large for this object"; endif
run=.false.; return
case ("point"); !change point location
if (wc==3) then; write(6,'(A)') CR//"missing point ID for this object"
run=.false.; return
elseif (wc==4) then;
call s_get_val(4, s, j ) !point ID
write(6,*) CR//"local:",o(i)%point(:,j), o(i)%color(:,j), o(i)%smooth(j)
write(6,*) CR//"initPos:",o(i)%ip(:,j)
write(6,*) CR//"relPos:",o(i)%rp(:,j)
write(6,*) CR//"sphPos:",o(i)%sp(1,j), o(i)%sp(2:3,j)/pi
run=.false.; return
elseif (wc>4) then;
call s_get_val(4, s, j ) !point ID
call s_get_val(5, s, p(1) )
call s_get_val(6, s, p(2) )