• Create Account

### #Actualtheo2005

Posted 20 April 2012 - 12:48 PM

I can't see my object... why?? (cannot find it)

Here's the whole code (related to transformations):

D3DXMATRIX matView;	// the view transform matrix

static float MouseSpeed = 0.0075f;

if (keystate[DIK_F1])
{
MouseSpeed += 0.0001f;
}
else if (keystate[DIK_F2])
{
if (MouseSpeed > 0.0001f)
{
MouseSpeed -= 0.0001f;
}
}
static float AngleX = 0.0f;   AngleX += mousestate.lX * MouseSpeed;
static float AngleY = 0.0f;   AngleY += mousestate.lY * MouseSpeed;

static float LookX = 0.0f;
static float LookY = 0.0f;
static float LookZ = 0.0f;

static float MoveX = 0.0f;
static float MoveY = 0.0f;
static float MoveZ = 0.0f;
if(keystate[DIK_A] & 0x80)
{
MoveX -= 0.3f;
}
if(keystate[DIK_D] & 0x80)
{
MoveX += 0.3f;
}
if(keystate[DIK_S] & 0x80)
{
MoveY -= 0.3f;
}
if(keystate[DIK_W] & 0x80)
{
MoveY += 0.3f;
}
LookX = cos(AngleX) * sin(AngleY);
LookY = sin(AngleY);
LookZ = sin(AngleX) * sin(AngleY);
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (MoveX, MoveY, MoveZ),	// the camera position
&D3DXVECTOR3 (LookX + MoveX, LookY + MoveY, LookZ + MoveZ),	// the look-at position + to go along with movement
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));	// the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView);	// set the view transform to matView
D3DXMATRIX matProjection;	 // the projection transform matrix
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),	// the horizontal field of view
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
1.0f,	// the near view-plane
1000.0f);	// the far view-plane
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);	// set the projection
// ----------------------------------------------------------- CAMERA SETUP <END> --------------------------------------------------------------------------//

// select the vertex buffer to display
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
d3ddev->SetIndices(i_buffer); //select the index buffer
D3DXMATRIX matTranslateA;	// a matrix to store the translation for triangle A
D3DXMATRIX matRotateX;	// a matrix to store the rotation for each triangle
D3DXMATRIX matRotateY;
static float indexX = 0.0f; // index+=0.03f;
static float indexY = 0.0f;
if(keystate[DIK_LEFT] & 0x80)
{
indexY += 0.03f;
}
if(keystate[DIK_RIGHT] & 0x80)
{
indexY -= 0.03f;
}
if(keystate[DIK_DOWN] & 0x80)
{
indexX += 0.03f;
}
if(keystate[DIK_UP] & 0x80)
{
indexX -= 0.03f;
}
//building matrices
D3DXMatrixTranslation(&matTranslateA, 0.0f, 0.0f, 15.0f); //15.0f away from the camera
D3DXMatrixRotationX(&matRotateX, indexX);
D3DXMatrixRotationY(&matRotateY, indexY);
// tell Direct3D about each world transform, and then draw another triangle
d3ddev->SetTransform(D3DTS_WORLD, &(matRotateX * matRotateY * matTranslateA));
d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
//single primitive: d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);


Also, even tho it was a typo, Sin actually means arcussinus or sin^-1. (asked the math teacher and only one search result on google)

### #3theo2005

Posted 20 April 2012 - 12:47 PM

Well, I used your code with normal sin's but camera doesnt move on Y at all, except if I move it a lot, the object disappears. And
the horizontal movement, it does something very fishy again. And how come the camera is not looking at the object at the start of the program???
So many mysteries I cannot solve.

Here's the whole code (related to transformations):

D3DXMATRIX matView;	// the view transform matrix

static float MouseSpeed = 0.0075f;

if (keystate[DIK_F1])
{
MouseSpeed += 0.0001f;
}
else if (keystate[DIK_F2])
{
if (MouseSpeed > 0.0001f)
{
MouseSpeed -= 0.0001f;
}
}
static float AngleX = 0.0f;   AngleX += mousestate.lX * MouseSpeed;
static float AngleY = 0.0f;   AngleY += mousestate.lY * MouseSpeed;

static float LookX = 0.0f;
static float LookY = 0.0f;
static float LookZ = 0.0f;

