• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
snoddas14

FPS camera.

2 posts in this topic

hey. i got this issue that i dont understand, and its the camera lookat. i want to use my mouse to look around and move whit W,A,S,D but i cant get it together. plz help me.
0

Share this post


Link to post
Share on other sites
The camera lookat vector is the vector that specifies the point in the world where you want to aim the camera.

Here's the code for the second one:

D3DCamera.h:

#ifndef D3DCAMERA_H
#define D3DCAMERA_H

// CD3DCamera class
class CD3DCamera {
public:
CD3DCamera(); // Constructor

void resetCamera(); // Reset the camera
void rotateCamera(); // Rotate the camera
void walk(float fUnits); // Camera fo walking
void strafe(float fUnits); // Camera for strafing
void fly(float fUnits); // Camera for flying
void yaw(float fAngle); // Camera for yawing
void roll(float fAngle); // Camera for rolling
void pitch(float fAngle); // Camera for pitching
void zoom(float fUnits); // For zooming and out
D3DXMATRIX *getViewMatrix(D3DXMATRIX *pmatView); // Get view transformation matrix

// ECameraType enumeration
enum ECameraType {
Land, // Camera is on the land
Air, // Camera is on the air
};

private:
POINT m_point; // Screen coordinates

D3DXMATRIXA16 m_matView; // View transformation matrix

float m_fX, m_fY, m_fZ; // View positions

D3DXVECTOR3 m_vecPosition, m_vecUp, m_vecRight, m_vecLookAt; // 3D vectors

BOOL m_bCameraPosChanged; // This will notify us if the camera's position has changed since last update

ECameraType m_cameraType; // This will hold camera type
};

extern CD3DCamera *g_pD3DCamera; // Externed class pointer

#endif // D3DCAMERA_H

D3DCamera.cpp:

//------------------------------------------------------------------
// Name: CD3DCamera
// Desc: CD3DCamera constructor
//------------------------------------------------------------------
CD3DCamera::CD3DCamera()
{
m_vecPosition = D3DXVECTOR3(0.0f, 0.0f, -5.0f); // Position vector
m_vecLookAt = D3DXVECTOR3(0.0f, 0.0f, 1.0f); // Look vector
m_vecUp = D3DXVECTOR3(0.0f, 1.0f, 0.0f); // Up vector
m_vecRight = D3DXVECTOR3(1.0f, 0.0f, 0.0f); // Right vector

m_cameraType = Land; // Set camera type to land
}

//------------------------------------------------------------------
// Name: resetCamera
// Desc: Reset the camera
//------------------------------------------------------------------
void CD3DCamera::resetCamera()
{
m_vecPosition = D3DXVECTOR3(0.0f, 0.0f, -250.0f);
m_vecLookAt = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
m_vecUp = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
::D3DXMatrixLookAtLH(&m_matView, &m_vecPosition, &m_vecLookAt, &m_vecUp);
g_pD3DGraphics->setViewTransform(&m_matView);
}

//------------------------------------------------------------------
// Name: rotateCamera
// Desc: Rotate the camera to an arbitrary axis
//------------------------------------------------------------------
void CD3DCamera::rotateCamera()
{
}

//------------------------------------------------------------------
// Name: walk
// Desc: Camera for walking
//------------------------------------------------------------------
void CD3DCamera::walk(float fUnits)
{
// Walk only on the XZ plane when the camera is on the land
if(m_cameraType == Land)
m_vecPosition += ::D3DXVECTOR3(m_vecLookAt.x, 0.0f, m_vecLookAt.z) * fUnits;
else
m_vecPosition += m_vecLookAt * fUnits;
}

//------------------------------------------------------------------
// Name: strafe
// Desc: Camera for strafing
//------------------------------------------------------------------
void CD3DCamera::strafe(float fUnits)
{
// Move only on the XZ plane when the camera is on the land
if(m_cameraType == Land)
m_vecPosition += ::D3DXVECTOR3(m_vecRight.x, 0.0f, m_vecRight.z) * fUnits;
else
m_vecPosition += m_vecRight * fUnits;
}

//------------------------------------------------------------------
// Name: fly
// Desc: Camera for flying
//------------------------------------------------------------------
void CD3DCamera::fly(float fUnits)
{
// Move only on y-axis when the camera is on the land
if(m_cameraType == Land)
m_vecPosition.y += fUnits;
else
m_vecPosition += m_vecUp * fUnits;
}

