Transformations

Started by
1 comment, last by crazy166 24 years, 1 month ago
sorry for longish post, but i''m at the end of my rope. here is code that doesn''t display anything at all: D3DMATRIX projMatrix, viewMatrix, destMatrix1, destMatrix2; D3DVECTOR scrCenter( 400.0f, 300.0f, 0.0f ); D3DUtil_SetTranslateMatrix( destMatrix1, scrCenter ); D3DUtil_SetProjectionMatrix( projMatrix, 3.141592f/4.0f, 1.0f, 1.0f, 100.0f ); D3DMath_MatrixMultiply( destMatrix2, destMatrix1, projMatrix ); projMatrix = destMatrix2; D3DVECTOR vEyePt = m_vPos; // m_vPos is a vector describing camera pos (init 0,0,-1) D3DVECTOR vLookatPt = D3DVECTOR( 0.0f, 0.0f, 0.0f ); D3DVECTOR vUpVec = D3DVECTOR( 0.0f, 1.0f, 0.0f ); D3DUtil_SetViewMatrix( destMatrix, vEyePt, vLookatPt, vUpVec ); pd3d->SetTransformState( D3DTRANSFORMSTATE_PROJECTION, projMatrix ); pd3d->SetTransformState( D3DTRANSFORMSTATE_VIEW, viewMatrix ); D3DVECTOR lpVerts[4]; lpVerts[0] = D3DVECTOR( -1.0f, -1.0f, 0.0f ); lpVerts[1] = D3DVECTOR( 5.0f, -1.0f, 0.0f ); lpVerts[2] = D3DVECTOR( -1.0f, 5.0f, 0.0f ); lpVerts[3] = D3DVECTOR( 5.0f, 5.0f, 0.0f ); D3DLVERTEX verts[] = { D3DLVERTEX( lpVerts[0], RGB_MAKE(255,255,255), RGB_MAKE(0,0,0), 0.0f, 0.0f ), D3DLVERTEX( lpVerts[1], RGB_MAKE(255,255,255), RGB_MAKE(0,0,0), 1.0f, 0.0f ), D3DLVERTEX( lpVerts[2], RGB_MAKE(255,255,255), RGB_MAKE(0,0,0), 0.0f, 1.0f ), D3DLVERTEX( lpVerts[3], RGB_MAKE(255,255,255), RGB_MAKE(0,0,0), 1.0f, 1.0f ) }; pdxInterface->DrawPrimitive( D3DPT_TRIANGLESTRIP, D3DFVF_LVERTEX, (LPVOID)verts, 4, NULL); here is code that displays something ok straight on but is all f* up as soon as camera moves: D3DMATRIX projMatrix, destMatrix, destMatrix1, destMatrix2; D3DVECTOR scrCenter( 400.0f, 300.0f, 0.0f ); D3DUtil_SetTranslateMatrix( destMatrix1, scrCenter ); D3DUtil_SetProjectionMatrix( projMatrix, 3.141592f/4.0f, 1.0f, 1.0f, 100.0f ); D3DMath_MatrixMultiply( destMatrix2, destMatrix1, projMatrix ); projMatrix = destMatrix2; D3DVECTOR vEyePt = m_vPos; // m_vPos is a vector describing camera pos (init 0,0,-1) D3DVECTOR vLookatPt = D3DVECTOR( 0.0f, 0.0f, 0.0f ); D3DVECTOR vUpVec = D3DVECTOR( 0.0f, 1.0f, 0.0f ); D3DUtil_SetViewMatrix( destMatrix, vEyePt, vLookatPt, vUpVec ); D3DMath_MatrixMultiply( m_mComposite, destMatrix1, projMatrix ); D3DVECTOR lpVerts[4]; lpVerts[0] = D3DVECTOR( -1.0f, -1.0f, 0.0f ); lpVerts[1] = D3DVECTOR( 5.0f, -1.0f, 0.0f ); lpVerts[2] = D3DVECTOR( -1.0f, 5.0f, 0.0f ); lpVerts[3] = D3DVECTOR( 5.0f, 5.0f, 0.0f ); D3DMath_VectorMatrixMultiply( lpVerts[0], lpVerts[0], m_mComposite ); D3DMath_VectorMatrixMultiply( lpVerts[1], lpVerts[1], m_mComposite ); D3DMath_VectorMatrixMultiply( lpVerts[2], lpVerts[2], m_mComposite ); D3DMath_VectorMatrixMultiply( lpVerts[3], lpVerts[3], m_mComposite ); D3DTLVERTEX verts[] = { D3DTLVERTEX( lpVerts[0], 1.0f, RGB_MAKE(255,255,255), RGB_MAKE(0,0,0), 0.0f, 0.0f ), D3DTLVERTEX( lpVerts[1], 1.0f, RGB_MAKE(255,255,255), RGB_MAKE(0,0,0), 1.0f, 0.0f ), D3DTLVERTEX( lpVerts[2], 1.0f, RGB_MAKE(255,255,255), RGB_MAKE(0,0,0), 0.0f, 1.0f ), D3DTLVERTEX( lpVerts[3], 1.0f, RGB_MAKE(255,255,255), RGB_MAKE(0,0,0), 1.0f, 1.0f ) }; pdxInterface->DrawPrimitive( D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, (LPVOID)verts, 4, NULL); what i don''t understand is the same damn params to the SetTransformState(...) (1st example) calls work fine in an overhauled version of one of the samples but not in mine. what i also don''t understand is why the second version doesn''t work either. it works relatively well orthographic, but you should see it. it is the most f* up thing i''ve ever seen. i''ve read dozens of books and tutorials and used twice that many different projection matrices. why doesn''t one of the 3 different ones provided in dx7 sdk doc work? and why the hell can''t d3d transform my f* vertices? it won''t work even with Identity matrices selected into transforms. thanks (sorry about pissed off attitude, but i''ve worked on this enough myself, it''s time for someone to tell me how to do it). thanks again in advance. i''ll even send you money to help me fix this. i''m at the end of my rope. crazy166 some people think i'm crazy, some people know it
Advertisement
Hi

