Making my first 3D scene with a shadow

Started by
17 comments, last by Programmer101 16 years, 10 months ago
Quote:Original post by Vinniee
Thanks for explaining that dude. So how should I implent this in my code?

Also, I'm trying to rotate my object along the X and Y axis. But I only can rotate it along the X axis.

This is the part of the code I'm talking about:

*** Source Snippet Removed ***

Does anyone know what I'm doing wrong?
I can't seem to use the function SetTransform() multiple times.


try this:

D3DXMATRIX matRotate;D3DXMatrixMultiply(&matRotate,&matRotateX, matRotateY);d3ddev->SetTransform(D3DTS_WORLD, &(matRotate));


Advertisement
Quote:Original post by Tutukun
Quote:Original post by Vinniee
Thanks for explaining that dude. So how should I implent this in my code?

Also, I'm trying to rotate my object along the X and Y axis. But I only can rotate it along the X axis.

This is the part of the code I'm talking about:

*** Source Snippet Removed ***

Does anyone know what I'm doing wrong?
I can't seem to use the function SetTransform() multiple times.


try this:

*** Source Snippet Removed ***


Thanks for the quick reply!

It gives me this error:

Quote:error C2664: 'D3DXMatrixMultiply' : cannot convert parameter 3 from 'D3DXMATRIX' to 'const D3DXMATRIX *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Quote:Original post by Vinniee
Quote:Original post by Tutukun
Quote:Original post by Vinniee
Thanks for explaining that dude. So how should I implent this in my code?

Also, I'm trying to rotate my object along the X and Y axis. But I only can rotate it along the X axis.

This is the part of the code I'm talking about:

*** Source Snippet Removed ***

Does anyone know what I'm doing wrong?
I can't seem to use the function SetTransform() multiple times.


try this:

*** Source Snippet Removed ***


Thanks for the quick reply!

It gives me this error:

Quote:error C2664: 'D3DXMatrixMultiply' : cannot convert parameter 3 from 'D3DXMATRIX' to 'const D3DXMATRIX *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


my bad, it was a typo. It's supposed to be '&matRotateY' not 'matRotateY'

D3DXMATRIX matRotate;D3DXMatrixMultiply(&matRotate,&matRotateX, &matRotateY);d3ddev->SetTransform(D3DTS_WORLD, &(matRotate));


Quote:Original post by Tutukun
Quote:Original post by Vinniee
Quote:Original post by Tutukun
Quote:Original post by Vinniee
Thanks for explaining that dude. So how should I implent this in my code?

Also, I'm trying to rotate my object along the X and Y axis. But I only can rotate it along the X axis.

This is the part of the code I'm talking about:

*** Source Snippet Removed ***

Does anyone know what I'm doing wrong?
I can't seem to use the function SetTransform() multiple times.


try this:

*** Source Snippet Removed ***


Thanks for the quick reply!

It gives me this error:

Quote:error C2664: 'D3DXMatrixMultiply' : cannot convert parameter 3 from 'D3DXMATRIX' to 'const D3DXMATRIX *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


my bad, it was a typo. It's supposed to be '&matRotateY' not 'matRotateY'

*** Source Snippet Removed ***


Ah thanks mate! It works :)

This is my current code:

D3DXMATRIX matRotX, matRotY, matRotZ, matTrans, matWorld;	static float XAngle, YAngle, ZAngle, XPos, YPos, ZPos = 0.0f;	if ( KEY_DOWN(VK_LEFT) )		XAngle += 0.03f; 	if ( KEY_DOWN(VK_RIGHT) )		XAngle -= 0.03f;	if ( KEY_DOWN(VK_DOWN) )		YAngle += 0.03f;    	if ( KEY_DOWN(VK_UP) )		YAngle -= 0.03f;	D3DXMatrixRotationX(&matRotX, XAngle);	D3DXMatrixRotationY(&matRotY, YAngle);	D3DXMatrixRotationZ(&matRotZ, ZAngle);	D3DXMatrixTranslation(&matTrans, ZAngle, XAngle, YAngle);	D3DXMatrixIdentity(&matWorld);	D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans);	D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ);	D3DXMatrixMultiply(&matWorld, &matWorld, &matRotY);	D3DXMatrixMultiply(&matWorld, &matWorld, &matRotX);	d3ddev->SetTransform(D3DTS_WORLD, &(matWorld));


So what exactly does this do? I know that it changes the location of the object, but how exactly does it work? Is this world transform what we have discussed before? So that the object "moves" from the origin to a given position?

Thanks :)
Yes it is the world transform. This code:

     D3DXMatrixRotationX(&matRotX, XAngle);	D3DXMatrixRotationY(&matRotY, YAngle);	D3DXMatrixRotationZ(&matRotZ, ZAngle);


this sets the rotation values where XAngle is the x rotational value, YAngle is the y rotational value and ZAngle is the z rotational value.

This code:

D3DXMatrixTranslation(&matTrans, ZAngle, XAngle, YAngle);


this moves the object. The only problem is that you need to change it to this:

D3DXMatrixTranslation(&matTrans, XPos, YPos, ZPos);


where XPos is the x translation, YPos is the y translation, and ZPos is the z translation.

This code:

D3DXMatrixIdentity(&matWorld)


this clears the world matrix.

Then this code:

     D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans);	D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ);	D3DXMatrixMultiply(&matWorld, &matWorld, &matRotY);	D3DXMatrixMultiply(&matWorld, &matWorld, &matRotX);


this combines all of the rotations and translations into one matrix.

Finally this:

d3ddev->SetTransform(D3DTS_WORLD, &(matWorld));


this sets the transform.
Thanks for the explanation mate!

So how do I get the object to stay in the origin and the wall to display behind the object? :)
Well just set the world matrix like this:

D3DXMatrixRotationX(&matRotX, XAngle);D3DXMatrixRotationY(&matRotY, YAngle);D3DXMatrixRotationZ(&matRotZ, ZAngle);D3DXMatrixTranslation(&matTrans, 0.0f, 0.0f, 0.0f);D3DXMatrixIdentity(&matWorld);D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans);D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ);D3DXMatrixMultiply(&matWorld, &matWorld, &matRotY);D3DXMatrixMultiply(&matWorld, &matWorld, &matRotX);d3ddev->SetTransform(D3DTS_WORLD, &matWorld);


then draw the object and it will be at the origin.

Then set the world matrix like this:

D3DXMatrixRotationX(&matRotX, XAngle);D3DXMatrixRotationY(&matRotY, YAngle);D3DXMatrixRotationZ(&matRotZ, ZAngle);D3DXMatrixTranslation(&matTrans, 0.0f, 0.0f, 10.0f/*distance of wall behind object*/);D3DXMatrixIdentity(&matWorld);D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans);D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ);D3DXMatrixMultiply(&matWorld, &matWorld, &matRotY);D3DXMatrixMultiply(&matWorld, &matWorld, &matRotX);d3ddev->SetTransform(D3DTS_WORLD, &matWorld);


and draw the wall. Make sure that your view is facing down the positive z axis. You could set it like this:

D3DXMatrixRotationX(&matRotX, -XAngle);D3DXMatrixRotationY(&matRotY, -YAngle);D3DXMatrixRotationZ(&matRotZ, -ZAngle);D3DXMatrixTranslation(&matTrans, 0.0f, 0.0f, 5.0f);D3DXMatrixIdentity(&matView);D3DXMatrixMultiply(&matView, &matView, &matTrans);D3DXMatrixMultiply(&matView, &matView, &matRotZ);D3DXMatrixMultiply(&matView, &matView, &matRotY);D3DXMatrixMultiply(&matView, &matView, &matRotX);d3ddev->SetTransform(D3DTS_VIEW, &matView);
Thanks! It works :)

It it difficult to add bloom or HDR lighting to this scene?
Yes. You will have to do some post processing which involves changing your program around a bit. I may be wrong in the fact of it being hard, but I've never gotten it to work so I think it may be difficult.

You will need to render the scene to a texture, then put that texture on a full screen quad. Somebody else will have to post the details because I'm not completely sure how to make the shaders.

This topic is closed to new replies.

Advertisement