static float MoveX = 0.0f;
static float MoveY = 0.0f;
static float MoveZ = 0.0f;
if(keystate[DIK_A] & 0x80)
{
MoveX -= 0.3f;
}
if(keystate[DIK_D] & 0x80)
{
MoveX += 0.3f;
}
if(keystate[DIK_S] & 0x80)
{
MoveY -= 0.3f;
}
if(keystate[DIK_W] & 0x80)
{
MoveY += 0.3f;
}
LookX = cos(AngleX) * sin(AngleY);
LookY = sin(AngleY);
LookZ = sin(AngleX) * sin(AngleY);
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (MoveX, MoveY, MoveZ),	// the camera position
&D3DXVECTOR3 (LookX + MoveX, LookY + MoveY, LookZ + MoveZ),	// the look-at position + to go along with movement
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));	// the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView);	// set the view transform to matView
D3DXMATRIX matProjection;	 // the projection transform matrix
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),	// the horizontal field of view
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
1.0f,	// the near view-plane
1000.0f);	// the far view-plane
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);	// set the projection
// ----------------------------------------------------------- CAMERA SETUP <END> --------------------------------------------------------------------------//

// select the vertex buffer to display
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
d3ddev->SetIndices(i_buffer); //select the index buffer
D3DXMATRIX matTranslateA;	// a matrix to store the translation for triangle A
D3DXMATRIX matRotateX;	// a matrix to store the rotation for each triangle
D3DXMATRIX matRotateY;
static float indexX = 0.0f; // index+=0.03f;
static float indexY = 0.0f;
if(keystate[DIK_LEFT] & 0x80)
{
indexY += 0.03f;
}
if(keystate[DIK_RIGHT] & 0x80)
{
indexY -= 0.03f;
}
if(keystate[DIK_DOWN] & 0x80)
{
indexX += 0.03f;
}
if(keystate[DIK_UP] & 0x80)
{
indexX -= 0.03f;
}
//building matrices
D3DXMatrixTranslation(&matTranslateA, 0.0f, 0.0f, 15.0f); //15.0f away from the camera
D3DXMatrixRotationX(&matRotateX, indexX);
D3DXMatrixRotationY(&matRotateY, indexY);
// tell Direct3D about each world transform, and then draw another triangle
d3ddev->SetTransform(D3DTS_WORLD, &(matRotateX * matRotateY * matTranslateA));
d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
//single primitive: d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);


Also, even tho it was a typo, Sin actually means arcussinus or sin^-1. (asked the math teacher and only one search result on google)

### #2theo2005

Posted 20 April 2012 - 08:50 AM

Well, I used your code with normal sin's but camera doesnt move on Y at all, except if I move it a lot, the object disappears. And
the horizontal movement, it does something very fishy again. And how come the camera is not looking at the object at the start of the program???
So many mysteries I cannot solve.

Here's the whole code (related to transformations):

D3DXMATRIX matView;	// the view transform matrix

static float MouseSpeed = 0.0075f;

if (keystate[DIK_F1])
{
MouseSpeed += 0.0001f;
}
else if (keystate[DIK_F2])
{
if (MouseSpeed > 0.0001f)
{
MouseSpeed -= 0.0001f;
}
}
static float AngleX = 0.0f;   AngleX += mousestate.lX * MouseSpeed;
static float AngleY = 0.0f;   AngleY += mousestate.lY * MouseSpeed;

static float LookX = 0.0f;
static float LookY = 0.0f;
static float LookZ = 0.0f;

static float MoveX = 0.0f;
static float MoveY = 0.0f;
static float MoveZ = 0.0f;
if(keystate[DIK_A] & 0x80)
{
MoveX -= 0.3f;
}
if(keystate[DIK_D] & 0x80)
{
MoveX += 0.3f;
}
if(keystate[DIK_S] & 0x80)
{
MoveY -= 0.3f;
}
if(keystate[DIK_W] & 0x80)
{
MoveY += 0.3f;
}
LookX = cos(AngleX) * sin(AngleY);
LookY = sin(AngleY);
LookZ = sin(AngleX) * sin(AngleY);
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (MoveX, MoveY, MoveZ),	// the camera position
&D3DXVECTOR3 (LookX + MoveX, LookY + MoveY, LookZ + LookZ),	// the look-at position + to go along with movement
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));	// the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView);	// set the view transform to matView
D3DXMATRIX matProjection;	 // the projection transform matrix
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),	// the horizontal field of view
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
1.0f,	// the near view-plane
1000.0f);	// the far view-plane
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);	// set the projection
// ----------------------------------------------------------- CAMERA SETUP <END> --------------------------------------------------------------------------//

// select the vertex buffer to display
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
d3ddev->SetIndices(i_buffer); //select the index buffer
D3DXMATRIX matTranslateA;	// a matrix to store the translation for triangle A
D3DXMATRIX matRotateX;	// a matrix to store the rotation for each triangle
D3DXMATRIX matRotateY;
static float indexX = 0.0f; // index+=0.03f;
static float indexY = 0.0f;
if(keystate[DIK_LEFT] & 0x80)
{
indexY += 0.03f;
}
if(keystate[DIK_RIGHT] & 0x80)
{
indexY -= 0.03f;
}
if(keystate[DIK_DOWN] & 0x80)
{
indexX += 0.03f;
}
if(keystate[DIK_UP] & 0x80)
{
indexX -= 0.03f;
}
//building matrices
D3DXMatrixTranslation(&matTranslateA, 0.0f, 0.0f, 15.0f); //15.0f away from the camera
D3DXMatrixRotationX(&matRotateX, indexX);
D3DXMatrixRotationY(&matRotateY, indexY);
// tell Direct3D about each world transform, and then draw another triangle
d3ddev->SetTransform(D3DTS_WORLD, &(matRotateX * matRotateY * matTranslateA));
d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
//single primitive: d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);


Also, even tho it was a typo, Sin actually means arcussinus or sin^-1. (asked the math teacher and only one search result on google)

### #1theo2005

Posted 20 April 2012 - 08:34 AM

Well, I used your code with normal sin's but camera doesnt move on Y at all, except if I move it a lot, the object disappears. And
the horizontal movement, it does something very fishy again. And how come the camera is not looking at the object at the start of the program???
So many mysteries I cannot solve.

Here's the whole code (related to transformations):

D3DXMATRIX matView;	// the view transform matrix

static float MouseSpeed = 0.0075f;

if (keystate[DIK_F1])
{
MouseSpeed += 0.0001f;
}
else if (keystate[DIK_F2])
{
if (MouseSpeed > 0.0001f)
{
MouseSpeed -= 0.0001f;
}
}
static float AngleX = 0.0f;   AngleX += mousestate.lX * MouseSpeed;
static float AngleY = 0.0f;   AngleY += mousestate.lY * MouseSpeed;

static float LookX = 0.0f;
static float LookY = 0.0f;
static float LookZ = 0.0f;

static float MoveX = 0.0f;
static float MoveY = 0.0f;
static float MoveZ = 0.0f;
if(keystate[DIK_A] & 0x80)
{
MoveX -= 0.3f;
}
if(keystate[DIK_D] & 0x80)
{
MoveX += 0.3f;
}
if(keystate[DIK_S] & 0x80)
{
MoveY -= 0.3f;
}
if(keystate[DIK_W] & 0x80)
{
MoveY += 0.3f;
}
//in order for the camera to keep looking in the same direction
LookX = cos(AngleX) * sin(AngleY);
LookY = sin(AngleY);
LookZ = sin(AngleX) * sin(AngleY);
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (MoveX, MoveY, MoveZ),	// the camera position
&D3DXVECTOR3 (LookX + MoveX, LookY + MoveY, LookZ + LookZ),	// the look-at position + to go along with movement
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));	// the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView);	// set the view transform to matView
D3DXMATRIX matProjection;	 // the projection transform matrix
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),	// the horizontal field of view
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
1.0f,	// the near view-plane
1000.0f);	// the far view-plane
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);	// set the projection
// ----------------------------------------------------------- CAMERA SETUP <END> --------------------------------------------------------------------------//

// select the vertex buffer to display
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
d3ddev->SetIndices(i_buffer); //select the index buffer
D3DXMATRIX matTranslateA;	// a matrix to store the translation for triangle A
D3DXMATRIX matRotateX;	// a matrix to store the rotation for each triangle
D3DXMATRIX matRotateY;
static float indexX = 0.0f; // index+=0.03f;
static float indexY = 0.0f;
if(keystate[DIK_LEFT] & 0x80)
{
indexY += 0.03f;
}
if(keystate[DIK_RIGHT] & 0x80)
{
indexY -= 0.03f;
}
if(keystate[DIK_DOWN] & 0x80)
{
indexX += 0.03f;
}
if(keystate[DIK_UP] & 0x80)
{
indexX -= 0.03f;
}
//building matrices
D3DXMatrixTranslation(&matTranslateA, 0.0f, 0.0f, 15.0f); //15.0f away from the camera
D3DXMatrixRotationX(&matRotateX, indexX);
D3DXMatrixRotationY(&matRotateY, indexY);
// tell Direct3D about each world transform, and then draw another triangle
d3ddev->SetTransform(D3DTS_WORLD, &(matRotateX * matRotateY * matTranslateA));
d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
//single primitive: d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);


Also, even tho it was a typo, Sin actually means arcussinus or sin^-1. (asked the math teacher and only one search result on google)

PARTNERS