PDA

View Full Version : Transforming vertex to camera space


lechoo
04-06-2006, 10:43 AM
Hi,
I'm trying to draw single pixels on a bitmap where object's verts will appear in rendered image. However they aren't exactly where they should be. You can see my bitmap composed over scanline rendering here: scaleBox.jpg (http://67.19.72.217/adam/trash/scaleBox.jpg). It looks as if there was slight difference in scale but I have no idea what causes this.

This is source code of my script
myPic = bitmap 640 480
myMesh = $Box01
myCam = $Camera01
pixPos = [0,0]

for i in 1 to (getNumVerts myMesh) do
(
v = getVert myMesh i
worldv = v

camv = worldv * (inverse myCam.transform)

pixPos.x = (atan (camv.x / -camv.z)) / (myCam.fov/2.0) * (myPic.Width / 2.0) + (myPic.Width / 2.0)
pixPos.y = (atan (-camv.y / -camv.z)) / ((myCam.fov/2.0) * (myPic.Height / (myPic.Width as float))) * (myPic.Height / 2.0) + (myPic.Height / 2.0)

picColor = #(color 255 255 255)
setPixels myPic [pixPos.x as integer, pixPos.y as integer] picColor
)

display myPic
There's propably something wrong with the way I calculate pixPos but I have no idea what. Can anyone help me to make this work right?

magicm
04-06-2006, 02:46 PM
Check out the example in the maxscript reference:
"How To ... Develop a Vertex Renderer"

Cheers,
Martijn

lechoo
04-09-2006, 08:34 AM
Thanks, Martijn.
I also found another example in maxsdk help.

regards

CGTalk Moderation
04-09-2006, 08:34 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.