• Create Account

### #Actualtheo2005

Posted 19 April 2012 - 10:23 AM

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 horizontal_angle = 0.0f; horizontal_angle += mousestate.lX * MouseSpeed;
static float vertical_angle = 0.0f;   vertical_angle += mousestate.lY * MouseSpeed;

static float LookX = 0.0f;			LookX = (sin(horizontal_angle) * 20.0f);
static float LookY = 0.0f;			LookY = (cos(vertical_angle) * 20.0f) - 20.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 += MoveX;
LookY += MoveY;
LookZ = MoveZ + (cos(horizontal_angle) * 20.0f); //this one has something to do with turning around 360*
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (MoveX, MoveY, MoveZ),	// the camera position
&D3DXVECTOR3 (LookX, LookY, LookZ),	// the look-at position
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));	// the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView);	// set the view transform to matView


So there it is, I did not believe it, but the horizontal movement works now.

I also tried to get vertical movement to work INSTEAD, and it did work, but after moving away from the object,
I noticed that what it did was move like around the orbit...

In any case, how to get vertical movement to work as well?

I still don't understand what the Z coordinates do in terms of the camera.
At first I thought that it's like zoom in or zoom out, but that's not it.
X and Y points at where the camera should look, but Z never seemed to do anything,
except in terms of moving in and out.

Oh and..
LookY = (cos(vertical_angle) * 20.0f) - 20.0f;


For some reason, the camera looked down in terms of the object, so I had to substract 20.0f for it to look perfectly at the object. Why is that?
The object is positioned at:

D3DXMatrixTranslation(&matTranslateA, 0.0f, 0.0f, 15.0f); //15.0f away from the camera


### #1theo2005

Posted 19 April 2012 - 10:20 AM

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 horizontal_angle = 0.0f; horizontal_angle += mousestate.lX * MouseSpeed;
static float vertical_angle = 0.0f;   vertical_angle += mousestate.lY * MouseSpeed;

static float LookX = 0.0f;		    LookX = (sin(horizontal_angle) * 20.0f);
static float LookY = 0.0f;		    LookY = (cos(vertical_angle) * 20.0f) - 20.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 += MoveX;
LookY += MoveY;
LookZ = MoveZ + (cos(horizontal_angle) * 20.0f); //this one has something to do with turning around 360*
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (MoveX, MoveY, MoveZ),    // the camera position
&D3DXVECTOR3 (LookX, LookY, LookZ),    // the look-at position
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView


So there it is, I did not believe it, but the horizontal movement works now.

I also tried to get vertical movement to work INSTEAD, and it did work, but after moving away from the object,
I noticed that what it did was move like around the orbit...

In any case, how to get vertical movement to work as well?

I still don't understand what the Z coordinates do in terms of the camera.
At first I thought that it's like zoom in or zoom out, but that's not it.
X and Y points at where the camera should look, but Z never seemed to do anything,
except in terms of moving in and out.

PARTNERS