Jump to content
  • Advertisement
Sign in to follow this  
Whorse

Cube Rendering Issue DirectX

This topic is 2608 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

Hey there all, working on my engine and have started implementing 3D features. At the moment I'm attempting to render a rotating cube, but am getting an error I can't quite pin point as my experience with DirectX is limited to 2D stuff. Basically I create, render and rotate something, however it's just a white vertical line and far from the cube I want it to be. I'm assuming it's a transform issue, however I can't be sure. I know it's a bit of a long shot, but does anyone have any opinions?

Cheers!

Share this post


Link to post
Share on other sites
Advertisement
If you dont post any code or at least some images of the error no one will be able to help you.

Try posting the parts of the code where you define the vertices/indices, create the buffers and apply transformations...

Share this post


Link to post
Share on other sites
I'm using the D3DXCreateBox function to create the cube.

This is what it looks like:

http://imageshack.us/photo/my-images/511/issue.jpg/

The vertical line can be seen rotating around an axis, so I know the rotation is at least functioning correctly. ^_^

The transform is as follows:

void Transform()
{
float x = D3DXToRadian(rotation.x);
float y = D3DXToRadian(rotation.y);
float z = D3DXToRadian(rotation.z);

D3DXMatrixRotationYawPitchRoll(&matRotate, x, y, z);

D3DXMatrixScaling(&matScale, scale.x, scale.y, scale.z);

D3DXMatrixTranslation(&matTranslate, position.x, position.y, position.z);

matWorld = matRotate * matScale * matTranslate;
Globals::GetRenderer()->GetDevice()->SetTransform(D3DTS_WORLD, &matWorld);
}

Share this post


Link to post
Share on other sites
Try replacing "matWorld = matRotate * matScale * matTranslate;" with something simpler like "matWorld = matRotate;" and test one thing at a time.

Share this post


Link to post
Share on other sites

Try replacing "matWorld = matRotate * matScale * matTranslate;" with something simpler like "matWorld = matRotate;" and test one thing at a time.


I'm starting to think it might be an issue with the Camera. Could I be on the right track here?

Share this post


Link to post
Share on other sites
Which version of the API are you using? It sounds to me like a problem with either the projection or the view matrix - most likely something with the projection matrix. Can you post your code showing how you set up those matrices?

Share this post


Link to post
Share on other sites

Which version of the API are you using? It sounds to me like a problem with either the projection or the view matrix - most likely something with the projection matrix. Can you post your code showing how you set up those matrices?


I'm using 9.

Here's the projection matrix code in a concise view:


SetPerspective(3.14159f / 4, 640 / 480, 1.0f, 2000.0f);

void SetPerspective(const float fov, const float aspectRatio, const float nearRange, const float farRange)
{
SetFOV(fov);
SetAspectRatio(aspectRatio);
SetNearRange(nearRange);
SetFarRange(farRange);
}

void Update()
{
D3DXMatrixPerspectiveFovLH(&matrixProj, fov, aspectRatio, nearRange, farRange);
Globals::GetRenderer()->GetDevice()->SetTransform(D3DTS_PROJECTION, &matrixProj);

D3DXMatrixLookAtLH(&matrixView, &position, &target, &upDir);
Globals::GetRenderer()->GetDevice()->SetTransform(D3DTS_VIEW, &matrixView);
}


That should give you a good idea of how the projection is set.

Share this post


Link to post
Share on other sites
It might be a long shot, but try to define your aspect ratio as two floating point values. So instead of using (640 / 480), use (640.0f / 480.0f). I think you might be setting the aspect ratio to something based on integer math (if you are using exactly the method that you posted...).

Share this post


Link to post
Share on other sites
The function is pretty much exactly the same as I listed. It's weird because I'm unable to move the camera from the looks of things, which is what led me to believe it was an issue with the camera in the first place. Unfortunately even specifying the values as floats didn't make a difference.

***EDIT***

I forgot to mention I have similar issues trying a sphere. What appears to be an outline of the sphere's circumference is shown while it rotates. Here is a picture, maybe it will help shed some light on the issue.

http://i53.tinypic.com/2rgjls9.jpg

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!