• Create Account

## Meshes look squished

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

10 replies to this topic

### #1ryan20fun  Members

Posted 01 January 2012 - 12:15 AM

Hi All.

for some reason the meshes looks to be vertically squashed, the white box if a perfect square.
im using GetClientRect to get the size for the back buffer and for the width and height param for the camera.

here is a pic of it:

here is the code im using for the camera( its a bit messy, but ill get around to cleaning it up later )
#include "StdAfx.h"
#include <d3dx9.h>
#include "TIPInput_Mouse_Async.h"
#include "TIPInput_Keyboard_Async.h"
#include "TIPVector3.h"
#define PIE D3DX_PI//3.1415926
{
return Radien * ( 180 / PIE  );
}
{
return Degree * ( PIE / 180  );
}
class Camera
{
public:
TIP::Physics::TIPVector3 Position;
TIP::Physics::TIPVector3 Target;
TIP::Physics::TIPVector3 Reference;
float aspectRatio;
float nearPlane;
float farPlane;
float fieldOfView;
D3DXMATRIX Projection;
D3DXMATRIX View;
float Yaw;
float Pitch;
TIP::Input::TIPInput_Mouse_Async mStateCashe;
int width, height;
public:
Camera()
{
nearPlane = 1.0f;
farPlane = 1000.0f;
fieldOfView = 45.0f;
Reference.Z = 1.0f;
Target = Reference + Position;
Yaw = 0.0f;
Pitch = 0.0f;
}
void Initialize( int ScreenWidth, int ScreenHeight )
{
width = ScreenWidth;
height = ScreenHeight;
aspectRatio = ScreenWidth / ScreenHeight;
D3DXMatrixPerspectiveFovLH( &Projection, rad, aspectRatio, nearPlane, farPlane );
SetCursorPos( ScreenWidth / 2, ScreenHeight / 2 );
mStateCashe.GetState();
}
void Update( float DeltaTime )
{
TIP::Input::TIPInput_Mouse_Async mouse;
TIP::Input::TIPInput_Keyboard_Async keyboard;
mouse.GetState();
keyboard.GetState();
TIP::Physics::TIPVector3 moveVector;
if ( keyboard.IsKeyDown( 'W' ) )
moveVector.Z += 150 * DeltaTime;
if ( keyboard.IsKeyDown( 'S' ) )
moveVector.Z -= 150 * DeltaTime;
if ( keyboard.IsKeyDown( 'A' ) )
moveVector.X -= 150 * DeltaTime;
if ( keyboard.IsKeyDown( 'D' ) )
moveVector.X += 150 * DeltaTime;
if ( keyboard.IsKeyDown( VK_CONTROL ) )
moveVector.Y -= 150 * DeltaTime;
else if ( keyboard.IsKeyDown( VK_SPACE ) )
moveVector.Y += 150 * DeltaTime;
float mouseX = mouse.State.Position_X - mStateCashe.State.Position_X;
float mouseY = mouse.State.Position_Y - mStateCashe.State.Position_Y;
Pitch += (mouseY * 0.15f) * DeltaTime;
Yaw += (mouseX * 0.15f) * DeltaTime;

if( Pitch < DegreeToRadian( -89.9f ) )
else if( Pitch > DegreeToRadian( 89.9f ) )
SetCursorPos( width / 2, height / 2 );
D3DXMATRIXA16 ViewRotationMatrix, MoveRotationMatrix, rotx, roty;
D3DXMatrixRotationX( &rotx, Pitch );
D3DXMatrixRotationY( &roty, Yaw );
ViewRotationMatrix = rotx * roty;
MoveRotationMatrix = roty;

D3DXVECTOR3 vec( Reference.X, Reference.Y, Reference.Z );
D3DXVECTOR3 transformedCameraReference;
D3DXVec3TransformCoord( &transformedCameraReference, &vec, &ViewRotationMatrix );

D3DXVECTOR3 vec3;
vec.x = moveVector.X;
vec.y = moveVector.Y;
vec.z = moveVector.Z;
D3DXVec3TransformCoord( &vec3, &vec, &MoveRotationMatrix );
Position.X += vec3.x;
Position.Y += vec3.y;
Position.Z += vec3.z;
Target.X = transformedCameraReference.x + Position.X;
Target.Y = transformedCameraReference.y + Position.Y;
Target.Z = transformedCameraReference.z + Position.Z;
D3DXVECTOR3 pos, tar, up;
pos.x = Position.X;
pos.y = Position.Y;
pos.z = Position.Z;
tar.x = Target.X;
tar.y = Target.Y;
tar.z = Target.Z;
up.x = 0;
up.y = 1;
up.z = 0;
D3DXMatrixLookAtLH( &View, &pos, &tar, &up );
}
};


