• 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
jozsef.horvath

CameraProblems

4 posts in this topic

Greetings,

So right one problem after another. After successfully been able to update the contents of the cBuffer, I found that my simple Camera does not work correctly.
[source lang="cpp"]#pragma once

#include <Windows.h>
#include <xnamath.h>

class CameraManager
{
XMFLOAT3 m_Position;
XMFLOAT3 m_Rotation;
XMFLOAT4X4 m_ViewMatrix;
public:
CameraManager(void);
virtual ~CameraManager(void);

void SetPosition(float, float, float);
void SetRotation(float, float, float);

XMVECTOR GetPosition(void) const;
XMVECTOR GetRotation(void) const;
XMMATRIX GetViewMatrix(void) const;

void BuildViewMatrix(void);
};[/source]

I'm using this simple class to render the scene from camera perspective but well this isn't going well... The BuildViewMatrix function looks like this:
[source lang="cpp"]void CameraManager::BuildViewMatrix(void)
{
// *******************
// World Up Direction.
// *******************
XMFLOAT3 Up(0.0f, 1.0f, 0.0f);

// ************************
// The Observer's position.
// ************************
XMFLOAT3 Eye(m_Position);

// *************************
// The LookAt (Focus) point.
// *************************
XMFLOAT3 LookAt(0.0f, 0.0f, 1.0f);

// ************************
// Set the Camera Rotation.
// ************************
XMFLOAT3 Rotation_VEC(m_Rotation);
float Pitch = Rotation_VEC.x * 0.0174532925f;
float Yaw = Rotation_VEC.y * 0.0174532925f;
float Roll = Rotation_VEC.z * 0.0174532925f;

// ****************************************
// Build Rotation matrix upon the rotation.
// ****************************************
XMMATRIX Rotation = XMMatrixIdentity();
Rotation = XMMatrixRotationRollPitchYaw(Pitch, Yaw, Roll);

XMVECTOR Look = XMVector3TransformCoord(XMLoadFloat3(&LookAt), Rotation);
XMVECTOR Up_D = XMVector3TransformCoord(XMLoadFloat3(&Up), Rotation);

Look = XMLoadFloat3(&Eye) + Look;
XMStoreFloat4x4(&m_ViewMatrix, XMMatrixLookAtLH(XMLoadFloat3(&Eye), Look, Up_D));
}[/source]

And well my problem is simple. Whenever I set the CameraPosition on other than the Depth(Z) axis, the scene gets demorfed. Like basically:
m_Camera->SetPosition(3.0f, 2.0f, -5.0f);
m_Camera->BuildViewMatrix();

m_ViewMatrix = m_Camera->GetViewMatrix();
// Update the cb.
...
// HLSL:
output.Position = mul(mul(mul(float4(input.Position, 1.0f), WorldMatrix),ViewMatrix), ProjectionMatrix);

The camera seems like is nowhere near the -15.0f coordinate. The Triangle goes out of the screen like -I'm close to it. The screen talks for screenshot talks for itself. Honestly I think I've done everything correctly when building the camera's ViewMatrix but I may be nissing something.
0

Share this post


Link to post
Share on other sites
Making a view matrix is simple: it's just the inverse of a matrix representing the camera's orientation and position. If you're already going through the trouble of creating a rotation matrix for the camera then there's no point in using that to transform lookAt or Up directions. Just do this:[list=1]
[*]Create the rotation matrix from your yaw/pitch/roll values
[*]Set the camera's XYZ position to the first 3 components of the 4th row of the matrix:
[code]
Rotation.r[3] = XMVectorSet(m_Position.x, m_Position.y, m_Position.z, 1.0f);
[/code]
Alternatively, you can create a translation matrix with translation == m_Position and then transform your rotation matrix by that
[*]Invert the matrix to get your view matrix
[/list]

Also you need to be careful about row-major vs. column-major layout of matrices in a constant buffer. XNAMath will create row-major matrices, but by default shaders will expect column-major matrices in constant buffers. This means that you either need to transpose your matrices when setting them into your constant buffer, or you need to compile your shader with the D3D10_SHADER_PACK_MATRIX_ROW_MAJOR flag. Or, you can declare your matrices with the "row_major" modifier in your HLSL constant buffer definition. Edited by MJP
1

Share this post


Link to post
Share on other sites
Another thing to note. The above camera is transformed with respect to the world coordinate system. It will work great for a 1st person shooter, or 3rd person camera like you would see in an MMO.

If you want to create a fly-by camera, like one which would be in a flight simulator, you will have to transform the camera with respect to its own coordinate system. For that, I recommend a quaternion-based solution.
0

Share this post


Link to post
Share on other sites
thanks a lot. you helped me implement my view matrix creation a lot more efficient. My problem however was the missing of projection matrix. So the Correct Projection matrix would be:

[source lang="cpp"]XMStoreFloat4x4(&m_ProjectionMatrix, XMMatrixTranspose(XMMatrixPerspectiveFovLH(XM_PIDIV2,
static_cast<float>(ClientWidth) / static_cast<float>(ClientHeight),
0.01f,
100.0f)));

//instead of:
XMStoreFloat4x4(&m_ProjectionMatrix, XMMatrixIdentity());[/source]

I should just get some sleep maybe because I'm going nuts of silly things that I don't notice...

@[url="http://www.gamedev.net/user/196305-hornsj3/"][color="#284b72"]Hornsj3[/color][/url]:
Thanks for your recommendation. I'm aware of these, and actually CameraClass will serve as an abstract Camera for the other specific cameras I'm going to implement in the near future. Actually the next would be the Quaternion based camera for a free-look system controlled with mouse from the inherited:

[source lang="cpp"]void MouseDown(WPARAM, int, int) = 0;
void MouseUp(WPARAM, int. int) = 0;
void MouseMove(WPARAM, int, int) = 0;[/source]
functions. I'm not sure if this is the best way to go but for the first look it seems promising. Edited by Wrath87
0

Share this post


Link to post
Share on other sites
Another way to do that would be to use policy classes (see Andrei Alexandrescu's book modern C++ design [url="http://www.amazon.com/Modern-Design-Generic-Programming-Patterns/dp/0201704315/ref=sr_1_1?ie=UTF8&qid=1341087580&sr=8-1&keywords=modern+c%2B%2B+design"]http://www.amazon.co...dern c++ design[/url])


In that way you could create a transformation policy to handle the specifics, so you don't have to deal with run-time polymorphism or inheritance hierarchies at all.

Just an idea. In fact now that I mention it I think I'm going to take a stab at it. Edited by Hornsj3
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