Made controls more flight sim like

This commit is contained in:
2006-07-19 00:14:21 -04:00
parent fdc4f9e0ce
commit 41ca59b63c
11 changed files with 128 additions and 193 deletions

View File

@@ -50,25 +50,27 @@ namespace OpenArena
{ {
Camera::Camera() Camera::Camera()
{ {
m_vPosition = Vec3f(0,0,0); _position = Vec3f(0,0,0);
m_vView = Vec3f(0,0,-1); _heading = Vec3f(0,0,-1);
m_vUpVector = Vec3f(0,1,0); _up = Vec3f(0,1,0);
} }
void Camera::PositionCamera(double xpos, double ypos, double zpos, void Camera::PositionCamera(double xpos, double ypos, double zpos,
double xview, double yview, double zview, double xview, double yview, double zview,
double xup, double yup, double zup) double xup, double yup, double zup)
{ {
m_vPosition = Vec3f(xpos, ypos, zpos); _position = Vec3f(xpos, ypos, zpos);
m_vView = Vec3f(xview, yview, zview); _heading = Vec3f(xview-xpos, yview-ypos, zview-zpos);
m_vUpVector = Vec3f(xup, yup, zup); _up = Vec3f(xup, yup, zup).normalized();
UpdateVectors();
} }
void Camera::PositionCamera(Vec3f pos, Vec3f view, Vec3f up) void Camera::PositionCamera(Vec3f pos, Vec3f view, Vec3f up)
{ {
m_vPosition = pos; _position = pos;
m_vView = view; _heading = view-pos;
m_vUpVector = up; _up = up;
UpdateVectors();
} }
void Camera::SetViewByMouse(Window window) void Camera::SetViewByMouse(Window window)
@@ -130,7 +132,7 @@ namespace OpenArena
} }
else else
{ {
Vec3d axis = (m_vView - m_vPosition).cross(m_vUpVector); Vec3d axis = (_heading).cross(_up);
axis.normalize(); axis.normalize();
RotateView(angleZ, axis.x, axis.y, axis.z); RotateView(angleZ, axis.x, axis.y, axis.z);
RotateView((middle.x-pos.x)/1000.0, 0, 1, 0); RotateView((middle.x-pos.x)/1000.0, 0, 1, 0);
@@ -175,12 +177,8 @@ namespace OpenArena
void Camera::MoveCamera(double speed) void Camera::MoveCamera(double speed)
{ {
Vec3f heading = (m_vView - m_vPosition).normalized(); _position = _position + _heading * speed;
UpdateVectors();
m_vPosition.x += heading.x * speed;
m_vPosition.z += heading.z * speed;
m_vView.x += heading.x * speed;
m_vView.z += heading.z * speed;
} }
void Camera::RotateView(double angle, Vec3d axis) void Camera::RotateView(double angle, Vec3d axis)
@@ -192,73 +190,64 @@ namespace OpenArena
void Camera::RotateView(double angle, double x, double y, double z) void Camera::RotateView(double angle, double x, double y, double z)
{ {
Vec3f nView;
Vec3f cView;
cView = m_vView - m_vPosition;
double cosTheta = cos(angle); double cosTheta = cos(angle);
double sinTheta = sin(angle); double sinTheta = sin(angle);
nView.x = (cosTheta + (1 - cosTheta) * x * x) * cView.x +
((1 - cosTheta) * x * y - z * sinTheta) * cView.y +
((1 - cosTheta) * x * z + y * sinTheta) * cView.z;
nView.y = (cosTheta + (1 - cosTheta) * y * y) * cView.y +
((1- cosTheta) * x * y + z * sinTheta) * cView.x +
((1 - cosTheta) * y * z - x * sinTheta) * cView.z;
nView.z = (cosTheta + (1 - cosTheta) * z * z) * cView.z+
((1 - cosTheta) * x * z - y * sinTheta) * cView.x +
((1 - cosTheta) * y * z + x * sinTheta) * cView.y;
m_vView.x = m_vPosition.x + nView.x; double newX = (cosTheta + (1 - cosTheta) * x * x) * _heading.x +
m_vView.y = m_vPosition.y + nView.y; ((1 - cosTheta) * x * y - z * sinTheta) * _heading.y +
m_vView.z = m_vPosition.z + nView.z; ((1 - cosTheta) * x * z + y * sinTheta) * _heading.z;
double newY = (cosTheta + (1 - cosTheta) * y * y) * _heading.y +
((1 - cosTheta) * x * y + z * sinTheta) * _heading.x +
((1 - cosTheta) * y * z - x * sinTheta) * _heading.z;
double newZ = (cosTheta + (1 - cosTheta) * z * z) * _heading.z +
((1 - cosTheta) * x * z - y * sinTheta) * _heading.x +
((1 - cosTheta) * y * z + x * sinTheta) * _heading.y;
_heading.x = newX;
_heading.y = newY;
_heading.z = newZ;
} }
void Camera::StrafeCamera(double speed) void Camera::StrafeCamera(double speed)
{ {
m_vPosition.x += m_vStrafe.x * speed; _position = _position + _strafe * speed;
m_vPosition.z += m_vStrafe.z * speed;
m_vView.x += m_vStrafe.x * speed;
m_vView.z += m_vStrafe.z * speed;
} }
void Camera::Update() void Camera::Update()
{ {
m_vStrafe =((m_vView - m_vPosition).cross(m_vUpVector)).normalized(); _strafe = ((_heading).cross(_up)).normalized();
//SetViewByMouse(); //TODO take this whole function out asap
} }
void Camera::Look() void Camera::Look()
{ {
gluLookAt(m_vPosition.x, m_vPosition.y, m_vPosition.z, Vec3f view = _position + _heading;
m_vView.x, m_vView.y, m_vView.z, gluLookAt(_position.x, _position.y, _position.z,
m_vUpVector.x, m_vUpVector.y, m_vUpVector.z); view.x, view.y, view.z,
_up.x, _up.y, _up.z);
} }
Vec3f Camera::Position() Vec3f Camera::Position()
{ {
return m_vPosition; return _position;
} }
Vec3f Camera::Strafe() Vec3f Camera::Strafe()
{ {
return m_vStrafe; return _strafe;
} }
Vec3f Camera::UpVector() Vec3f Camera::UpVector()
{ {
return m_vUpVector; return _up;
} }
Vec3f Camera::View() Vec3f Camera::View()
{ {
return m_vView; return _heading + _position;
} }
void Camera::RotateHorizontal(float angle) void Camera::RotateHorizontal(float angle)
@@ -273,16 +262,20 @@ namespace OpenArena
Vec3f Camera::GetUpVector() Vec3f Camera::GetUpVector()
{ {
return _up;
} }
Vec3f Camera::GetRightVector() Vec3f Camera::GetRightVector()
{ {
return _strafe;
} }
Vec3f Camera::GetForwardVector() Vec3f Camera::GetForwardVector()
{
return _heading;
}
void Camera::UpdateVectors()
{ {
} }
}; };

