Cube geometry has equal lengths but appears squashed

Started by
5 comments, last by ocelot663 17 years, 3 months ago
Hi i'm pretty new to game programming, but currently have folowed tutorials and have a cube in the centre of the screen...The problem is although the cubes sides are all equal in the code, it appears alot wider than it is high on the screen, does anybody know how to solve this.... sorry if i haven't given enough information but i'm not entirely sure what info you might need, so please ask what info you need thanks EDIT: 'squashed' is not a good subject line, please be more descriptive in the future. [Edited by - jollyjeffers on December 20, 2006 7:50:23 AM]
Advertisement
If you post some code we'll be able to spot the problem, namely the class in which you initialise your geometry and secondly the one in which you are transforming your matrices. The most likely cause of this (since you say you have the same dimensions for the cube) is the scaling matrix you're multiplying by before you render isn't perfectly square.

Edit: Easier yet you could point us to tutorial you're using! :)
Sounds like you're not setting the aspect ratio correctly. How do you set your projection matrix up?
If all the parts of your cube are equal in your code but not on your screen, I would say the problem is in the projection matrix you use.

I don't know for sure but I would say that the problem would happen if you defined a projection with an aspect ratio different that the aspect ratio of you resolution. For example, if you render fullscreen in 640x480, your aspect ratio would be 640/480 = 1.3333.

Then, the field-of-view also influence the look / render of your render.

You should seek a tutorial about projections and / or post your code about the projection matrix.

Feel free to correct me if I made mistakes,
Hope it helps,
Sebastien

[EDIT: too slow, Evil Steve was faster than me :d ]
Lead programmer of the (slowly evolving) syBR game engine --- http://sybr.sourceforge.net
the tutorial i am using is

http://www.directtutorial.com/DX9/Direct3D/dx9-B7.php

(click 'show code' just above the last picture to see the code i used) but i changed the SCREENWIDTH and SCREENHEIGHT to 1024 and 768 respectively, and replaced the code defining the spaceships vertices with the code for the cube from further up the page.

my perspective matrix is:

D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(45), SCREEN_WIDTH / SCREEN_HEIGHT, 1.0f, 1000.0f);

Hi.

I would say the problem come from that piece of code:
    D3DXMATRIX matProjection;    // the projection transform matrix    D3DXMatrixPerspectiveFovLH(&matProjection,                               D3DXToRadian(45),    // the horizontal field of view                               SCREEN_WIDTH / SCREEN_HEIGHT,    // the aspect ratio                               1.0f,   // the near view-plane                               100.0f);    // the far view-plane


But you defined SCREEN_WIDTH and SCREEN_HEIGHT as :
#define SCREEN_WIDTH 1024#define SCREEN_HEIGHT 768


The compiler use them as integers and so 1024/768=1. You should convert them to floats (1024.0f and 768.0f). It could generate a few warnings.

Sebastien
Lead programmer of the (slowly evolving) syBR game engine --- http://sybr.sourceforge.net
ahhh! problem solved. thanks everybody!

This topic is closed to new replies.

Advertisement