You forgot to apply your matrices to the Render Device.
You need to call the IDirect3DDevice7::SetTransform Function
with the appropriate Matrices, in your first Function, you are using a SetTransformState Function, which i never heard from, and the DirectX Help File doesn't know it too.

The Problem with the Transforming by Hand, which you do in the second Code Part, was an Problem i got too, and it took me some time to get it working, but it never looked the same as when D3D transforms the Vertices.
i did it the folowing way : i applied the transformation and View Matrices, and then made the following projective transformation "by hand"




float rhz=1.0f/(ausgabe.punkte.punkt.z);

ausgabe.punkte.punkt.z=ausgabe.punkte.punkt.z/(2500000.0f-10.0f);<br> ausgabe.punkte.punkt.x=ausgabe.punkte.punkt.x*rhz*yres+xres/2.0f;<br> ausgabe.punkte.punkt.y=-ausgabe.punkte.punkt.y*rhz*yres+yres/2.0f;<br> ausgabe.punkte.rhw=rhz;<br></TT><br><BR><br>Sorry, that it is in German ( ausgabe <=> output, punkt <=> point ). I think the main Problem, was to put in the resolution. Don't ask me why i using the y-Resolution two times, but i only tried to getting it look good.<br>I never tried it again, maybe in the future. I hope it helps you a bit :-)<br><br>Lars </i> <br><br>Edited by - Lars W. on 3/17/00 8:08:25 PM
--------> http://www.larswolter.de <---------
well, thanx for reply. yes, i use SetTransform or whatever, the problem with the code in the post was i pulled all of the vert transforms out of a CCamera class (while still showing exactly what the code does), i just plumb forgot whether the function was SetTransform or SetTransformState or whatever.
it totally is boggling me. right now i''m just taking the source from the D3DFrame apps and modifying them to fit what i need, but eventually it will get too difficult (that is, reverse modifying the d3dframe code instead of my own from scratch).

thanx again,
crazy166

some people think i'm crazy, some people know it

This topic is closed to new replies.

Advertisement