• Advertisement
Sign in to follow this  

Meshes look squished

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

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:
[attachment=6574:squished.jpg]

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
#define DEG_TO_RAD 0.0174532925
float RadianToDegree( float Radien )
{
return Radien * ( 180 / PIE );
}
float DegreeToRadian( float Degree )
{
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;
float rad = D3DX_PI / 4;//DegreeToRadian( fieldOfView );
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 ) )
Pitch = DegreeToRadian( -89.9f );
else if( Pitch > DegreeToRadian( 89.9f ) )
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 );
g_pd3dDevice->SetTexture( 0, Textures );
// Draw the mesh subset
Mesh->DrawSubset( i );
}
}

what am i doing wrong ?
Thanks In Advance.

---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.

Share this post


Link to post
Share on other sites
Advertisement
I think this is your problem

[color=#000088]float[color=#000000] rad [color=#666600]=[color=#000000] D3DX_PI [color=#666600]/[color=#000000] [color=#006666]4[color=#666600];

try

[color=#000088]float rad = 0.4f * D3DX_PI

Share this post


Link to post
Share on other sites

I think this is your problem

[color=#000088]float[color=#000000] rad [color=#666600]=[color=#000000] D3DX_PI [color=#666600]/[color=#000000] [color=#006666]4[color=#666600];

try

[color=#000088]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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I think i might have found your problem


[color=#000000] matWorld [color=#666600]=[color=#000000] rotation [color=#666600]*[color=#000000] translation [color=#666600]*[color=#000000] scale[color=#666600];

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:


[color=#000000] matWorld [color=#666600]= scale *[color=#000000] rotation [color=#666600]*[color=#000000] translation[color=#666600];

Share this post


Link to post
Share on other sites
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 ) ?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
From initialize():
[source]
aspectRatio = ScreenWidth / ScreenHeight;

[/source]

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.

Share this post


Link to post
Share on other sites

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

Thank You smile.png smile.png smile.png


From initialize():
[source]
aspectRatio = ScreenWidth / ScreenHeight;

[/source]

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 smile.png smile.png smile.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement