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

View File

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

View File

@@ -1,5 +1,4 @@
#include "keys.h"
#include "physics.h"
#include "datatypes.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
#include "vector.h"
#include "camera.h"
#include "entities.h"
#include "geometry.h"
#include "myglFont.h"
#include "myglTexture.h"
@@ -455,7 +454,7 @@ namespace OpenArena
Triangle* triangles;
uint32 numTriangles;
list<Player> players;
list<ENTITY> ents;
// list<ENTITY> ents;
list<Texture*> textures;
Texture menuTextures[NUM_MENU_TEXTURES];
Window* _window;

View File

@@ -222,8 +222,21 @@ int main(int argc, char** argv)
{
if(level.mlook)
{
//get the mouse delta and rotate the camera accordingly
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
{

View File

@@ -223,7 +223,21 @@ int main(int argc, char** argv)
{
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
{

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__
#define __texture_h__
/*!
* \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
namespace OpenArena
{
public:
unsigned char* data;
unsigned int bpp;
unsigned int sizeX;
unsigned int sizeY;
unsigned int type;
/*!
* \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;
unsigned int bpp;
unsigned int sizeX;
unsigned int sizeY;
unsigned int type;
};
};
#endif

View File

@@ -289,18 +289,20 @@ int WINAPI WinMain( HINSTANCE hInstance,
if (level.mlook)
{
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 mouseDelta = mousePosition - middleOfScreen;
const float MOUSE_SENSATIVITY_HORIZONTAL = 1;
const float MOUSE_SENSATIVITY_VERTICAL = 1;
float horizontalAngle = mouseDelta.x * MOUSE_SENSATIVITY_HORIZONTAL;
float verticalAngle = mouseDelta.y * MOUSE_SENSATIVITY_VERTICAL;
level.defaultPlayer[0].camera.RotateHorizontal(horizontalAngle);
level.defaultPlayer[0].camera.RotateVertical(verticalAngle);
//level.defaultPlayer[0].camera.SetViewByMouse(g_Screen);
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
{