Notifications
Clear all
[Closed] Using matrices to achive "lookat" effect
Aug 18, 2011 3:19 pm
This is difficult to explain, so please have a look at this example:
delete $point*
if NOT isvalidnode obj1 do obj1= Teapot pos:[0,0,0]
if NOT isvalidnode obj2 do obj2=Teapot pos:[100,100,100]
theTM = matrixFromNormal [1,0,0]
theNormalTM =matrixfromnormal (normalize (obj2.pos-obj1.pos))
for a = 0 to 324 by 36 do
(
rm = rotateZMatrix a
theRotTM = (theTM * rm) * theNormalTM
theRay = Ray theRotTM.row4 theRotTM.row3
point pos:((obj1.pos+obj2.pos)/2+(theray.dir*50)) wirecolor:(if a==0 then red else green) axistripod:off centermarker:on cross:off Box:off
)
What I’m trying to do is emit radial rays penpendicular to a vector.
Here the vector is between the position of the two teapots. You can move the teapots and rerun the script to see the effect.
I’m using point helpers to illustrate the rays. It seems to work, but the direction of the first ray, designated by the red point helper, tends to vary a lot and sometimes flips (gimbal lock?)
Ideally I’d want the first ray to be more predictable, like if its a clock face using a LookAt controller (facing the 2nd teapot) and the first ray is at 12’o clock… (I think this works if you were to use Axis Alignment as the Upnode control for the LookAt controller. )
Any ideas?
1 Reply
Aug 18, 2011 3:19 pm
check this
delete $point*
if NOT isvalidnode obj1 do obj1= Teapot pos:[0,0,0]
if NOT isvalidnode obj2 do obj2=Teapot pos:[100,100,100]
vx = normalize (obj2.pos-obj1.pos)
vy = normalize (cross [0,0,1] vx)
vz = cross vx vy
lookTM = matrix3 vx vy vz ((obj2.pos-obj1.pos) * .5)
for a = 0 to 324 by 36 do
(
Tm = copy lookTM
prerotatex Tm a
pretranslate Tm [0,0,50]
point pos:Tm.pos wirecolor:(if a==0 then red else green) axistripod:off centermarker:on cross:off Box:off
)