View File

@@ -167,7 +167,7 @@ namespace OpenArena
* *
* \see * \see
*/ */
void Camera::RotateView(double angle, Vec3d axis); void RotateView(double angle, Vec3d axis);
/*! /*!
* \brief * \brief
@@ -318,49 +318,43 @@ namespace OpenArena
/*! /*!
* \brief * \brief
* Write brief comment for GetRightVector here. * Returns a unit vector pointing to the immediate right of the current view.
*
* *
* \returns * \returns
* Write description of return value here. * A unit vector pointing to the immediate right of the current view.
* *
* \throws <exception class> * Returns a unit vector pointing to the immediate right of the current view.
* Description of criteria for throwing this exception. * This is the direction of a positive strafe movement.
*
* Write detailed description for GetRightVector here.
* *
* \remarks * \remarks
* Write remarks for GetRightVector here.
* *
* \see * \see
* Separate items with the '|' character.
*/ */
Vec3f GetRightVector(); Vec3f GetRightVector();
/*! /*!
* \brief * \brief
* Write brief comment for GetForwardVector here. * Returns a unit vector pointing directly into the current view.
* *
* \returns * \returns
* Write description of return value here. * A unit vector pointing directly into the current view.
* *
* \throws <exception class> * Returns a unit vector pointing directly into the current view. This is the direction of positive movement.
* Description of criteria for throwing this exception.
*
* Write detailed description for GetForwardVector here.
* *
* \remarks * \remarks
* Write remarks for GetForwardVector here.
* *
* \see * \see
* Separate items with the '|' character.
*/ */
Vec3f GetForwardVector(); Vec3f GetForwardVector();
void UpdateVectors();
private: private:
Vec3f m_vPosition; Vec3f _heading;
Vec3f m_vView; Vec3f _position;
Vec3f m_vUpVector; Vec3f _up;
Vec3f m_vStrafe; Vec3f _strafe;
}; };
}; };

