C
crappydude123
Guest
I had setup a fighting game camera
Main.cpp
void Main::Initialize(
_In_ Controller controller,
_In_ GameRenderer^ renderer)
{
// This method is expected to be called as an asynchronous task.
// Make sure that you don't call rendering methods on the
// m_renderer as this would result in the D3D Context being
// used in multiple threads, which is not allowed.
m_controller = controller;
m_renderer = renderer;
m_audioController = ref new Audio;
m_audioController->CreateDeviceIndependentResources();
m_level = std::vector<Level^>();
m_savedState = ref new PersistentState();
m_savedState->Initialize(ApplicationData::Current->LocalSettings->Values, "Game");
// Create a sphere primitive to represent the player
// The sphere is used to handle collisions and constrain the player in the world
// It's not rendered so it's not added to the list of render objects.
m_playerOne = ref new Player(XMFLOAT3(0.0f, -1.3f, 4.0f));
m_playerTwo = ref new Player(XMFLOAT3(0.0f, -1.3f, -4.0f));
m_camera = ref new Camera;
m_camera->SetProjParams(XM_PI / 2, 1.0f, 0.01f, 100.0f);
m_camera->SetViewParams(
XMFLOAT3(0.0f, 0.7f, 0.0f), // Eye point in world coordinates.
m_playerOne->Position() +
m_playerTwo->Position(), // Look at point in world coordinates.
XMFLOAT3(0.0f, 1.0f, 0.0f) // The Up vector for the camera.
);
m_arena = ref new Arena(XMFLOAT3(0.0f, 0.0f, 0.0f));
// Instantiate the world primitive. This object maintains the geometry and
// material properties of the walls, floor, and ceiling of the enclosing world.
// The TargetId is used to identify the world objects so that the right geometry
// and textures can be associated with them later after those resources have
// been created.
// Min and max Bound are defining the world space of the game.
// All camera motion and dynamics are confined to this space.
m_minBound = XMFLOAT3(-4.0f, -3.0f, -6.0f);
m_maxBound = XMFLOAT3(4.0f, 3.0f, 6.0f);
// Instantiate each of the game levels. The Level class contains methods
// that initialize the objects in the world for the given level and also
// define any motion paths for the objects in that level.
m_level.push_back(ref new Level1);
m_levelCount = static_cast<uint32>(m_level.size());
// Load the currentScore for saved state
LoadState();
m_controller->Active(false);
}
Player.h
__forceinline void Player:osition(DirectX::XMFLOAT3 position)
{
m_position = position;
Update();
}
__forceinline void Player:osition(DirectX::XMVECTOR position)
{
DirectX::XMStoreFloat3(&m_position, position);
Update();
}
__forceinline void Player::Radius(float radius)
{
m_radius = radius;
Update();
}
__forceinline float Player::Radius()
{
return m_radius;
}
Camera.cpp
#undef min // use __min instead
#undef max // use __max instead
//--------------------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------------------
Camera::Camera()
{
// Setup the view matrix.
SetViewParams(
XMFLOAT3(0.0f, 0.0f, 0.0f), // default eye position.
XMFLOAT3(0.0f, 0.0f, 1.0f), // default look at position.
XMFLOAT3(0.0f, 1.0f, 0.0f) // default up vector.
);
// Setup the projection matrix.
SetProjParams(XM_PI / 4, 1.0f, 1.0f, 1000.0f);
}
//--------------------------------------------------------------------------------------
void Camera::LookDirection(_In_ XMFLOAT3 lookDirection)
{
XMFLOAT3 lookAt;
lookAt.x = m_eye.x + lookDirection.x;
lookAt.y = m_eye.y + lookDirection.y;
lookAt.z = m_eye.z + lookDirection.z;
SetViewParams(m_eye, lookAt, m_up);
}
//--------------------------------------------------------------------------------------
void Camera::Eye(_In_ XMFLOAT3 eye)
{
SetViewParams(eye, m_lookAt, m_up);
}
//--------------------------------------------------------------------------------------
void Camera::SetViewParams(
_In_ XMFLOAT3 eye,
_In_ XMFLOAT3 lookAt,
_In_ XMFLOAT3 up
)
{
m_eye = eye;
m_lookAt = lookAt;
m_up = up;
// Calc the view matrix.
XMMATRIX view = XMMatrixLookAtLH(
XMLoadFloat3(&m_eye),
XMLoadFloat3(&m_lookAt),
XMLoadFloat3(&m_up)
);
XMVECTOR det;
XMMATRIX inverseView = XMMatrixInverse(&det, view);
XMStoreFloat4x4(&m_viewMatrix, view);
XMStoreFloat4x4(&m_inverseView, inverseView);
// The axis basis vectors and camera position are stored inside the
// position matrix in the four rows of the camera's world matrix.
// To figure out the yaw/pitch of the camera, we just need the Z basis vector
XMFLOAT3 zBasis;
XMStoreFloat3(&zBasis, inverseView.r[2]);
m_cameraYawAngle = atan2f(zBasis.x, zBasis.z);
float len = sqrtf(zBasis.z * zBasis.z + zBasis.x * zBasis.x);
m_cameraPitchAngle = atan2f(zBasis.y, len);
}
//--------------------------------------------------------------------------------------
// Calculates the projection matrix based on input params
//--------------------------------------------------------------------------------------
void Camera::SetProjParams(
_In_ float fieldOfView,
_In_ float aspectRatio,
_In_ float nearPlane,
_In_ float farPlane
)
{
// Set attributes for the projection matrix.
m_fieldOfView = fieldOfView;
m_aspectRatio = aspectRatio;
m_nearPlane = nearPlane;
m_farPlane = farPlane;
XMStoreFloat4x4(
&m_projectionMatrix,
XMMatrixPerspectiveFovLH(
m_fieldOfView,
m_aspectRatio,
m_nearPlane,
m_farPlane
)
);
}
//--------------------------------------------------------------------------------------
DirectX::XMMATRIX Camera::View()
{
return XMLoadFloat4x4(&m_viewMatrix);
}
DirectX::XMMATRIX Camera:rojection()
{
return XMLoadFloat4x4(&m_projectionMatrix);
}
DirectX::XMMATRIX Camera::LeftEyeProjection()
{
return XMLoadFloat4x4(&m_projectionMatrixLeft);
}
DirectX::XMMATRIX Camera::RightEyeProjection()
{
return XMLoadFloat4x4(&m_projectionMatrixRight);
}
DirectX::XMMATRIX Camera::World()
{
return XMLoadFloat4x4(&m_inverseView);
}
DirectX::XMFLOAT3 Camera::Eye()
{
return m_eye;
}
DirectX::XMFLOAT3 Camera::LookAt()
{
return m_lookAt;
}
float Camera::NearClipPlane()
{
return m_nearPlane;
}
float Camera::FarClipPlane()
{
return m_farPlane;
}
float Camera:itch()
{
return m_cameraPitchAngle;
}
float Camera::Yaw()
{
return m_cameraYawAngle;
}
I keep getting this error:
E0289 no instance of constructor "Player:layer" matches the argument list
E2143 ref new cannot allocate an entity of type "Camera"
E0077 this declaration has no storage class or type specifier
Continue reading...
Main.cpp
void Main::Initialize(
_In_ Controller controller,
_In_ GameRenderer^ renderer)
{
// This method is expected to be called as an asynchronous task.
// Make sure that you don't call rendering methods on the
// m_renderer as this would result in the D3D Context being
// used in multiple threads, which is not allowed.
m_controller = controller;
m_renderer = renderer;
m_audioController = ref new Audio;
m_audioController->CreateDeviceIndependentResources();
m_level = std::vector<Level^>();
m_savedState = ref new PersistentState();
m_savedState->Initialize(ApplicationData::Current->LocalSettings->Values, "Game");
// Create a sphere primitive to represent the player
// The sphere is used to handle collisions and constrain the player in the world
// It's not rendered so it's not added to the list of render objects.
m_playerOne = ref new Player(XMFLOAT3(0.0f, -1.3f, 4.0f));
m_playerTwo = ref new Player(XMFLOAT3(0.0f, -1.3f, -4.0f));
m_camera = ref new Camera;
m_camera->SetProjParams(XM_PI / 2, 1.0f, 0.01f, 100.0f);
m_camera->SetViewParams(
XMFLOAT3(0.0f, 0.7f, 0.0f), // Eye point in world coordinates.
m_playerOne->Position() +
m_playerTwo->Position(), // Look at point in world coordinates.
XMFLOAT3(0.0f, 1.0f, 0.0f) // The Up vector for the camera.
);
m_arena = ref new Arena(XMFLOAT3(0.0f, 0.0f, 0.0f));
// Instantiate the world primitive. This object maintains the geometry and
// material properties of the walls, floor, and ceiling of the enclosing world.
// The TargetId is used to identify the world objects so that the right geometry
// and textures can be associated with them later after those resources have
// been created.
// Min and max Bound are defining the world space of the game.
// All camera motion and dynamics are confined to this space.
m_minBound = XMFLOAT3(-4.0f, -3.0f, -6.0f);
m_maxBound = XMFLOAT3(4.0f, 3.0f, 6.0f);
// Instantiate each of the game levels. The Level class contains methods
// that initialize the objects in the world for the given level and also
// define any motion paths for the objects in that level.
m_level.push_back(ref new Level1);
m_levelCount = static_cast<uint32>(m_level.size());
// Load the currentScore for saved state
LoadState();
m_controller->Active(false);
}
Player.h
__forceinline void Player:osition(DirectX::XMFLOAT3 position)
{
m_position = position;
Update();
}
__forceinline void Player:osition(DirectX::XMVECTOR position)
{
DirectX::XMStoreFloat3(&m_position, position);
Update();
}
__forceinline void Player::Radius(float radius)
{
m_radius = radius;
Update();
}
__forceinline float Player::Radius()
{
return m_radius;
}
Camera.cpp
#undef min // use __min instead
#undef max // use __max instead
//--------------------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------------------
Camera::Camera()
{
// Setup the view matrix.
SetViewParams(
XMFLOAT3(0.0f, 0.0f, 0.0f), // default eye position.
XMFLOAT3(0.0f, 0.0f, 1.0f), // default look at position.
XMFLOAT3(0.0f, 1.0f, 0.0f) // default up vector.
);
// Setup the projection matrix.
SetProjParams(XM_PI / 4, 1.0f, 1.0f, 1000.0f);
}
//--------------------------------------------------------------------------------------
void Camera::LookDirection(_In_ XMFLOAT3 lookDirection)
{
XMFLOAT3 lookAt;
lookAt.x = m_eye.x + lookDirection.x;
lookAt.y = m_eye.y + lookDirection.y;
lookAt.z = m_eye.z + lookDirection.z;
SetViewParams(m_eye, lookAt, m_up);
}
//--------------------------------------------------------------------------------------
void Camera::Eye(_In_ XMFLOAT3 eye)
{
SetViewParams(eye, m_lookAt, m_up);
}
//--------------------------------------------------------------------------------------
void Camera::SetViewParams(
_In_ XMFLOAT3 eye,
_In_ XMFLOAT3 lookAt,
_In_ XMFLOAT3 up
)
{
m_eye = eye;
m_lookAt = lookAt;
m_up = up;
// Calc the view matrix.
XMMATRIX view = XMMatrixLookAtLH(
XMLoadFloat3(&m_eye),
XMLoadFloat3(&m_lookAt),
XMLoadFloat3(&m_up)
);
XMVECTOR det;
XMMATRIX inverseView = XMMatrixInverse(&det, view);
XMStoreFloat4x4(&m_viewMatrix, view);
XMStoreFloat4x4(&m_inverseView, inverseView);
// The axis basis vectors and camera position are stored inside the
// position matrix in the four rows of the camera's world matrix.
// To figure out the yaw/pitch of the camera, we just need the Z basis vector
XMFLOAT3 zBasis;
XMStoreFloat3(&zBasis, inverseView.r[2]);
m_cameraYawAngle = atan2f(zBasis.x, zBasis.z);
float len = sqrtf(zBasis.z * zBasis.z + zBasis.x * zBasis.x);
m_cameraPitchAngle = atan2f(zBasis.y, len);
}
//--------------------------------------------------------------------------------------
// Calculates the projection matrix based on input params
//--------------------------------------------------------------------------------------
void Camera::SetProjParams(
_In_ float fieldOfView,
_In_ float aspectRatio,
_In_ float nearPlane,
_In_ float farPlane
)
{
// Set attributes for the projection matrix.
m_fieldOfView = fieldOfView;
m_aspectRatio = aspectRatio;
m_nearPlane = nearPlane;
m_farPlane = farPlane;
XMStoreFloat4x4(
&m_projectionMatrix,
XMMatrixPerspectiveFovLH(
m_fieldOfView,
m_aspectRatio,
m_nearPlane,
m_farPlane
)
);
}
//--------------------------------------------------------------------------------------
DirectX::XMMATRIX Camera::View()
{
return XMLoadFloat4x4(&m_viewMatrix);
}
DirectX::XMMATRIX Camera:rojection()
{
return XMLoadFloat4x4(&m_projectionMatrix);
}
DirectX::XMMATRIX Camera::LeftEyeProjection()
{
return XMLoadFloat4x4(&m_projectionMatrixLeft);
}
DirectX::XMMATRIX Camera::RightEyeProjection()
{
return XMLoadFloat4x4(&m_projectionMatrixRight);
}
DirectX::XMMATRIX Camera::World()
{
return XMLoadFloat4x4(&m_inverseView);
}
DirectX::XMFLOAT3 Camera::Eye()
{
return m_eye;
}
DirectX::XMFLOAT3 Camera::LookAt()
{
return m_lookAt;
}
float Camera::NearClipPlane()
{
return m_nearPlane;
}
float Camera::FarClipPlane()
{
return m_farPlane;
}
float Camera:itch()
{
return m_cameraPitchAngle;
}
float Camera::Yaw()
{
return m_cameraYawAngle;
}
I keep getting this error:
E0289 no instance of constructor "Player:layer" matches the argument list
E2143 ref new cannot allocate an entity of type "Camera"
E0077 this declaration has no storage class or type specifier
Continue reading...