//------------------------------------------------------------------
// Name: yaw
// Desc: Camera for yawing
//------------------------------------------------------------------
void CD3DCamera::yaw(float fAngle)
{
// If the camera is on land
if(m_cameraType == Land)
::D3DXMatrixRotationY(&m_matView, fAngle); // Rotate around the y-axis

// The camera is on th air
else
::D3DXMatrixRotationAxis(&m_matView, &m_vecUp, fAngle); // Rotate the up vector

// Rotate right and look vectors around y-axis
::D3DXVec3TransformCoord(&m_vecRight, &m_vecRight, &m_matView);
::D3DXVec3TransformCoord(&m_vecLookAt, &m_vecLookAt, &m_matView);
}

//------------------------------------------------------------------
// Name: roll
// Desc: Camera for rolling
//------------------------------------------------------------------
void CD3DCamera::roll(float fAngle)
{
// Check to see if the camera is on the air
if(m_cameraType == Air) {

// Rotate the look-at vector by the specified amount
::D3DXMatrixRotationAxis(&m_matView, &m_vecLookAt, fAngle);

// Rotate up and right vectors around look vector
::D3DXVec3TransformCoord(&m_vecUp, &m_vecUp, &m_matView);
::D3DXVec3TransformCoord(&m_vecRight, &m_vecRight, &m_matView);
}
}

//------------------------------------------------------------------
// Name: pitch
// Desc: Camera for pitching
//------------------------------------------------------------------
void CD3DCamera::pitch(float fAngle)
{
// Rotate around the x-axis
::D3DXMatrixRotationAxis(&m_matView, &m_vecRight, fAngle);

// Rotate up and look vectors around the right vector
::D3DXVec3TransformCoord(&m_vecUp, &m_vecUp, &m_matView);
::D3DXVec3TransformCoord(&m_vecLookAt, &m_vecLookAt, &m_matView);
}

//------------------------------------------------------------------
// Name: zoom
// Desc: For zooming in and out
//------------------------------------------------------------------
void CD3DCamera::zoom(float fUnits)
{
m_vecPosition.z = fUnits;
}

//------------------------------------------------------------------
// Name: getViewMatrix
// Desc: Get the view transformation matrix
//------------------------------------------------------------------
D3DXMATRIX *CD3DCamera::getViewMatrix(D3DXMATRIX *pmatView)
{
// Normalize the look-at vector
::D3DXVec3Normalize(&m_vecLookAt, &m_vecLookAt);

// Keep up vector orthogonal to the look and right vectors
::D3DXVec3Cross(&m_vecUp, &m_vecLookAt, &m_vecRight);

// Normalize the up vector
::D3DXVec3Normalize(&m_vecUp, &m_vecUp);

// Keep right vector orthogonal to right and up vectors
::D3DXVec3Cross(&m_vecRight, &m_vecUp, &m_vecLookAt);

// Normalize the right vector
::D3DXVec3Normalize(&m_vecRight, &m_vecRight);

// Build the view matrix
m_fX = -::D3DXVec3Dot(&m_vecRight, &m_vecPosition); // X-coordinate
m_fY = -::D3DXVec3Dot(&m_vecUp, &m_vecPosition); // Y-coordinate
m_fZ = -::D3DXVec3Dot(&m_vecLookAt, &m_vecPosition); // Z-coordinate

// Modify the values of view transformation matrix
(*pmatView)(0, 0) = m_vecRight.x; (*pmatView)(0, 1) = m_vecUp.x; (*pmatView)(0, 2) = m_vecLookAt.x; (*pmatView)(0, 3) = 0.0f;
(*pmatView)(1, 0) = m_vecRight.y; (*pmatView)(1, 1) = m_vecUp.y; (*pmatView)(1, 2) = m_vecLookAt.y; (*pmatView)(1, 3) = 0.0f;
(*pmatView)(2, 0) = m_vecRight.z; (*pmatView)(2, 1) = m_vecUp.z; (*pmatView)(2, 2) = m_vecLookAt.z; (*pmatView)(2, 3) = 0.0f;
(*pmatView)(3, 0) = m_fX; (*pmatView)(3, 1) = m_fY; (*pmatView)(3, 2) = m_fZ; (*pmatView)(3, 3) = 1.0f;

return pmatView;
}

I would recommend this book: "Introduction to 3D game programming with DirectX 9.0c a shader approach" by Frank Luna. That's the best book out there!! Here you can download that's book's source code: http://www.wordware.com/files/dx9c/ Good luck
0

Share this post


Link to post
Share on other sites
Define "look around and move". What should each key do? You can't get full lookat and movement with just 4 keys (in a easy way). What do you have at the moment? In what way does it not work?
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0