View File

@@ -1,5 +1,4 @@
#include "keys.h" #include "keys.h"
#include "physics.h"
#include "datatypes.h" #include "datatypes.h"
#include "list.h" #include "list.h"

View File

@@ -1,58 +0,0 @@
//Yank/rename this class
#ifndef __entity_h__
#define __entity_h__
#include "datatypes.h"
enum EntityType{ //Begin entity declaration
ENTITY_NONE=0, //Nonexistant entity this should never be used.
ENTITY_PLAYER_MULTI_START //Player start position for multiplayer.
}; //End entity declaration
/*!
* \brief
* Write brief comment for ENTITY here.
*
* Write detailed description for ENTITY here.
*
* \remarks
* Write remarks for ENTITY here.
*
* \see
* Separate items with the '|' character.
*/
class ENTITY
{
public:
/*!
* \brief
* Write brief comment for ENTITY here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ENTITY here.
*
* \remarks
* Write remarks for ENTITY here.
*
* \see
* Separate items with the '|' character.
*/
ENTITY()
{
type = ENTITY_NONE;
vPosition = Vec3f(0,0,0);
vHeading = Vec3f(0,0,0);
vUp = Vec3f(0,0,0);
health = 0;
}
uint32 type;
Vec3f vPosition;
Vec3f vHeading;
Vec3f vUp;
uint16 health;
};
#endif

View File

@@ -29,7 +29,6 @@
#endif #endif
#include "vector.h" #include "vector.h"
#include "camera.h" #include "camera.h"
#include "entities.h"
#include "geometry.h" #include "geometry.h"
#include "myglFont.h" #include "myglFont.h"
#include "myglTexture.h" #include "myglTexture.h"
@@ -455,7 +454,7 @@ namespace OpenArena
Triangle* triangles; Triangle* triangles;
uint32 numTriangles; uint32 numTriangles;
list<Player> players; list<Player> players;
list<ENTITY> ents; // list<ENTITY> ents;
list<Texture*> textures; list<Texture*> textures;
Texture menuTextures[NUM_MENU_TEXTURES]; Texture menuTextures[NUM_MENU_TEXTURES];
Window* _window; Window* _window;

View File

