DesignCAD SDK > User Contributions

Yet Another 3D Viewer

(1/13) > >>

bdeck:
Here's my take on a 3d viewing macro where the viewer never ends up standing on his/her head.

Viewer moves up, down, right and left by using the arrow keys.  The "h" key displays a help menu

Still needs lighting control......maybe someone else will provide that.

bd


Edit 10/24/17  see message 49 in this thread for latest version 


--- Code: ---' vdd.d3m   macro to manage 3d views   bdeck   4/2014
'
' View Down from Dome
' If any entities have been previously selected, the selection center will be the view center.
' Otherwise the drawing center will be the view center.
' Except for panning, all operations are performed using the keyboard.
'
' Viewer remains upright while moving along the surface of a shere
' without passing north or south poles.
'
' Hit the h key for a menu of key commands.
'

da=5 ' increment or decrement rotation angle when a key is pressed
df=1.25 ' distance factor
zf=1.25  ' zoom factor
sys(470) =1  ' prevent other commands from running during this macro

if sys(80)>0 then  ' rotate viewer about center of selection
gosub Vselectcenter
>Deselect
{
}
else ' rotate viewer about center of drawing
gosub Vdwgcenter
endif

' -------- list of key values ----------
k_r=82
k_spc=32
k_f=70
k_a=65
k_q=81
k_w=87
k_z=90
k_x=88
k_s=83
k_d=68
k_esc=27
k_cr=13
k_g=71
k_h=72
k_c=67
k_k=75
k_l=76
k_m=77
k_n=78
k_p=80
k_t=84
k_e=69
k_v=86
k_b=66
k_u=85
k_up=38
k_dn=40
k_rt=39
k_lft=37
k_spc=32
k_shft=16
k_cntrl=17
k_click=1
k_plus=107
k_minus=109
k_plusA=187    ' use keycode for =
k_minusA=189
k_esc=27
k_cr=13
k_zero=96
k_zeroA=48


' Get starting angles, distance, and type of 3d view

ax=sys(205)
ay=sys(206)
az=sys(207)
d=sys(208)
t=sys(209)

do while k<>k_esc

ax=ax mod 360 ' limit range of viewing angles displayed
ay=ay mod 360 ' limit range of viewing angles displayed

Precision 2
print " ax, ay, az  = ", ax, ay, az, " d = ", d, " iso= ", t, " shade = ",s2 ,"      Hit  h key for menu,    esc to exit"

anykey k

if k=k_up then ax=ax+da
if k=k_dn then ax=ax-da
if k=k_rt then ay=ay+da
if k=k_lft then ay=ay-da

if k=k_spc then gosub panit

if ax>90 then ax=90 'do not go beyond north pole
if ax<-90 then ax=-90 'do not go beyond south pole

if k=k_f then gosub farther 'larger distance
if k=k_n then gosub nearer 'smaller distance

if (k=k_plus or k=k_plusA) then gosub bigger 'narrower lens angle
if (k=k_minus or k=k_minusA) then gosub smaller 'wider lens angle

if k=u then az=0 ' make viewer upright
if (k=k_zero or k=k_zeroA) then gosub zeroit ' zero all viewing angles

if k=k_p then gosub isotoggle ' toggle perspective and isometric view modes
if k=k_h then gosub helper ' show help screen
if k=k_w then gosub winfit ' fit drawing to window

sys(205)=ax
sys(206)=ay
sys(207)=az

if k=k_s then
gosub shadetoggle
else
regen
endif
loop
end

shadeToggle:
s2=(sys(2)+1) mod 5
sys(2)=s2
return

zeroit:
ax=0
ay=0
az=0
return

bigger:
>Zoom
{
<Zoomfactor [zf]
}
return

smaller:
>Zoom
{
<Zoomfactor [1/zf]
}
return

nearer:
d=d/df
sys(208) =d
return

farther:
d=d*df
sys(208) =d
return

isotoggle:
t=(t+1) mod 2
sys(209)=t
return

winfit:
>fittowindow
{
}
return

panit:
'allow user to set points or drag view as desired
>Pan
{
<incomplete
}

return

helper:
sys$(42)="Help Menu"
WINDOW 13, 64

print
TAB 2
print "arrows";
TAB 10
print "move viewer up, down, left right on spherical dome surface"
TAB 2
print "spc";
TAB 10
print "Pan view by setting points or dragging"
TAB 2
print "p";
TAB 10
print "toggle perspective/ isometric view"
TAB 2
print "u";
TAB 10
print  "upright viewer (z angle =0)"
TAB 2
print "0";
TAB 10
print  "set all viewing angles to zero" 
TAB 2
print "w";
TAB 10
print  "fit entire drawing to window"
TAB 2
print "s";
TAB 10
print  "cycle shade modes"
TAB 2
print "+ / -";
TAB 10
print  "zoom bigger / smaller"
TAB 2
print "n / f";
TAB 10
print  "camera nearer / farther"
        TAB 2
print "esc";
TAB 10
print  "exit this macro"
        print
TAB 2
print "Hit any key to exit help menu"
anykey
WCLOSE
return


Vdwgcenter:
xc = 0.5*(sys(120) + sys(122))
yc = 0.5*(sys(121) + sys(123))
zc = 0.5*(Sys(124) + sys(125))
>SetViewerPoints
{
        <Pointxyz [xc, yc, zc]
}
return

Vselectcenter:
xc = 0.5*(sys(196) + sys(198))
yc = 0.5*(sys(197) + sys(199))
zc = 0.5*(Sys(200) + sys(201))
>SetViewerPoints
{
        <Pointxyz [xc, yc, zc]
}
return
--- End code ---

prl:
Bd, now that is a keeper!!  Great job.  I love the arrow keys and the +/-, so intuitive. 

Did the hairy Borland C awake the coding bug?  Whatever the reason, thanks for sharing.




prl:
I added some self-playing test movies in the zip file.   Folks, you need to try this routine!  I'm sitting in my chair jumping up and down.  The perspective toggle with the n/f is fun.

prl:

--- Quote from: bdeck on April 12, 2014, 10:37:16 PM ---Still needs lighting control......maybe someone else will provide that.

--- End quote ---

Bd, picking your brain.  If you could control lighting, what (generally speaking) would you do?

SFA:
I agree.  This is great! :)

Navigation

[0] Message Index

[#] Next page

Go to full version