Gibbz
02-14-2007, 08:04 AM
Ok the game engine has y and Z swapped around as per normal.
this is the code im running on a selected camera to get a projection matrix. It doesnt seem to be working.
If anyone has any experience with this could they give me some help?
-- Get Projection Matrix
clearListener()
myUnits = units.MetricType
units.MetricType = #centimeters
mapped fn fnMatrixMaxToEngine valMatrix = --takes a matrix output a string
(
mRow1 = valMatrix.row1
--for i = 1 to 3 do
--if mRow1[i] < 0.00001 do
-- mRow1[i] = 0
mRow2 = valMatrix.row2
--for i = 1 to 3 do
--if mRow2[i] < 0.00001 do
-- mRow2[i] = 0
mRow3 = -(valMatrix.row3) -- invert this as cam faces backwards!
--for i = 1 to 3 do
--if mRow3[i] < 0.00000001 do
-- mRow3[i] = 0
mTranslation = valMatrix.translation
print mTranslation
--for i = 1 to 3 do
--if mTranslation[i] < 0.00001 do
-- mTranslation[i] = 0
mString = (mRow1.X as string) + ", " + (mRow1.Z as string) + ", " + (mRow1.Y as string) + ", 0, " + (mRow3.X as string) + ", " + (mRow3.Z as string) + ", " + (mRow3.Y as string) + ", 0, " + (mRow2.X as string) + ", " + (mRow2.Z as string) + ", " + (mRow2.Y as string) + ", 0, " + (mTranslation.X as string) + ", " + (mTranslation.Z as string) + ", " + (mTranslation.Y as string) + ", 1"
return mString
)
for i = 1 to selection.count do
(
mObj = selection[i]
mMatrix = matrix3 1
--mMatrix = mObj.transform
mViewMatrix = inverse mObj.transform -- get camera view matrix
print mViewMatrix
-- cam shiz
mFov = mObj.fov
mDistanceToTarget = distance mObj.pos mObj.target.pos
mWidth = mDistanceToTarget * (tan (mFov/2))
mXScale = 1/(mWidth* 2) -- light:mObj.falloff
mYScale = mXScale * getRendImageAspect() -- light: mObj.aspect
mXScale = 1/1000.0
mYScale = 1/1000.0
mMatrix = scale mMatrix [mXScale,-mYScale,-mYScale]
--mMatrix = rotateX mMatrix 90
mMatrix.translation = [0.5, 0.5, 0.0]
mProj = mMatrix
mViewProj = mViewMatrix * mProj
--mMatrix.translation = mObj.transform.translation * 1/1000.0
--mMatrix = translate mMatrix [0.5, 0, 0.5]
mProjectionMatrix = fnMatrixMaxToEngine mViewProj
format "projectorMatrix = %\n" mProjectionMatrix
)
units.MetricType = myUnits
this is the code im running on a selected camera to get a projection matrix. It doesnt seem to be working.
If anyone has any experience with this could they give me some help?
-- Get Projection Matrix
clearListener()
myUnits = units.MetricType
units.MetricType = #centimeters
mapped fn fnMatrixMaxToEngine valMatrix = --takes a matrix output a string
(
mRow1 = valMatrix.row1
--for i = 1 to 3 do
--if mRow1[i] < 0.00001 do
-- mRow1[i] = 0
mRow2 = valMatrix.row2
--for i = 1 to 3 do
--if mRow2[i] < 0.00001 do
-- mRow2[i] = 0
mRow3 = -(valMatrix.row3) -- invert this as cam faces backwards!
--for i = 1 to 3 do
--if mRow3[i] < 0.00000001 do
-- mRow3[i] = 0
mTranslation = valMatrix.translation
print mTranslation
--for i = 1 to 3 do
--if mTranslation[i] < 0.00001 do
-- mTranslation[i] = 0
mString = (mRow1.X as string) + ", " + (mRow1.Z as string) + ", " + (mRow1.Y as string) + ", 0, " + (mRow3.X as string) + ", " + (mRow3.Z as string) + ", " + (mRow3.Y as string) + ", 0, " + (mRow2.X as string) + ", " + (mRow2.Z as string) + ", " + (mRow2.Y as string) + ", 0, " + (mTranslation.X as string) + ", " + (mTranslation.Z as string) + ", " + (mTranslation.Y as string) + ", 1"
return mString
)
for i = 1 to selection.count do
(
mObj = selection[i]
mMatrix = matrix3 1
--mMatrix = mObj.transform
mViewMatrix = inverse mObj.transform -- get camera view matrix
print mViewMatrix
-- cam shiz
mFov = mObj.fov
mDistanceToTarget = distance mObj.pos mObj.target.pos
mWidth = mDistanceToTarget * (tan (mFov/2))
mXScale = 1/(mWidth* 2) -- light:mObj.falloff
mYScale = mXScale * getRendImageAspect() -- light: mObj.aspect
mXScale = 1/1000.0
mYScale = 1/1000.0
mMatrix = scale mMatrix [mXScale,-mYScale,-mYScale]
--mMatrix = rotateX mMatrix 90
mMatrix.translation = [0.5, 0.5, 0.0]
mProj = mMatrix
mViewProj = mViewMatrix * mProj
--mMatrix.translation = mObj.transform.translation * 1/1000.0
--mMatrix = translate mMatrix [0.5, 0, 0.5]
mProjectionMatrix = fnMatrixMaxToEngine mViewProj
format "projectorMatrix = %\n" mProjectionMatrix
)
units.MetricType = myUnits
