# Help with projection matrix

This topic is 3621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im trying to do this via maxscript to bear with me :) What im trying to do is to convert my mesh into camera space using the code from here http://msdn.microsoft.com/en-us/library/ms537094.aspx. It works ok but the depth values arent working. For example I set my near plane to 4cm and my far to 7 cm and put my teapot further away than 7cm and it still shows up inside my unit cube :( This is the matrix I am generating here (matrix4 [8,0,0,0][0,3,0,18][0,0,8,0][0,-1,0,0])

-- for testing, clipping planes
mNear = 40 -- cm
mFar = 70 -- cm
-- http://msdn.microsoft.com/en-us/library/ms537094.aspx

A =	(right + left) / (right - left)
B = (top + bottom) / (top - bottom)
C = (mFar + mNear) / (mFar - mNear)
D = (2 * mFar * mNear) / (mFar - mNear)
E = -1
F = (2 * mNear) / (right - left)
G = (2 * mNear) / (top - bottom)

-- NOTE: Need to rotate OGL matrix right to get a 3ds matrix!!

mProjectionMatrix = Matrix4 0 -- my own matrix structure
mProjectionMatrix.row1 = Point4 F 0 A 0
mProjectionMatrix.row2 = Point4 0 G B 0
mProjectionMatrix.row3 = Point4 0 0 C D
mProjectionMatrix.row4 = Point4 0 0 E 0

mProjectionMatrix.print()

mNumVerts = mGeometry.numverts
for i = 1 to mNumVerts do
(
mVertPos = meshop.getVert valGeometry i
mNewVertPos = mVertPos * mViewMatrix -- camera view matrix
mNewVertPos = mProjectionMatrix.multiplyPoint mNewVertPos  -- multiply my projection matrix and the point of a mesh
meshop.setVert valGeometry i mNewVertPos
)

-- mesh is output in the 3ds max viewport



1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 24
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633695
• Total Posts
3013373
×