Changed: Renamed a few classes

Changed: Moved most sensible objects into the OpenArena namespace
~g2k
This commit is contained in:
2005-06-29 11:33:11 -04:00
parent f6a191d21d
commit c16a0dae6d
17 changed files with 1818 additions and 1781 deletions

View File

@@ -10,8 +10,8 @@
// To implement an OpenGL Camera
//
// Summary of Methods:
// CameraClass
// -CameraClass();
// Camera
// -Camera();
// Initalize PDM's. Sets position to 0,0,0 up to 0,1,0 and view to 0,0,-1
// -Vec3f Position();
// Returns a copy of the position vector.
@@ -29,7 +29,7 @@
// Sets the position, up, and view vectors to those passed in.
// -void RotateView(double angle, double X, double Y, double Z);
// Rotates the view angle degrees on the axis specified by X, Y, and Z.
// -void SetViewByMouse(SCREEN g_Screen);
// -void SetViewByMouse(Screen g_Screen);
// Rotates the pitch and yaw of the view based on the mouse.
// -void RotateAroundPoint(double angle, double X, double Y, double Z, Vec3f vCenter);
// Rotates the view angle degrees around a point vCenter on the axis specified by X, Y, Z.
@@ -46,148 +46,151 @@
#include "../include/camera.h"
CameraClass::CameraClass()
namespace OpenArena
{
m_vPosition = Vec3f(0,0,0);
m_vView = Vec3f(0,0,-1);
m_vUpVector = Vec3f(0,1,0);
}
void CameraClass::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);
}
void CameraClass::PositionCamera(Vec3f pos, Vec3f view, Vec3f up)
{
m_vPosition = pos;
m_vView = view;
m_vUpVector = up;
}
void CameraClass::SetViewByMouse(SCREEN g_Screen)
{
//Most of this is sorta right for linux I think but since I don't know how yet it's currently windows only
#ifdef WIN32
static double currentRotX = 0.0f;
POINT mpos;
POINT middle;
double angleZ;
middle.x = g_Screen.width / 2;
middle.y = g_Screen.height / 2;
GetCursorPos(&mpos);
SetCursorPos(middle.x, middle.y);
if(mpos.x != middle.x || mpos.y != middle.y)
Camera::Camera()
{
angleZ = double(middle.y - mpos.y) / 1000.0f;
currentRotX -= angleZ;
if(currentRotX > 1.0f)
currentRotX = 1.0f;
else if(currentRotX < -1.0f)
currentRotX = -1.0f;
else
{
Vec3f axis = (m_vView - m_vPosition).cross(m_vUpVector);
axis.normalize();
RotateView(angleZ, axis.x, axis.y, axis.z);
//need to switch these two when I figure out stuff for flight
//till then I think the first is faster
RotateView(double(middle.x - mpos.x) / 1000.0f, 0, 1, 0);
//RotateView(double(middle.x - mpos.x) / 1000.0f, m_vUpVector.x, m_vUpVector.y, m_vUpVector.z);
}
m_vPosition = Vec3f(0,0,0);
m_vView = Vec3f(0,0,-1);
m_vUpVector = Vec3f(0,1,0);
}
#endif
}
void CameraClass::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;
}
void CameraClass::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;
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);
}
m_vView.x = m_vPosition.x + nView.x;
m_vView.y = m_vPosition.y + nView.y;
m_vView.z = m_vPosition.z + nView.z;
}
void CameraClass::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;
}
void CameraClass::Update()
{
m_vStrafe =((m_vView - m_vPosition).cross(m_vUpVector)).normalized();
//SetViewByMouse(); //TODO take this whole function out asap
}
void CameraClass::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 CameraClass::Position()
{
return m_vPosition;
}
Vec3f CameraClass::Strafe()
{
return m_vStrafe;
}
Vec3f CameraClass::UpVector()
{
return m_vUpVector;
}
Vec3f CameraClass::View()
{
return m_vView;
}
void Camera::PositionCamera(Vec3f pos, Vec3f view, Vec3f up)
{
m_vPosition = pos;
m_vView = view;
m_vUpVector = up;
}
void Camera::SetViewByMouse(Screen g_Screen)
{
//Most of this is sorta right for linux I think but since I don't know how yet it's currently windows only
#ifdef WIN32
static double currentRotX = 0.0f;
POINT mpos;
POINT middle;
double angleZ;
middle.x = g_Screen.width / 2;
middle.y = g_Screen.height / 2;
GetCursorPos(&mpos);
SetCursorPos(middle.x, middle.y);
if(mpos.x != middle.x || mpos.y != middle.y)
{
angleZ = double(middle.y - mpos.y) / 1000.0f;
currentRotX -= angleZ;
if(currentRotX > 1.0f)
currentRotX = 1.0f;
else if(currentRotX < -1.0f)
currentRotX = -1.0f;
else
{
Vec3f axis = (m_vView - m_vPosition).cross(m_vUpVector);
axis.normalize();
RotateView(angleZ, axis.x, axis.y, axis.z);
//need to switch these two when I figure out stuff for flight
//till then I think the first is faster
RotateView(double(middle.x - mpos.x) / 1000.0f, 0, 1, 0);
//RotateView(double(middle.x - mpos.x) / 1000.0f, m_vUpVector.x, m_vUpVector.y, m_vUpVector.z);
}
}
#endif
}
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;
}
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;
}
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;
}
void Camera::Update()
{
m_vStrafe =((m_vView - m_vPosition).cross(m_vUpVector)).normalized();
//SetViewByMouse(); //TODO take this whole function out asap
}
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 Camera::Position()
{
return m_vPosition;
}
Vec3f Camera::Strafe()
{
return m_vStrafe;
}
Vec3f Camera::UpVector()
{
return m_vUpVector;
}
Vec3f Camera::View()
{
return m_vView;
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,65 +1,67 @@
#include "../include/mygl.h"
void FreeGLTexture(GLuint& texture)
namespace OpenArena
{
glDeleteTextures(1, &texture);
}
bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min)
{
if(Right(tolower(fn), 4) == ".bmp")
void FreeGLTexture(GLuint& texture)
{
TextureImage* texImage = NULL;
if(texImage = LoadBMP(fn.c_str()))
glDeleteTextures(1, &texture);
}
bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min)
{
if(Right(tolower(fn), 4) == ".bmp")
{
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE, texImage->data);
if(texImage) //Just in case somehow the file was empty or unloadable
TextureImage* texImage = NULL;
if(texImage = LoadBMP(fn.c_str()))
{
if(texImage->data)
free(texImage->data);
free(texImage);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE, texImage->data);
if(texImage) //Just in case somehow the file was empty or unloadable
{
if(texImage->data)
free(texImage->data);
free(texImage);
}
return true;
}
else
{
return false;
}
return true;
}
}
else if(Right(tolower(fn), 4) == ".tga")
{
TextureImage* texImage = NULL;
if(texImage = LoadTGA(fn.c_str()))
{
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE, texImage->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if(texImage) //Just in case somehow the file was empty or unloadable
{
if(texImage->data)
free(texImage->data);
free(texImage);
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else if(Right(tolower(fn), 4) == ".tga")
{
TextureImage* texImage = NULL;
if(texImage = LoadTGA(fn.c_str()))
{
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE, texImage->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if(texImage) //Just in case somehow the file was empty or unloadable
{
if(texImage->data)
free(texImage->data);
free(texImage);
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
};
OpenArena::Window g_Screen;

View File

@@ -25,118 +25,121 @@
#include "../include/myglFont.h"
GLFontClass::GLFontClass()
namespace OpenArena
{
status = 0;
base = 0;
texture = 0;
screenWidth = 1;
screenHeight = 1;
}
GLFontClass::~GLFontClass()
{
FreeFont();
}
bool GLFontClass::BuildFont(const char* texName)
{
FreeFont();
if(LoadGLTexture(texName, texture, GL_NEAREST, GL_NEAREST))
{
float x, y;
base = glGenLists(256);
glBindTexture(GL_TEXTURE_2D, texture);
for(short i = 0; i<256; i++)
{
x = i%16/16.0f;
y = i/16/16.0f;
glNewList(base+i, GL_COMPILE);
glBegin(GL_QUADS);
glTexCoord2f(x, 1-y-0.0625f);
glVertex2i(0,0);
glTexCoord2f(x+0.0625f, 1-y-0.0625f);
glVertex2i(16,0);
glTexCoord2f(x+0.0625f, 1-y);
glVertex2i(16,16);
glTexCoord2f(x, 1-y);
glVertex2i(0,16);
glEnd();
glTranslated(16,0,0);
glEndList();
Font::Font()
{
status = 0;
base = 0;
texture = 0;
screenWidth = 1;
screenHeight = 1;
}
Font::~Font()
{
FreeFont();
}
bool Font::BuildFont(const char* texName)
{
FreeFont();
if(LoadGLTexture(texName, texture, GL_NEAREST, GL_NEAREST))
{
float x, y;
base = glGenLists(256);
glBindTexture(GL_TEXTURE_2D, texture);
for(short i = 0; i<256; i++)
{
x = i%16/16.0f;
y = i/16/16.0f;
glNewList(base+i, GL_COMPILE);
glBegin(GL_QUADS);
glTexCoord2f(x, 1-y-0.0625f);
glVertex2i(0,0);
glTexCoord2f(x+0.0625f, 1-y-0.0625f);
glVertex2i(16,0);
glTexCoord2f(x+0.0625f, 1-y);
glVertex2i(16,16);
glTexCoord2f(x, 1-y);
glVertex2i(0,16);
glEnd();
glTranslated(16,0,0);
glEndList();
}
status = true;
}
status = true;
return status;
}
return status;
}
bool GLFontClass::FreeFont()
{
if(status)
bool Font::FreeFont()
{
glDeleteLists(base, 256);
status = false;
if(status)
{
glDeleteLists(base, 256);
status = false;
}
return status;
}
return status;
}
void GLFontClass::Print(int x, int y, const char* str, unsigned int set)
{
if(status)
void Font::Print(int x, int y, const char* str, unsigned int set)
{
if(set>1)
set = 1;
glBindTexture(GL_TEXTURE_2D, texture);
//glDisable(GL_DEPTH_TEST);
//glEnable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,screenWidth,0,screenHeight,-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslated(x, y, 0);
glListBase(base-32+(128*set));
glCallLists(strlen(str), GL_BYTE, str);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
//glDisable(GL_BLEND);
//glEnable(GL_DEPTH_TEST);
if(status)
{
if(set>1)
set = 1;
glBindTexture(GL_TEXTURE_2D, texture);
//glDisable(GL_DEPTH_TEST);
//glEnable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,screenWidth,0,screenHeight,-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslated(x, y, 0);
glListBase(base-32+(128*set));
glCallLists(strlen(str), GL_BYTE, str);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
//glDisable(GL_BLEND);
//glEnable(GL_DEPTH_TEST);
}
}
}
bool GLFontClass::Loaded()
{
return status;
}
void GLFontClass::SetScreenDimensions(short x, short y)
{
screenWidth = x;
screenHeight = y;
}
void GLFontClass::SetScreenWidth(short x)
{
screenWidth = x;
}
void GLFontClass::SetScreenHeight(short y)
{
screenHeight = y;
}
short GLFontClass::ScreenWidth()
{
return screenWidth;
}
short GLFontClass::ScreenHeight()
{
return screenHeight;
}
bool Font::Loaded()
{
return status;
}
void Font::SetScreenDimensions(short x, short y)
{
screenWidth = x;
screenHeight = y;
}
void Font::SetScreenWidth(short x)
{
screenWidth = x;
}
void Font::SetScreenHeight(short y)
{
screenHeight = y;
}
short Font::ScreenWidth()
{
return screenWidth;
}
short Font::ScreenHeight()
{
return screenHeight;
}
};

View File

@@ -1,107 +1,111 @@
#include "../include/myglTexture.h"
using namespace OpenArena;
GL_MY_TEXTURE::GL_MY_TEXTURE()
namespace OpenArena
{
id=0xFFFFFFFF;
filename = "";
minFilter = GL_LINEAR;
magFilter = GL_LINEAR;
}
GL_MY_TEXTURE::~GL_MY_TEXTURE()
{
Free();
}
string GL_MY_TEXTURE::Filename()
{
return filename;
}
GLuint GL_MY_TEXTURE::ID()
{
return id;
}
bool GL_MY_TEXTURE::Loaded()
{
return filename != "";
}
bool GL_MY_TEXTURE::Load(string fn)
{
if(Loaded())
Free();
if(LoadGLTexture(fn.c_str(), id, minFilter, magFilter))
{
filename = fn;
return true;
}
else
Texture::Texture()
{
id=0xFFFFFFFF;
return false;
}
}
bool GL_MY_TEXTURE::Load(string fn, GLuint min, GLuint mag)
{
if(Loaded())
Free();
if(LoadGLTexture(fn.c_str(), id, min, mag))
{
filename = fn;
minFilter = min;
magFilter = mag;
return true;
}
else
{
id=0xFFFFFFFF;
return false;
}
}
void GL_MY_TEXTURE::Free()
{
if(Loaded())
{
FreeGLTexture(id);
filename = "";
minFilter = GL_LINEAR;
magFilter = GL_LINEAR;
filename = "";
id = 0xFFFFFFFF;
}
}
bool GL_MY_TEXTURE::operator<(const GL_MY_TEXTURE& rtOp)
{
return id<rtOp.id;
}
bool GL_MY_TEXTURE::operator<=(const GL_MY_TEXTURE& rtOp)
{
return id<=rtOp.id;
}
bool GL_MY_TEXTURE::operator==(const GL_MY_TEXTURE& rtOp)
{
return id==rtOp.id;
}
bool GL_MY_TEXTURE::operator!=(const GL_MY_TEXTURE& rtOp)
{
return id!=rtOp.id;
}
bool GL_MY_TEXTURE::operator>=(const GL_MY_TEXTURE& rtOp)
{
return id>=rtOp.id;
}
bool GL_MY_TEXTURE::operator>(const GL_MY_TEXTURE& rtOp)
{
return id>rtOp.id;
}
Texture::~Texture()
{
Free();
}
string Texture::Filename()
{
return filename;
}
GLuint Texture::ID()
{
return id;
}
bool Texture::Loaded()
{
return filename != "";
}
bool Texture::Load(string fn)
{
if(Loaded())
Free();
if(LoadGLTexture(fn.c_str(), id, minFilter, magFilter))
{
filename = fn;
return true;
}
else
{
id=0xFFFFFFFF;
return false;
}
}
bool Texture::Load(string fn, GLuint min, GLuint mag)
{
if(Loaded())
Free();
if(LoadGLTexture(fn.c_str(), id, min, mag))
{
filename = fn;
minFilter = min;
magFilter = mag;
return true;
}
else
{
id=0xFFFFFFFF;
return false;
}
}
void Texture::Free()
{
if(Loaded())
{
FreeGLTexture(id);
minFilter = GL_LINEAR;
magFilter = GL_LINEAR;
filename = "";
id = 0xFFFFFFFF;
}
}
bool Texture::operator<(const Texture& rtOp)
{
return id<rtOp.id;
}
bool Texture::operator<=(const Texture& rtOp)
{
return id<=rtOp.id;
}
bool Texture::operator==(const Texture& rtOp)
{
return id==rtOp.id;
}
bool Texture::operator!=(const Texture& rtOp)
{
return id!=rtOp.id;
}
bool Texture::operator>=(const Texture& rtOp)
{
return id>=rtOp.id;
}
bool Texture::operator>(const Texture& rtOp)
{
return id>rtOp.id;
}
};

View File

@@ -1,23 +1,26 @@
#include "../include/player.h"
void PLAYER::Load()
namespace OpenArena
{
}
void PLAYER::Save()
{
}
void PLAYER::AddItem(unsigned int item)
{
// inventory = inventory | item;
}
void PLAYER::RemoveItem(unsigned int item)
{
// inventory = inventory & ~item;
}
void PLAYER::CreateCharacter()
{
}
void Player::Load()
{
}
void Player::Save()
{
}
void Player::AddItem(unsigned int item)
{
// inventory = inventory | item;
}
void Player::RemoveItem(unsigned int item)
{
// inventory = inventory & ~item;
}
void Player::CreateCharacter()
{
}
};