@@ -222,8 +222,21 @@ int main(int argc, char** argv)
{ {
if(level.mlook) if(level.mlook)
{ {
//get the mouse delta and rotate the camera accordingly using OpenArena::Vec2i;
level.defaultPlayer[0].camera.SetViewByMouse(g_Screen); Vec2i middleOfScreen = Vec2i(g_Screen.GetWidth()/2, g_Screen.GetHeight()/2);
Vec2i mousePosition = g_Screen.GetMousePosition();
if(mousePosition != middleOfScreen)
{
//Vec2i mouseDelta = mousePosition - middleOfScreen;
Vec2i mouseDelta = middleOfScreen - mousePosition;
g_Screen.SetMousePosition(middleOfScreen);
const float MOUSE_SENSITIVITY_HORIZONTAL = 0.005;
const float MOUSE_SENSITIVITY_VERTICAL = 0.005;
float horizontalAngle = mouseDelta.x * MOUSE_SENSITIVITY_HORIZONTAL;
float verticalAngle = mouseDelta.y * MOUSE_SENSITIVITY_VERTICAL;
level.defaultPlayer[0].camera.RotateHorizontal(horizontalAngle);
level.defaultPlayer[0].camera.RotateVertical(verticalAngle);
}
} }
else else
{ {

View File

@@ -223,7 +223,21 @@ int main(int argc, char** argv)
{ {
if(level.mlook) if(level.mlook)
{ {
level.defaultPlayer[0].camera.SetViewByMouse(g_Screen); using OpenArena::Vec2i;
Vec2i middleOfScreen = Vec2i(g_Screen.GetWidth()/2, g_Screen.GetHeight()/2);
Vec2i mousePosition = g_Screen.GetMousePosition();
if(mousePosition != middleOfScreen)
{
//Vec2i mouseDelta = mousePosition - middleOfScreen;
Vec2i mouseDelta = middleOfScreen - mousePosition;
g_Screen.SetMousePosition(middleOfScreen);
const float MOUSE_SENSITIVITY_HORIZONTAL = 0.005;
const float MOUSE_SENSITIVITY_VERTICAL = 0.005;
float horizontalAngle = mouseDelta.x * MOUSE_SENSITIVITY_HORIZONTAL;
float verticalAngle = mouseDelta.y * MOUSE_SENSITIVITY_VERTICAL;
level.defaultPlayer[0].camera.RotateHorizontal(horizontalAngle);
level.defaultPlayer[0].camera.RotateVertical(verticalAngle);
}
} }
else else
{ {

View File

@@ -1,5 +0,0 @@
#include "physics.h"
WORLD_PHYSICS::WORLD_PHYSICS()
{
}

View File

@@ -1,18 +0,0 @@
//Rename/Move
/*!
* \brief
* Write brief comment for WORLD_PHYSICS here.
*
* Write detailed description for WORLD_PHYSICS here.
*
* \remarks
* Write remarks for WORLD_PHYSICS here.
*
* \see
* Separate items with the '|' character.
*/
class WORLD_PHYSICS
{
public:
WORLD_PHYSICS();
};

View File

@@ -1,26 +1,28 @@
#ifndef __texture_h__ #ifndef __texture_h__
#define __texture_h__ #define __texture_h__
/*! namespace OpenArena
* \brief
* Write brief comment for TextureImage here.
*
* Write detailed description for TextureImage here.
*
* \remarks
* Write remarks for TextureImage here.
*
* \see
* Separate items with the '|' character.
*/
class TextureImage
{ {
public: /*!
unsigned char* data; * \brief
unsigned int bpp; * Write brief comment for TextureImage here.
unsigned int sizeX; *
unsigned int sizeY; * Write detailed description for TextureImage here.
unsigned int type; *
* \remarks
* Write remarks for TextureImage here.
*
* \see
* Separate items with the '|' character.
*/
class TextureImage
{
public:
unsigned char* data;
unsigned int bpp;
unsigned int sizeX;
unsigned int sizeY;
unsigned int type;
};
}; };
#endif #endif

View File

@@ -289,18 +289,20 @@ int WINAPI WinMain( HINSTANCE hInstance,
if (level.mlook) if (level.mlook)
{ {
using OpenArena::Vec2i; using OpenArena::Vec2i;
//Get the mouse delta and rotate accordingly
Vec2i mousePosition = g_Screen.GetMousePosition();
Vec2i middleOfScreen = Vec2i(g_Screen.GetWidth()/2, g_Screen.GetHeight()/2); Vec2i middleOfScreen = Vec2i(g_Screen.GetWidth()/2, g_Screen.GetHeight()/2);
Vec2i mouseDelta = mousePosition - middleOfScreen; Vec2i mousePosition = g_Screen.GetMousePosition();
const float MOUSE_SENSATIVITY_HORIZONTAL = 1; if(mousePosition != middleOfScreen)
const float MOUSE_SENSATIVITY_VERTICAL = 1; {
float horizontalAngle = mouseDelta.x * MOUSE_SENSATIVITY_HORIZONTAL; //Vec2i mouseDelta = mousePosition - middleOfScreen;
float verticalAngle = mouseDelta.y * MOUSE_SENSATIVITY_VERTICAL; Vec2i mouseDelta = middleOfScreen - mousePosition;
level.defaultPlayer[0].camera.RotateHorizontal(horizontalAngle); g_Screen.SetMousePosition(middleOfScreen);
level.defaultPlayer[0].camera.RotateVertical(verticalAngle); const float MOUSE_SENSITIVITY_HORIZONTAL = 0.005;
//level.defaultPlayer[0].camera.SetViewByMouse(g_Screen); const float MOUSE_SENSITIVITY_VERTICAL = 0.005;
float horizontalAngle = mouseDelta.x * MOUSE_SENSITIVITY_HORIZONTAL;
float verticalAngle = mouseDelta.y * MOUSE_SENSITIVITY_VERTICAL;
level.defaultPlayer[0].camera.RotateHorizontal(horizontalAngle);
level.defaultPlayer[0].camera.RotateVertical(verticalAngle);
}
} }
else else
{ {