IonicWind Software

IWBasic => 3D Programming => Topic started by: RG on May 20, 2008, 07:43:21 PM

Title: Transforming a Vertice
Post by: RG on May 20, 2008, 07:43:21 PM
I've been reading and searching direct3D tutorials but haven't found the answer so thought I'd ask here. I have a program that creates a mesh which I can display, rotate and move without problem. Next I want to be able to move a vertice in the mesh independent of the mesh itself. I need to take the x,y,z coordinates and multiply that by the 4x4 transformation matrix. Is there a simple way in ebasic to multiply a vector (which contain the coordinates) with a matrix? Or how do I retrieve the individual elements from the matrix?

Thanks, Rich
Title: Re: Transforming a Vertice
Post by: Ionic Wind Support Team on May 20, 2008, 08:13:39 PM
Rich,
If I read your question correctly then MatrixTranslation(MATRIX4 mat, FLOAT  x, FLOAT  y, FLOAT  z) is the function your looking for. It's in the users guide.

Paul.
Title: Re: Transforming a Vertice
Post by: RG on May 21, 2008, 07:40:05 PM
Thanks Paul. This may get me on the right track. I had seen this but only thought of it as a way to translate the object not a vertice. Let me play with this a bit.

Rich



Title: Re: Transforming a Vertice
Post by: RG on May 22, 2008, 08:31:48 PM
I was trying to use these commands from the users guide:

MATRIX4 matresult, matpos, matrot
MatrixIdentity(matrot)
MatrixTranslation(matpos, 25.0, 10.0, -2)
MatrixRotation(matrot, 90 * 0.01745, 0, 0)
MatrixMultiply(matresult, matpos, matrot)

but I got compiler errors:

Compiling...
vasemaker001.eba
File: C:\Program Files\EBDev\projects\3D samples\vasemaker001.eba (569) Warning: undeclared function 'MatrixIdentity' - )
File: C:\Program Files\EBDev\projects\3D samples\vasemaker001.eba (570) Warning: undeclared function 'MatrixTranslation' - )
File: C:\Program Files\EBDev\projects\3D samples\vasemaker001.eba (571) Warning: undeclared function 'MatrixRotation' - )
File: C:\Program Files\EBDev\projects\3D samples\vasemaker001.eba (572) Warning: undeclared function 'MatrixMultiply' - )
C:\Program Files\EBDev\projects\3D samples\vasemaker001.a:7798: error: symbol `MatrixIdentity' undefined
C:\Program Files\EBDev\projects\3D samples\vasemaker001.a:7824: error: symbol `MatrixTranslation' undefined
C:\Program Files\EBDev\projects\3D samples\vasemaker001.a:7856: error: symbol `MatrixRotation' undefined
C:\Program Files\EBDev\projects\3D samples\vasemaker001.a:7866: error: symbol `MatrixMultiply' undefined
C:\Program Files\EBDev\projects\3D samples\vasemaker001.a:10996: error: phase error detected at end of assembly.
Error(s) in assembling "C:\Program Files\EBDev\projects\3D samples\vasemaker001.a"

I noticed the functions like MatrixIdentity did not show in the popup box in the IDE nor did they change color. Looking into the ebx3d.incc, I saw these commands had a dx in front of them. When I converted the commands to:

dxMatrixIdentity(matrot)
dxMatrixTranslation(matpos, 25.0, 10.0, -2)
dxMatrixRotation(matrot, 90 * 0.01745, 0, 0)
dxMatrixMultiply(matresult, matpos, matrot)

They did show in the popup box and with a blue color, making it look like this was the proper spelling. However I get the following compiler message:

Compiling...
vasemaker001.eba
No Errors

Linking...
Emergence Linker v1.11 Copyright ÂÃ,© 2006 Ionic Wind Software
Unresolved external __imp_dxMatrixIdentity
Error: Unresolved extern __imp_dxMatrixIdentity
Error: Unresolved extern __imp_dxMatrixTranslation
Error: Unresolved extern __imp_dxMatrixRotation
Error: Unresolved extern __imp_dxMatrixMultiply
Error(s) in linking C:\Program Files\EBDev\projects\3D samples\vasemaker001.exe

Not clear to me what I'm doing wrong.

Rich


Title: Re: Transforming a Vertice
Post by: LarryMc on May 23, 2008, 01:02:28 AM
Appears there is a naming mismatch somewhere.

In the ebx3d.incc file you have:$command CDECL IMPORT, dxMatrixIdentity(mat as MATRIX4)
$command CDECL IMPORT, dxMatrixTranslation(mat as MATRIX4,x as FLOAT,y as FLOAT,z as FLOAT)
$command CDECL IMPORT, dxMatrixRotation(mat as MATRIX4,x as FLOAT,y as FLOAT,z as FLOAT)
$command CDECL IMPORT, dxMatrixMultiply(out as MATRIX4,m1 as MATRIX4,m2 as MATRIX4)

I got a file to compile by using :MATRIX4 matresult, matpos, matrot
MatrixIdentity(matrot)
MatrixTranslation(matpos, 25.0, 10.0, -2)
MatrixRotation(matrot, 90 * 0.01745, 0, 0)
MatrixMultiply(matresult, matpos, matrot)

after I changed the ebx3d.incc lines to:$command CDECL IMPORT, MatrixIdentity(mat as MATRIX4)
$command CDECL IMPORT, MatrixTranslation(mat as MATRIX4,x as FLOAT,y as FLOAT,z as FLOAT)
$command CDECL IMPORT, MatrixRotation(mat as MATRIX4,x as FLOAT,y as FLOAT,z as FLOAT)
$command CDECL IMPORT, MatrixMultiply(out as MATRIX4,m1 as MATRIX4,m2 as MATRIX4)


Have no idea if the functions even work when I do that but at least it compiled and makes me think(based upon your results and my results) that there is a name mismatch somewhere. Possibly missing aliases?

Paul will probably tell me I'm all wet as usual and it's us doing something totally wrong. ;D

Larry
Title: Re: Transforming a Vertice
Post by: RG on May 23, 2008, 05:28:58 PM
Larry,

Thanks! I had the same thought but was hesitant to mess with the .incc file. But I went ahead and deleted the extra dx's and it appears to work. I made a small console program, used the MatrixIdentity command, and printed out the matrix. It looks as it should with diagonal one's.

OPENCONSOLE

MATRIX4 matresult
MatrixIdentity(matresult)
FOR i=0 to 3
PRINT matresult.m[i,0],matresult.m[i,1],matresult.m[i,2],matresult.m[i,3]
NEXT i
PRINT
PRINT "Press Any Key To Close"
DO
UNTIL INKEY$ <> ""
CLOSECONSOLE
END


I did the same with the other matrix commands and they appear to work too.

Now I can move forward  :D

Rich
Title: Re: Transforming a Vertice
Post by: RG on May 23, 2008, 08:24:52 PM
Now I'm even happier  ;D  Was able to get vertice translation and rotation to work in my vasemaker program. After I add some controls, I'll publish an updated version.
Title: Re: Transforming a Vertice
Post by: RG on June 07, 2008, 04:17:25 PM
Used these learnings to revise Vasemaker code:

http://www.ionicwind.com/forums/index.php/topic,2000.0.html (http://www.ionicwind.com/forums/index.php/topic,2000.0.html)