and here is the rendering code for the meshes:
void Render( IDirect3DDevice9* g_pd3dDevice, TIP::Physics::TIPVector3 Pos, TIP::Physics::TIPVector3 Rot, float Scale )
{
// Set up world matrix
D3DXMATRIXA16 matWorld;
D3DXMATRIXA16 translation;
D3DXMATRIXA16 rotation;
D3DXMATRIXA16 scale;
D3DXMatrixRotationYawPitchRoll( &rotation, Rot.X, Rot.Y, Rot.Z );
D3DXMatrixTranslation( &translation, Pos.X, Pos.Y, Pos.Z );
D3DXMatrixScaling( &scale, Scale, Scale, Scale );
matWorld = rotation * translation * scale;
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
// Meshes are divided into subsets, one for each material. Render them in
// a loop
for( DWORD i = 0; i < NumMaterials; i++ )
{
// Set the material and texture for this subset
g_pd3dDevice->SetMaterial( &Materials[i] );
g_pd3dDevice->SetTexture( 0, Textures[i] );
// Draw the mesh subset
Mesh->DrawSubset( i );
}
}

what am i doing wrong ?

---edit---
also the window size also seams to affect the way the objects looked.
if the window width and height are the same, then the square box looks square like it is supposed to.
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

### #2iedoc  Members

Posted 01 January 2012 - 01:06 AM

I think this is your problem

float rad = D3DX_PI / 4;

try

float rad = 0.4f * D3DX_PI
Braynzar Soft - DirectX Lessons & Game Programming Resources!

### #3ryan20fun  Members

Posted 01 January 2012 - 02:15 AM

I think this is your problem

float rad = D3DX_PI / 4;

try

float rad = 0.4f * D3DX_PI

unfortunetly it does not seam to help.

---edit---
when i try to move objects, they have to have a larger amount of movement to visually move, is there a problem with the view matrix ?
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

### #4iedoc  Members

Posted 01 January 2012 - 03:42 AM

What are you setting ScreenWidth and ScreenHeight to? maybe you are setting them backwards?
Braynzar Soft - DirectX Lessons & Game Programming Resources!

### #5ryan20fun  Members

Posted 01 January 2012 - 04:20 AM

im setting it like this
RECT size;
ZeroMemory( &size, sizeof( size ) );
GetClientRect( Window.GetHandle(), &size );
camera.Initialize( size.right, size.bottom );


i also set the backbuffer width and height to that value.

i also tried using the "camera" code from the "Meshes" tutorial of the SDK and it got the exact same results( box is slightly squached verticall ).

could this be a result of using the Panda 3D exporter of 3ds Max ?
ill try using a box from Blender and see if it has the same results.
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

### #6iedoc  Members

Posted 01 January 2012 - 06:29 AM

I think i might have found your problem

matWorld = rotation * translation * scale;

since the order that you multiply matrices matter, what will happen is that first your rotate, then translate, so that's good (the reverse order will create an orbiting effect), but then you scale your object after you translate it. since the object is not centered around (0,0,0) after you translate it, it will become stretched when you scale it. the order that you do rotations and scaling together don't matter, but the order you do translations and either rotation or scale does matter. try doing this instead:

matWorld = scale * rotation * translation;
Braynzar Soft - DirectX Lessons & Game Programming Resources!

### #7ryan20fun  Members

Posted 01 January 2012 - 08:08 AM

that solved a problem of positioning my objects, but unfortunetly it does not seam to be affecting how the objects look.

can you have a look at the .X meshe to see if that is the problem( as i cannot view it in a another app for verification of the mesh ) ?

#### Attached Files

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

### #8iedoc  Members

Posted 01 January 2012 - 08:28 AM

I'm still looking for your problem, but i'll let you know your x file is fine. You can also check x files with the utility in your directx sdk called directx viewer or something
Braynzar Soft - DirectX Lessons & Game Programming Resources!

### #9iedoc  Members

Posted 01 January 2012 - 08:36 AM

When you get this problem of stretching, is it after you change your window size? or when you first start the program?

I'm starting to think this has to do with your aspect ratio, where you have width/height
Braynzar Soft - DirectX Lessons & Game Programming Resources!

### #10Brother Bob  Moderators

Posted 01 January 2012 - 08:51 AM

From initialize():

aspectRatio = ScreenWidth / ScreenHeight;



Both ScreenWidth and ScreenHeight are integers, so you're performing an integer division and the results is thus an integer. That is, your aspect ratio is wrong. Cast the numerator and/or the denominator to a floating point value to perform a floating point division.

### #11ryan20fun  Members

Posted 01 January 2012 - 10:16 AM

I'm starting to think this has to do with your aspect ratio, where you have width/height

Thank You

From initialize():

aspectRatio = ScreenWidth / ScreenHeight;



Both ScreenWidth and ScreenHeight are integers, so you're performing an integer division and the results is thus an integer. That is, your aspect ratio is wrong. Cast the numerator and/or the denominator to a floating point value to perform a floating point division.

Thank You
Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.