fftrader-cvs Mailing List for Final Frontier Trader (Page 2)
Status: Alpha
Brought to you by:
tomt64
You can subscribe to this list here.
2005 |
Jan
(8) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(23) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: TomT64 <to...@us...> - 2005-01-05 22:06:09
|
Update of /cvsroot/fftrader/fftrader3d/src/engine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6521/src/engine Added Files: console.cpp console.h entity.cpp entity.h eventsys.cpp eventsys.h gfxsys.cpp gfxsys.h logicsys.cpp logicsys.h main.cpp main.h mesh.cpp mesh.h model.cpp model.h Log Message: Initial checkin --- NEW FILE: main.cpp --- #include "main.h" Engine* engine = 0; GraphicsConsole* console = 0; static int tickCount = 0; Uint32 timer_handler(Uint32 interval, void* param) { tickCount++; return interval; } void Engine::Startup() { exitFlag = false; cfg.loadConfig("fftrader.cfg"); if(cfg.getKey("log")) Log::Init("fftrader.log"); Log::Write("-------------------------\n"); Log::Write(APPNAME); Log::Write(" / " __DATE__); Log::Write("\n-------------------------\n"); Log::Write("Initializing SDL\n"); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); Log::Write("Initializing Graphics subsystem\n"); gfxSystem.Initialize(cfg.getKey("xres"), cfg.getKey("yres"), cfg.getKey("bpp"), cfg.getKey("fullscreen")); Log::Write("Initializing Event subsystem\n"); eventSystem.Initialize(); } void Engine::Run() { Entity* myEntity = new Entity(); myEntity->model = new Model("models/cube.model"); entityList.push_back(myEntity); SDL_TimerID logicTimer = SDL_AddTimer(1000/60, timer_handler, NULL); while(!exitFlag) { while(tickCount > 0) { logicSystem.procLogic(entityList, newEntities); eventSystem.procEvents(); tickCount--; } gfxSystem.procGraphics(); } SDL_RemoveTimer(logicTimer); delete myEntity->model; delete myEntity; } void Engine::Shutdown() { SDL_Quit(); } int main(int argc, char* argv[]) { freopen("CON", "w", stdout); GraphicsConsole myConsole; console = &myConsole; Engine videoGame; engine = &videoGame; engine->Startup(); engine->Run(); engine->Shutdown(); return 0; } --- NEW FILE: model.cpp --- #include "main.h" #include "model.h" Model::Model(const char *fileName) { loadModel(fileName); } Model::~Model() { delete[] meshPos; delete[] meshRot; delete[] mesh; } int Model::loadModel(const char *fileName) { ifstream inFile(fileName); inFile >> numMeshes; mesh = new Mesh*[numMeshes]; meshPos = new Vector3f[numMeshes]; meshRot = new Vector3f[numMeshes]; for(int i=0; i<numMeshes; i++) { std::string meshFile; inFile >> meshFile; mesh[i] = meshLib.load(("meshes/" + meshFile).c_str()); inFile >> meshPos[i].x >> meshPos[i].y >> meshPos[i].z; inFile >> meshRot[i].x >> meshRot[i].y >> meshRot[i].z; } inFile.close(); } --- NEW FILE: entity.cpp --- #include "entity.h" void Entity::update() { vRot.z += 1; vRot.x += 0.1; } --- NEW FILE: console.cpp --- #include "console.h" #include <gl/gl.h> gltext::FontPtr myFont(gltext::OpenFont("fonts/arial.ttf", 10)); gltext::FontRendererPtr myRenderer(gltext::CreateRenderer(gltext::TEXTURE, myFont)); void GraphicsConsole::render() { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub(255, 255, 255, 255); glPushMatrix(); glTranslatef(50, 50, 0); myRenderer->render("This is the end, my friend.. see you soon again :("); glPopMatrix(); glDisable(GL_BLEND); } --- NEW FILE: gfxsys.h --- #ifndef GFXSYS_H #define GFXSYS_H #include <sdl/sdl.h> #include <gl/gl.h> class GraphicsSystem { public: void Initialize(int xres=640, int yres=480, int bpp=16, int fullScreen=0); void procGraphics(); // Exposed render call private: void RenderScene(); // Renders Scene (perspctive elements) void RenderGUI(); // Renders GUI (orthogonal elements) SDL_Surface* _screen; // Primary OpenGL surface GLfloat _aspectRatio; // Aspect ratio of screen: xres/yres = aspect int _xres; // Width of screen resolution int _yres; // Height of screen resolution }; #endif --- NEW FILE: eventsys.h --- #ifndef EVENTSYS_H #define EVENTSYS_H #include <sdl/sdl.h> class EventSystem { public: void Initialize(); void procEvents(); private: SDL_Event sdlEvent; bool key[322]; void pollEvents(); void handleEvents(); }; #endif --- NEW FILE: eventsys.cpp --- #include "main.h" #include "eventSys.h" void EventSystem::Initialize() { for(int i=0; i<322; i++) { key[i] = false; } } void EventSystem::procEvents() { pollEvents(); handleEvents(); } void EventSystem::pollEvents() { while(SDL_PollEvent(&sdlEvent)) { if(sdlEvent.type == SDL_QUIT) {engine->exitFlag = true; } if(sdlEvent.type == SDL_KEYDOWN) { for(int i=0; i<322; i++) { if (sdlEvent.key.keysym.sym == i) { key[i] = true; } } } if(sdlEvent.type == SDL_KEYUP) { for(int i=0; i<322; i++) { if (sdlEvent.key.keysym.sym == i) { key[i] = false; } } } } } void EventSystem::handleEvents() { if (key[SDLK_ESCAPE]) { Log::Write("ESC pressed\n"); engine->exitFlag = true; } } --- NEW FILE: gfxsys.cpp --- #include "main.h" #include "gfxsys.h" #include <gl/gl.h> #include <gl/glu.h> void GraphicsSystem::Initialize(int xres, int yres, int bpp, int fullScreen) { _screen = SDL_SetVideoMode(xres, yres, bpp, SDL_OPENGL | (fullScreen ? SDL_FULLSCREEN : 0)); _xres = xres; _yres = yres; _aspectRatio = (GLfloat)_xres / (GLfloat)_yres; glViewport(0, 0, _xres, _yres); glClearColor(0.25, 0.25, 0.25, 1); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glShadeModel(GL_SMOOTH); GLfloat ambience[] = {0.0f, 0.0f, 0.0f, 1.0}; GLfloat diffuse[] = {1.0f, 1.0f, 1.0f, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, ambience); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); } void GraphicsSystem::procGraphics() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); RenderScene(); RenderGUI(); SDL_GL_SwapBuffers(); } void GraphicsSystem::RenderScene() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, _aspectRatio, 0.1, 16); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0); GLfloat lightPos[] = {0, 0, 10, 0}; glLightfv(GL_LIGHT0, GL_POSITION, lightPos); std::vector<Entity*>::iterator curEnt; for(curEnt = engine->entityList.begin(); curEnt != engine->entityList.end(); curEnt++) { if((*curEnt)->bVisible == true) { glPushMatrix(); glTranslatef((*curEnt)->vPos.x, (*curEnt)->vPos.y, (*curEnt)->vPos.z); glRotatef((*curEnt)->vRot.x, 1, 0, 0); glRotatef((*curEnt)->vRot.y, 0, 1, 0); glRotatef((*curEnt)->vRot.z, 0, 0, 1); for(int i=0; i<(*curEnt)->model->numMeshes; i++) { glPushMatrix(); glTranslatef((*curEnt)->model->meshPos[i].x, (*curEnt)->model->meshPos[i].y, (*curEnt)->model->meshPos[i].z); glRotatef((*curEnt)->model->meshRot[i].x, 1, 0, 0); glRotatef((*curEnt)->model->meshRot[i].y, 0, 1, 0); glRotatef((*curEnt)->model->meshRot[i].z, 0, 0, 1); glColor4ub(255, 255, 255, 255); glCallList((*curEnt)->model->mesh[i]->listID); glPopMatrix(); } glPopMatrix(); } } } void GraphicsSystem::RenderGUI() { glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, _xres, _yres, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPushMatrix(); glColor4ub(0, 0, 255, 128); glBegin(GL_QUADS); glVertex2f(0, 0); glVertex2f(0, 0); glVertex2f(320, 480); glVertex2f(640, 0); glEnd(); glColor4ub(255, 255, 255, 255); glPopMatrix(); glDisable(GL_BLEND); console->render(); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); } --- NEW FILE: console.h --- #ifndef GFXCONSOLE_H #define GFXCONSOLE_H #include <common/console.h> #include <gltext.h> class GraphicsConsole : public Console { public: virtual void render(); }; #endif --- NEW FILE: logicsys.h --- #ifndef LOGICSYS_H #define LOGICSYS_H #include <vector> #include "entity.h" /** * LogicSystem is a singleton class where all game logic is processed. */ class LogicSystem { public: void procLogic(std::vector<Entity*> &entityList, std::vector<Entity*> &newEntites); }; #endif --- NEW FILE: model.h --- #ifndef MODEL_H #define MODEL_H #include "3dmath/vector3f.h" #include "mesh.h" #include <common/datalib.h> class Model { public: Model(const char *fileName); ~Model(); Mesh **mesh; Vector3f *meshPos; Vector3f *meshRot; int numMeshes; DataLib<Mesh> meshLib; int loadModel(const char *fileName); }; #endif --- NEW FILE: main.h --- #ifndef ENGINE_H #define ENGINE_H #include <iostream> // For debug purposes using namespace std; // For debug purposes #define APPNAME "FFTrader 3D" #include <vector> #include "gfxsys.h" #include "eventsys.h" #include "logicsys.h" #include "entity.h" #include "console.h" #include "model.h" #include "mesh.h" #include <common/config.h> #include <common/log.h> /** * The main engine that runs the game. */ class Engine { public: void Startup(); //!< Turns the key void Run(); void Shutdown(); GraphicsSystem gfxSystem; EventSystem eventSystem; LogicSystem logicSystem; ConfigFile cfg; std::vector<Entity*> entityList; std::vector<Entity*> newEntities; Entity* player; Entity* camera; bool exitFlag; }; extern Engine* engine; extern GraphicsConsole* console; #endif --- NEW FILE: logicsys.cpp --- #include "logicsys.h" void LogicSystem::procLogic(std::vector<Entity*> &entityList, std::vector<Entity*> &newEntities) { std::vector<Entity*>::iterator curEnt; for(curEnt = entityList.begin(); curEnt != entityList.end(); curEnt++) (*curEnt)->update(); for(curEnt = entityList.begin(); curEnt != entityList.end(); curEnt++) { if((*curEnt)->bDead) { delete *curEnt; entityList.erase(curEnt); curEnt--; } } for(curEnt = newEntities.begin(); curEnt != newEntities.end(); curEnt++) entityList.push_back(*curEnt); newEntities.clear(); } --- NEW FILE: mesh.cpp --- #include "mesh.h" #include <gl/gl.h> #include <stdio.h> Mesh::Mesh(const char* fileName) { loadMesh(fileName); genList(); } Mesh::~Mesh() { delete[] verts; delete[] faces; // delete[] coords; delete[] normals; } void Mesh::genList() { listID = glGenLists(1); glNewList(listID, GL_COMPILE); glBegin(GL_TRIANGLES); for(int i=0; i<numFaces; i++) { glNormal3f(normals[faces[i].x].x, normals[faces[i].x].y, normals[faces[i].x].z); glVertex3f(verts[faces[i].x].x, verts[faces[i].x].y, verts[faces[i].x].z); glNormal3f(normals[faces[i].y].x, normals[faces[i].y].y, normals[faces[i].y].z); glVertex3f(verts[faces[i].y].x, verts[faces[i].y].y, verts[faces[i].y].z); glNormal3f(normals[faces[i].z].x, normals[faces[i].z].y, normals[faces[i].z].z); glVertex3f(verts[faces[i].z].x, verts[faces[i].z].y, verts[faces[i].z].z); } glEnd(); glEndList(); } int Mesh::loadMesh(const char* fileName) { int i, j; float tFloat; FILE *fp = fopen(fileName, "rb"); if(fp == NULL) { // cout << "ERROR: FILE NOT FOUND" << endl; numVerts = 0; numFaces = 0; // numCoords = 0; return 1; } //==================================== //Load in Vertice and Face Information //==================================== fread(&numVerts, 1, sizeof(long), fp); verts = new Vector3f[numVerts]; normals = new Vector3f[numVerts]; //cout << fileName << " - numVerts: " << numVerts << endl; for(i=0; i<numVerts; i++) { fread(&verts[i].x , 1, sizeof(float), fp); fread(&verts[i].y , 1, sizeof(float), fp); fread(&verts[i].z , 1, sizeof(float), fp); fread(&normals[i].x, 1, sizeof(float), fp); fread(&normals[i].y, 1, sizeof(float), fp); fread(&normals[i].z, 1, sizeof(float), fp); tFloat = -verts[i].y; verts[i].y = verts[i].z; verts[i].z = tFloat; tFloat = -normals[i].y; normals[i].y = normals[i].z; normals[i].z = tFloat; } fread(&numFaces, 1, sizeof(long), fp); faces = new t_Face[numFaces]; //cout << fileName << " - numFaces: " << numFaces << endl; for(i=0; i<numFaces; i++) { fread(&faces[i].x, 1, sizeof(unsigned short), fp); fread(&faces[i].y, 1, sizeof(unsigned short), fp); fread(&faces[i].z, 1, sizeof(unsigned short), fp); } fclose(fp); /* //============================== //PreCalculate Plane Information //============================== planes = new Plane[numFaces]; //cout << fileName << " - numPlanes: " << numFaces << endl; for(i=0; i<numFaces; i++) { Vector3f vTriangle[3]; vTriangle[0] = verts[faces[i].x]; vTriangle[1] = verts[faces[i].y]; vTriangle[2] = verts[faces[i].z]; planes[i].point = verts[faces[i].x]; planes[i].normal = Vector3f::Normal(vTriangle); planes[i].distance = -1 * Vector3f::Dot(planes[i].normal, planes[i].point); } */ return 0; } --- NEW FILE: mesh.h --- #ifndef MESH_H #define MESH_H #include "3dmath/vector3f.h" #include "3dmath/face.h" #include "3dmath/texcoord.h" class Mesh { public: Mesh(const char* fileName); ~Mesh(); Vector3f *verts; Vector3f *normals; t_Face *faces; // t_Texcoord *coords; // Plane *planes; long numFaces; long numVerts; // long numCoords; int listID; int loadMesh(const char* fileName); void genList(); }; #endif --- NEW FILE: entity.h --- #ifndef ENTITY_H #define ENTITY_H #include "model.h" #include "3dmath/vector3f.h" class Entity { public: Entity() : bDead(false), bVisible(true) {} bool bVisible; bool bDead; void update(); Model *model; Vector3f vPos; Vector3f vRot; }; #endif |
From: TomT64 <to...@us...> - 2005-01-05 22:06:08
|
Update of /cvsroot/fftrader/fftrader3d/src/engine/3dmath In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6521/src/engine/3dmath Added Files: face.h texcoord.h vector3f.h Log Message: Initial checkin --- NEW FILE: vector3f.h --- #ifndef VECTOR3F_H #define VECTOR3F_H class Vector3f { public: Vector3f() : x(0), y(0), z(0) {} Vector3f(float X, float Y, float Z) : x(X), y(Y), z(Z) {} inline Vector3f operator + (Vector3f addVector) { return Vector3f(x + addVector.x, y + addVector.y, z + addVector.z); } inline Vector3f operator - (Vector3f subVector) { return Vector3f(x - subVector.x, y - subVector.y, z - subVector.z); } inline Vector3f operator * (float scalar) { return Vector3f(scalar * x, scalar * y, scalar * z); } inline Vector3f operator / (float scalar) { return Vector3f(scalar / x, scalar / y, scalar / z); } float x, y, z; }; #endif --- NEW FILE: face.h --- #ifndef FACE_H #define FACE_H typedef struct { unsigned short x, y, z; } t_Face; #endif --- NEW FILE: texcoord.h --- #ifndef TEXCOORD_H #define TEXCOORD_H typedef struct { float u, v; } t_Texcoord; #endif |
From: TomT64 <to...@us...> - 2005-01-05 22:06:07
|
Update of /cvsroot/fftrader/fftrader3d/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6521/src Added Files: Makefile.mingw Log Message: Initial checkin --- NEW FILE: Makefile.mingw --- ENGINESRC = engine/main.o engine/gfxsys.o engine/eventsys.o engine/logicsys.o engine/entity.o engine/console.o COMMONSRC = common/log.o common/config.o common/console.o DATASRC = engine/model.o engine/mesh.o MMTHSRC = engine/3dmath/vector3f.o engine/3dmath/plane.o CPPFLAGS = -I$(CURDIR) LIB = -lmingw32 -lSDLmain -lSDL -lopengl32 -lglu32 -lgltext main : $(ENGINESRC) $(COMMONSRC) $(DATASRC) $(MATHSRC) g++ -o ../fftrader.exe $(ENGINESRC) $(COMMONSRC) $(DATASRC) $(MATHSRC) $(LIB) |
From: TomT64 <to...@us...> - 2005-01-05 22:06:07
|
Update of /cvsroot/fftrader/fftrader3d/models In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6521/models Added Files: cube.model ship.model Log Message: Initial checkin --- NEW FILE: cube.model --- 1 cube.mesh 0 0 0 0 0 0 --- NEW FILE: ship.model --- (Model (Mesh (x 0) (y 0) (z 0) ) ) |
From: TomT64 <to...@us...> - 2005-01-05 22:06:07
|
Update of /cvsroot/fftrader/fftrader3d/meshes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6521/meshes Added Files: Cube.mesh Log Message: Initial checkin --- NEW FILE: Cube.mesh --- (This appears to be a binary file; contents omitted.) |
From: TomT64 <to...@us...> - 2005-01-05 22:06:06
|
Update of /cvsroot/fftrader/fftrader3d/fonts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6521/fonts Added Files: ARIAL.TTF VERDANA.TTF Log Message: Initial checkin --- NEW FILE: ARIAL.TTF --- (This appears to be a binary file; contents omitted.) --- NEW FILE: VERDANA.TTF --- (This appears to be a binary file; contents omitted.) |