Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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
	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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!