I don't want an elliptic sun.... (advanced patch placement in 3d)
Status: Alpha
Brought to you by:
cwalther
From: Andrea V. <and...@gm...> - 2008-06-23 13:10:07
|
Hi, Probably my knowledge of trigonometry are a bit rusty, but I was not able to put a patch so that it is always orthogonal to the segment connecting the center view (nx,ny,nz=0,0,0) with its center. Imagine that I want to draw the sun in a cubic node, the sun is simply an image representing a yellow circle, and I want draw it passing azimuth and elevation to a function that place and orienting the patch so that the sun is never distorted, but always it appear perfectly circular. (You know that in the reality the sun is a sphere, so it should always appear circular from anywhere I look at it, and never should be appear elliptical ...) This would be useful if I wanted that my node can be visited at different hours of day and I want to render the idea of the time flow by the position of the sun (and possibly also the brightness of the scene). How could I do? I tried the code that follows, you can move the sun using arrow, and you can notice distorsion with elevation>45 The distorsion is due to the system used to rotate patches, as the first rotation (along x) also amends the orientation of the second axis of rotation (along y). and I believe that, in this case, the problem will disappear if you rotate first along the Y axis and then along the axis X, (perhaps the ideal would be able to choose the order of rotation axis ...) What do you think? -Andrea --------------------------------------- cubic { "front.jpg", --front "right.jpg", --right "back.jpg", --back "left.jpg", --left "top.jpg", --top "bottom.jpg" --bottom } function setpos(p,dis,az,el) local nz=math.cos(math.rad(az))*dis*math.cos(math.rad(el)) local nx=math.sin(math.rad(az))*dis*math.cos(math.rad(el)) local ny=math.sin(math.rad(el))*dis p:move{nx=nx, ny=ny ,nz=nz, anglex=el2, angley=az } end onkeydown ( function(key) local press="no" if key == pipmak.key_arrow_right then az=az+10 press="yes" end if key == pipmak.key_arrow_left then az=az-10 press="yes" end if key == pipmak.key_arrow_up then el=el+10 press="yes" end if key == pipmak.key_arrow_down then el=el-10 press="yes" end if press=="yes" then setpos(sun,di,az,el) end end ) pipmak.setverticalfov(70) -- initial position of the sun: az = 0 el = 45 di = 2 -- "sun.png" is simply a yellow circle on trasparent png 80x80 pixel sun=patch {nx=0, ny=0 ,nz=0, anchorh=40,anchorv=40, w=80, h=80,image="sun.png",visible=true } setpos(sun,di,az,el) ------------------------------------------------------------- |