PDA

View Full Version : Davey I need your big brain again! I am in the dark



Digits
10-10-01, 10:32 AM
Heh, sorry to keep pestering you with my little problems :) I am trying to figure out how to convert the Z Postitioning of a light to object cords. The XY cords were pretty easy. This routine will convert an objects XY postion into Light cords and move the light position to correspond

<BLOCKQUOTE>quote:</font><HR>
[RoutineDef,FollowObjectwithLight,
[VarSet,dWidth,DOCUMENT:MODIFIERS:WIDTH]
[VarSet,dHeight,DOCUMENT:MODIFIERS:HEIGHT]
[VarSet,dMidX,dWidth/2]
[VarSet,dMidY,dHeight/2]
[VarDef,opic,0]
[VarDef,lx,0]
[VarDef,ly,0]
[VarDef,dptr,0]
//xdata and ydata is array of the objects xy position indexed by dptr
[if,[isenabled,light:modifiers:Placement],
[VarSet,dptr,(opic*50)+Frame]
[VarSet,opic,[IGet,zscript:Follow]]
[VarSet,lx,(((xdata(dptr)-dmidx)*100)/dwidth)/100]
[VarSet,ly,(((ydata(dptr)-dmidy)*100)/dheight)/100]
[ISet,Light:Modifiers:Placement:Locallightxpos,lx]
[ISet,Light:Modifiers:Placement:Locallightypos,ly]
]
]
<HR></BLOCKQUOTE>

The X & Y is referenced to the Doc Width and Height so it is easy to figure out. But I have been unable to figure out what reference the Z axis uses. I have made tests in excel sampling the result of different positions in z but I still can't seem to get it. It seems that the clipping plane changes in regards to Doc width and height but that doesn't seem to help me either. Anyhoo, you probably have the answer I hope! Thanks!

Pixolator
10-10-01, 12:38 PM
Hi Digits,

The lights’ x,y,z and radius values are based on an internally calculated unified size value which equals the average width and height of the current document.

the math…

document depth value = light z value * ( (document width + document height) /2 )

This function holds true for Lights as well as for Fog and DepthCue values

Hope this helps :)
-Pixolator

Digits
10-10-01, 06:16 PM
Thanks Pixolator, I appreciate the help, I need to keep what hair I have left on the top of my head and you saved them!

Here is the new routine
<BLOCKQUOTE>quote:</font><HR>
[RoutineDef,Follow,
[VarSet,dWidth,DOCUMENT:MODIFIERS:WIDTH]
[VarSet,dHeight,DOCUMENT:MODIFIERS:HEIGHT]
[VarSet,dMidX,dWidth/2]
[VarSet,dMidY,dHeight/2]
[VarDef,opic,0]
[VarDef,lx,0]
[VarDef,ly,0]
[VarDef,lz,0]
[VarDef,zadd,0]
[VarDef,dptr,0]
[if,[isenabled,light:modifiers:Placement],
[VarSet,opic,[IGet,zscript:Follow]]
[VarSet,opic,opic-1]
[VarSet,dptr,(opic*50)+Frame]
//convert object XY to light position data
[VarSet,lx,(((xdata(dptr)-dmidx)*100)/dwidth)/100]
[VarSet,ly,(((ydata(dptr)-dmidy)*100)/dheight)/100]
//move light out from center of object
[VarSet,zadd,zdata(dptr)-(zsdata(dptr)*2)]
//convert Z of object to ZPosition of light
[VarSet,lz,zadd/((dHeight+dWidth)/2)]
[ISet,Light:Modifiers:Placement:Locallightxpos,lx]
[ISet,Light:Modifiers:Placement:Locallightypos,ly]
[ISet,Light:Modifiers:Placement:Locallightzpos,lz]
]
]
<HR></BLOCKQUOTE>

Not done testing yet, hopefully tonight I will have a new test animation up.

I must say that your solution for uniforming the scale is ingenious! I am going to use the same method to update my ZDepth Reference Widget. So that you can size an object depending on where it is in ZDepth thus giving the illusion of perspective. This method is much better than the way I was figuring it out before.