mirror of
https://github.com/glest/glest-source.git
synced 2025-10-02 02:16:40 +02:00
Code Restructuring to make mega-glest more standard
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
#ifndef _SHARED_GRAPHICS_BUFFER_H_
|
||||
#define _SHARED_GRAPHICS_BUFFER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class VertexBuffer
|
||||
// =====================================================
|
||||
|
||||
class VertexBuffer{
|
||||
private:
|
||||
static const int texCoordCount = 8;
|
||||
static const int attribCount = 8;
|
||||
|
||||
private:
|
||||
void *positionPointer;
|
||||
void *normalPointer;
|
||||
|
||||
void *texCoordPointers[texCoordCount];
|
||||
int texCoordCoordCounts[texCoordCount];
|
||||
|
||||
void *attribPointers[attribCount];
|
||||
int attribCoordCounts[attribCount];
|
||||
string attribNames[attribCount];
|
||||
|
||||
public:
|
||||
VertexBuffer();
|
||||
virtual ~VertexBuffer(){};
|
||||
|
||||
virtual void init(int size)= 0;
|
||||
|
||||
void setPositionPointer(void *pointer);
|
||||
void setNormalPointer(void *pointer);
|
||||
void setTexCoordPointer(void *pointer, int texCoordIndex, int coordCount);
|
||||
void setAttribPointer(void *pointer, int attribIndex, int coordCount, const string &name);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class IndexBuffer
|
||||
// =====================================================
|
||||
|
||||
class IndexBuffer{
|
||||
private:
|
||||
void *indexPointer;
|
||||
|
||||
public:
|
||||
IndexBuffer();
|
||||
virtual ~IndexBuffer(){}
|
||||
|
||||
virtual void init(int size)= 0;
|
||||
|
||||
void setIndexPointer(void *pointer);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,48 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_CAMERA_H_
|
||||
#define _SHARED_GRAPHICS_CAMERA_H_
|
||||
|
||||
#include "vec.h"
|
||||
#include "quaternion.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class Camera
|
||||
// =====================================================
|
||||
|
||||
class Camera{
|
||||
private:
|
||||
Quaternion orientation;
|
||||
Vec3f position;
|
||||
public:
|
||||
Camera();
|
||||
|
||||
Vec3f getPosition() const {return position;}
|
||||
Quaternion getOrientation() const {return orientation;}
|
||||
|
||||
void setPosition(const Vec3f &position) {this->position= position;}
|
||||
void setOrientation(const Quaternion &orientation) {this->orientation= orientation;}
|
||||
|
||||
void moveLocalX(float amount);
|
||||
void moveLocalY(float amount);
|
||||
void moveLocalZ(float amount);
|
||||
|
||||
void addYaw(float amount);
|
||||
void addPitch(float amount);
|
||||
void addRoll(float amount);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,53 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_CONTEXT_H_
|
||||
#define _SHARED_GRAPHICS_CONTEXT_H_
|
||||
|
||||
#include "types.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
using Platform::uint32;
|
||||
|
||||
// =====================================================
|
||||
// class Context
|
||||
// =====================================================
|
||||
|
||||
class Context{
|
||||
protected:
|
||||
uint32 colorBits;
|
||||
uint32 depthBits;
|
||||
uint32 stencilBits;
|
||||
|
||||
public:
|
||||
Context();
|
||||
virtual ~Context(){}
|
||||
|
||||
uint32 getColorBits() const {return colorBits;}
|
||||
uint32 getDepthBits() const {return depthBits;}
|
||||
uint32 getStencilBits() const {return stencilBits;}
|
||||
|
||||
void setColorBits(uint32 colorBits) {this->colorBits= colorBits;}
|
||||
void setDepthBits(uint32 depthBits) {this->depthBits= depthBits;}
|
||||
void setStencilBits(uint32 stencilBits) {this->stencilBits= stencilBits;}
|
||||
|
||||
virtual void init()= 0;
|
||||
virtual void end()= 0;
|
||||
virtual void reset()= 0;
|
||||
|
||||
virtual void makeCurrent()= 0;
|
||||
virtual void swapBuffers()= 0;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,48 +0,0 @@
|
||||
#ifndef _SHARED_D3D9_DEVICECONTEXTD3D9_H_
|
||||
#define _SHARED_D3D9_DEVICECONTEXTD3D9_H_
|
||||
|
||||
#include "context.h"
|
||||
|
||||
#include <d3d9.h>
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class ContextD3d9
|
||||
// ===============================
|
||||
|
||||
class ContextD3d9: public Context{
|
||||
private:
|
||||
bool windowed;
|
||||
bool hardware;
|
||||
|
||||
IDirect3D9 *d3dObject;
|
||||
IDirect3DDevice9 *d3dDevice;
|
||||
D3DCAPS9 caps;
|
||||
D3DPRESENT_PARAMETERS d3dPresentParameters;
|
||||
|
||||
public:
|
||||
bool getWindowed() const {return windowed;}
|
||||
bool getHardware() const {return hardware;}
|
||||
|
||||
void setWindowed(bool windowed) {this->windowed= windowed;}
|
||||
void setHardware(bool hardware) {this->hardware= hardware;}
|
||||
|
||||
ContextD3d9();
|
||||
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
virtual void reset();
|
||||
|
||||
virtual void makeCurrent();
|
||||
virtual void swapBuffers();
|
||||
|
||||
const D3DCAPS9 *getCaps() const {return ∩︀};
|
||||
|
||||
|
||||
IDirect3DDevice9 *getD3dDevice() {return d3dDevice;}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,26 +0,0 @@
|
||||
#ifndef _SHARED_D3D9_D3D9UTIL_H_
|
||||
#define _SHARED_D3D9_D3D9UTIL_H_
|
||||
|
||||
#include <d3d9.h>
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#define D3DCALL(X) checkResult(X, #X);
|
||||
|
||||
using std::string;
|
||||
using std::runtime_error;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
string d3dErrorToStr(HRESULT result);
|
||||
|
||||
inline void checkResult(HRESULT result, const string &functionCall){
|
||||
if(result!=D3D_OK){
|
||||
throw runtime_error("Direct3D Error\nCode: " + d3dErrorToStr(result) + "\nFunction: " + functionCall);
|
||||
}
|
||||
}
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,26 +0,0 @@
|
||||
#ifndef _SHARED_D3D9_FONTD3D9_H_
|
||||
#define _SHARED_D3D9_FONTD3D9_H_
|
||||
|
||||
#include "font.h"
|
||||
|
||||
#include <d3dx9.h>
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class FontD3d9
|
||||
// ===============================
|
||||
|
||||
class Font2DD3d9: public Font2D{
|
||||
private:
|
||||
LPD3DXFONT d3dFont;
|
||||
|
||||
public:
|
||||
LPD3DXFONT getD3dFont() const {return d3dFont;}
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,33 +0,0 @@
|
||||
#ifndef _SHARED_D3D9_GRAPHICSFACTORYD3D9_H_
|
||||
#define _SHARED_D3D9_GRAPHICSFACTORYD3D9_H_
|
||||
|
||||
#include "context_d3d9.h"
|
||||
#include "model_renderer_d3d9.h"
|
||||
#include "texture_d3d9.h"
|
||||
#include "font_d3d9.h"
|
||||
#include "text_renderer_d3d9.h"
|
||||
#include "shader_d3d9.h"
|
||||
#include "graphics_factory.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class GraphicsFactoryD3d9
|
||||
// ===============================
|
||||
|
||||
class GraphicsFactoryD3d9: public GraphicsFactory{
|
||||
public:
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return new TextRenderer2DD3d9();}
|
||||
virtual ModelRenderer *newModelRenderer() {return NULL;}
|
||||
virtual Context *newContext() {return new ContextD3d9();}
|
||||
virtual Texture2D *newTexture2D() {return new Texture2DD3d9();}
|
||||
virtual TextureCube *newTextureCube() {return new TextureCubeD3d9();}
|
||||
virtual Font2D *newFont2D() {return new Font2DD3d9();}
|
||||
virtual ShaderProgram *newShaderProgram() {return new ShaderProgramD3d9();}
|
||||
virtual VertexShader *newVertexShader() {return new VertexShaderD3d9();}
|
||||
virtual FragmentShader *newFragmentShader() {return new PixelShaderD3d9();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,53 +0,0 @@
|
||||
#ifndef _SHARED_D3D9_MODELRENDERERD3D9_H_
|
||||
#define _SHARED_D3D9_MODELRENDERERD3D9_H_
|
||||
|
||||
#include "model_renderer.h"
|
||||
#include "model.h"
|
||||
|
||||
#include <d3d9.h>
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class ModelRendererD3d9
|
||||
// ===============================
|
||||
|
||||
class ModelRendererD3d9: public ModelRenderer{
|
||||
private:
|
||||
static const int defBufferPointCount= 100; //buffer size in vertices
|
||||
static const int defBufferIndexCount= 100; //buffer size in vertices
|
||||
|
||||
struct CustomVertexPNTT{
|
||||
Vec3f vertex;
|
||||
Vec3f normal;
|
||||
Vec2f texCoord;
|
||||
Vec3f tangent;
|
||||
};
|
||||
|
||||
private:
|
||||
bool rendering;
|
||||
int bufferPointCount;
|
||||
int bufferIndexCount;
|
||||
|
||||
IDirect3DDevice9 *d3dDevice;
|
||||
IDirect3DVertexBuffer9 *d3dVertexBuffer;
|
||||
IDirect3DIndexBuffer9 *d3dIndexBuffer;
|
||||
IDirect3DVertexDeclaration9 *d3dVertexDeclarationPNT;
|
||||
IDirect3DVertexDeclaration9 *d3dVertexDeclarationPNTT;
|
||||
|
||||
public:
|
||||
ModelRendererD3d9();
|
||||
~ModelRendererD3d9();
|
||||
virtual void begin(bool renderNormals= true, bool renderTextures= true, bool renderColors= true);
|
||||
virtual void end();
|
||||
virtual void render(const Model *model);
|
||||
virtual void renderNormalsOnly(const Model *model);
|
||||
|
||||
private:
|
||||
void renderMesh(const Mesh *mesh);
|
||||
void readyBuffers(int newPointCount, int newIndexCount);
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,109 +0,0 @@
|
||||
#ifndef _SHARED_D3D9_SHADERD3D9_H_
|
||||
#define _SHARED_D3D9_SHADERD3D9_H_
|
||||
|
||||
#include "shader.h"
|
||||
#include "vec.h"
|
||||
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9shader.h>
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class ShaderProgramD3d9
|
||||
// ===============================
|
||||
|
||||
class VertexShaderD3d9;
|
||||
class PixelShaderD3d9;
|
||||
|
||||
class ShaderProgramD3d9: public virtual ShaderProgram{
|
||||
protected:
|
||||
IDirect3DDevice9 *d3dDevice;
|
||||
ID3DXConstantTable *d3dVsConstantTable;
|
||||
ID3DXConstantTable *d3dPsConstantTable;
|
||||
|
||||
VertexShaderD3d9 *vertexShader;
|
||||
PixelShaderD3d9 *pixelShader;
|
||||
|
||||
public:
|
||||
ShaderProgramD3d9();
|
||||
|
||||
virtual void init(){};
|
||||
virtual void end(){};
|
||||
|
||||
virtual void attach(VertexShader *vs, FragmentShader *fs);
|
||||
virtual void activate();
|
||||
|
||||
virtual bool link(string &messages);
|
||||
|
||||
virtual void setUniform(const string &name, int value);
|
||||
virtual void setUniform(const string &name, float value);
|
||||
virtual void setUniform(const string &name, const Vec2f &value);
|
||||
virtual void setUniform(const string &name, const Vec3f &value);
|
||||
virtual void setUniform(const string &name, const Vec4f &value);
|
||||
virtual void setUniform(const string &name, const Matrix3f &value);
|
||||
virtual void setUniform(const string &name, const Matrix4f &value);
|
||||
//virtual void setUniform(const string &name, const Texture *value);
|
||||
};
|
||||
|
||||
|
||||
// ===============================
|
||||
// class ShaderD3d9
|
||||
// ===============================
|
||||
|
||||
class ShaderD3d9: virtual public Shader{
|
||||
protected:
|
||||
ShaderSource source;
|
||||
string target;
|
||||
|
||||
IDirect3DDevice9 *d3dDevice;
|
||||
ID3DXConstantTable *d3dConstantTable;
|
||||
|
||||
public:
|
||||
ShaderD3d9();
|
||||
virtual void init(){};
|
||||
virtual void end();
|
||||
virtual void load(const string &path);
|
||||
|
||||
ID3DXConstantTable *getD3dConstantTable() const {return d3dConstantTable;}
|
||||
|
||||
void setTarget(const string &target) {this->target= target;}
|
||||
};
|
||||
|
||||
// ===============================
|
||||
// class VertexShaderD3d9
|
||||
// ===============================
|
||||
|
||||
class VertexShaderD3d9: public ShaderD3d9, public VertexShader{
|
||||
private:
|
||||
IDirect3DVertexShader9 *d3dVertexShader;
|
||||
|
||||
public:
|
||||
VertexShaderD3d9();
|
||||
virtual void end();
|
||||
|
||||
virtual bool compile(string &messages);
|
||||
|
||||
IDirect3DVertexShader9 *getD3dVertexShader() const {return d3dVertexShader;}
|
||||
};
|
||||
|
||||
// ===============================
|
||||
// class PixelShaderD3d9
|
||||
// ===============================
|
||||
|
||||
class PixelShaderD3d9: public ShaderD3d9, public FragmentShader{
|
||||
private:
|
||||
IDirect3DPixelShader9 *d3dPixelShader;
|
||||
|
||||
public:
|
||||
PixelShaderD3d9();
|
||||
virtual void end();
|
||||
|
||||
virtual bool compile(string &messages);
|
||||
|
||||
IDirect3DPixelShader9 *getD3dPixelShader() const {return d3dPixelShader;}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,25 +0,0 @@
|
||||
#ifndef _SHARED_D3D9_TEXTRENDERERD3D9_H_
|
||||
#define _SHARED_D3D9_TEXTRENDERERD3D9_H_
|
||||
|
||||
#include "text_renderer.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class TextRenderer2DD3d9
|
||||
// ===============================
|
||||
|
||||
class TextRenderer2DD3d9: public TextRenderer2D{
|
||||
private:
|
||||
const Font *font;
|
||||
Vec4f color;
|
||||
|
||||
public:
|
||||
virtual void begin(const Font2D *font);
|
||||
virtual void render(const string &text, int x, int y, bool centered= false);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,41 +0,0 @@
|
||||
#ifndef _SHARED_D3D9_TEXTURED3D9_H_
|
||||
#define _SHARED_D3D9_TEXTURED3D9_H_
|
||||
|
||||
#include "texture.h"
|
||||
#include <d3d9.h>
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace D3d9{
|
||||
|
||||
// ===============================
|
||||
// class Texture2DD3d9
|
||||
// ===============================
|
||||
|
||||
class Texture2DD3d9: public Texture2D{
|
||||
private:
|
||||
IDirect3DTexture9 *d3dTexture;
|
||||
|
||||
public:
|
||||
IDirect3DTexture9 *getD3dTexture() const {return d3dTexture;}
|
||||
|
||||
virtual void init(Filter textureFilter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// ===============================
|
||||
// class TextureCubeD3d9
|
||||
// ===============================
|
||||
|
||||
class TextureCubeD3d9: public TextureCube{
|
||||
private:
|
||||
IDirect3DCubeTexture9 *d3dCubeTexture;
|
||||
|
||||
public:
|
||||
IDirect3DCubeTexture9 *getD3dCubeTexture() const {return d3dCubeTexture;}
|
||||
|
||||
virtual void init(Filter textureFilter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,110 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_FONT_H_
|
||||
#define _SHARED_GRAPHICS_FONT_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class FontMetrics
|
||||
// =====================================================
|
||||
|
||||
class FontMetrics{
|
||||
private:
|
||||
float *widths;
|
||||
float height;
|
||||
|
||||
public:
|
||||
FontMetrics();
|
||||
~FontMetrics();
|
||||
|
||||
void setWidth(int i, float width) {widths[i]= width;}
|
||||
void setHeight(float height) {this->height= height;}
|
||||
|
||||
float getTextWidth(const string &str) const;
|
||||
float getHeight() const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Font
|
||||
// =====================================================
|
||||
|
||||
class Font{
|
||||
public:
|
||||
static const int charCount;
|
||||
|
||||
public:
|
||||
enum Width{
|
||||
wNormal= 400,
|
||||
wBold= 700
|
||||
};
|
||||
|
||||
protected:
|
||||
string type;
|
||||
int width;
|
||||
bool inited;
|
||||
FontMetrics metrics;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Font();
|
||||
virtual ~Font(){};
|
||||
virtual void init()=0;
|
||||
virtual void end()=0;
|
||||
|
||||
//get
|
||||
string getType() const {return type;}
|
||||
int getWidth() const {return width;}
|
||||
const FontMetrics *getMetrics() const {return &metrics;}
|
||||
|
||||
//set
|
||||
void setType(string type) {this->type= type;}
|
||||
void setWidth(int width) {this->width= width;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Font2D
|
||||
// =====================================================
|
||||
|
||||
class Font2D: public Font{
|
||||
protected:
|
||||
int size;
|
||||
|
||||
public:
|
||||
Font2D();
|
||||
|
||||
int getSize() const {return size;}
|
||||
void setSize(int size) {this->size= size;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Font3D
|
||||
// =====================================================
|
||||
|
||||
class Font3D: public Font{
|
||||
protected:
|
||||
float depth;
|
||||
|
||||
public:
|
||||
Font3D();
|
||||
|
||||
float getDepth() const {return depth;}
|
||||
void setDepth(float depth) {this->depth= depth;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,48 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_FONTMANAGER_H_
|
||||
#define _SHARED_GRAPHICS_FONTMANAGER_H_
|
||||
|
||||
#include "font.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class FontManager
|
||||
//
|
||||
/// Creates, Intializes, Finalizes, and Deletes fonts
|
||||
// =====================================================
|
||||
|
||||
class FontManager{
|
||||
protected:
|
||||
typedef vector<Font*> FontContainer;
|
||||
|
||||
protected:
|
||||
FontContainer fonts;
|
||||
|
||||
public:
|
||||
virtual ~FontManager();
|
||||
|
||||
Font2D *newFont2D();
|
||||
Font3D *newFont3D();
|
||||
|
||||
void init();
|
||||
void end();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,43 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_CONTEXTGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_CONTEXTGL_H_
|
||||
|
||||
#include "context.h"
|
||||
#include "gl_wrap.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
using Platform::PlatformContextGl;
|
||||
|
||||
// =====================================================
|
||||
// class ContextGl
|
||||
// =====================================================
|
||||
|
||||
class ContextGl: public Context{
|
||||
protected:
|
||||
PlatformContextGl pcgl;
|
||||
|
||||
public:
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
virtual void reset(){};
|
||||
|
||||
virtual void makeCurrent();
|
||||
virtual void swapBuffers();
|
||||
|
||||
const PlatformContextGl *getPlatformContextGl() const {return &pcgl;}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,58 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_FONTGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_FONTGL_H_
|
||||
|
||||
#include "font.h"
|
||||
#include "opengl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class FontGl
|
||||
// =====================================================
|
||||
|
||||
class FontGl{
|
||||
protected:
|
||||
GLuint handle;
|
||||
|
||||
public:
|
||||
GLuint getHandle() const {return handle;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Font2DGl
|
||||
//
|
||||
/// OpenGL bitmap font
|
||||
// =====================================================
|
||||
|
||||
class Font2DGl: public Font2D, public FontGl{
|
||||
public:
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Font3DGl
|
||||
//
|
||||
/// OpenGL outline font
|
||||
// =====================================================
|
||||
|
||||
class Font3DGl: public Font3D, public FontGl{
|
||||
public:
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,43 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_GRAPHICSFACTORYBASICGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_GRAPHICSFACTORYBASICGL_H_
|
||||
|
||||
#include "graphics_factory.h"
|
||||
#include "text_renderer_gl.h"
|
||||
#include "model_renderer_gl.h"
|
||||
#include "context_gl.h"
|
||||
#include "model_gl.h"
|
||||
#include "texture_gl.h"
|
||||
#include "font_gl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsFactoryBasicGl
|
||||
// =====================================================
|
||||
|
||||
class GraphicsFactoryBasicGl: public GraphicsFactory{
|
||||
public:
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return new TextRenderer2DGl();}
|
||||
virtual TextRenderer3D *newTextRenderer3D() {return new TextRenderer3DGl();}
|
||||
virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();}
|
||||
virtual Context *newContext() {return new ContextGl();}
|
||||
virtual Model *newModel() {return new ModelGl();}
|
||||
virtual Texture2D *newTexture2D() {return new Texture2DGl();}
|
||||
virtual Font2D *newFont2D() {return new Font2DGl();}
|
||||
virtual Font3D *newFont3D() {return new Font3DGl();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,65 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL_H_
|
||||
|
||||
#include "texture_manager.h"
|
||||
#include "model_manager.h"
|
||||
#include "particle.h"
|
||||
#include "font_manager.h"
|
||||
#include "graphics_factory.h"
|
||||
#include "text_renderer_gl.h"
|
||||
#include "model_renderer_gl.h"
|
||||
#include "particle_renderer_gl.h"
|
||||
#include "context_gl.h"
|
||||
#include "model_gl.h"
|
||||
#include "texture_gl.h"
|
||||
#include "font_gl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsFactoryGl
|
||||
// =====================================================
|
||||
|
||||
class GraphicsFactoryGl: public GraphicsFactory{
|
||||
public:
|
||||
//context
|
||||
virtual Context *newContext() {return new ContextGl();}
|
||||
|
||||
//textures
|
||||
virtual TextureManager *newTextureManager() {return new TextureManager();}
|
||||
virtual Texture1D *newTexture1D() {return new Texture1DGl();}
|
||||
virtual Texture2D *newTexture2D() {return new Texture2DGl();}
|
||||
virtual Texture3D *newTexture3D() {return new Texture3DGl();}
|
||||
virtual TextureCube *newTextureCube() {return new TextureCubeGl();}
|
||||
|
||||
//models
|
||||
virtual ModelManager *newModelManager() {return new ModelManager();}
|
||||
virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();}
|
||||
virtual Model *newModel() {return new ModelGl();}
|
||||
|
||||
//text
|
||||
virtual FontManager *newFontManager() {return new FontManager();}
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return new TextRenderer2DGl();}
|
||||
virtual TextRenderer3D *newTextRenderer3D() {return new TextRenderer3DGl();}
|
||||
virtual Font2D *newFont2D() {return new Font2DGl();}
|
||||
virtual Font3D *newFont3D() {return new Font3DGl();}
|
||||
|
||||
//particles
|
||||
virtual ParticleManager *newParticleManager() {return new ParticleManager();}
|
||||
virtual ParticleRenderer *newParticleRenderer() {return new ParticleRendererGl();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,62 +0,0 @@
|
||||
#ifndef _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL2_H_
|
||||
#define _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL2_H_
|
||||
|
||||
#include "texture_manager.h"
|
||||
#include "model_manager.h"
|
||||
#include "font_manager.h"
|
||||
#include "particle.h"
|
||||
#include "graphics_factory.h"
|
||||
#include "text_renderer_gl.h"
|
||||
#include "model_renderer_gl.h"
|
||||
#include "particle_renderer_gl.h"
|
||||
#include "context_gl.h"
|
||||
#include "model_gl.h"
|
||||
#include "texture_gl.h"
|
||||
#include "font_gl.h"
|
||||
#include "shader_gl.h"
|
||||
#include "shader_manager.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsFactoryGl
|
||||
// =====================================================
|
||||
|
||||
class GraphicsFactoryGl2: public GraphicsFactory{
|
||||
public:
|
||||
//context
|
||||
virtual Context *newContext() {return new ContextGl();}
|
||||
|
||||
//textures
|
||||
virtual TextureManager *newTextureManager() {return new TextureManager();}
|
||||
virtual Texture1D *newTexture1D() {return new Texture1DGl();}
|
||||
virtual Texture2D *newTexture2D() {return new Texture2DGl();}
|
||||
virtual Texture3D *newTexture3D() {return new Texture3DGl();}
|
||||
virtual TextureCube *newTextureCube() {return new TextureCubeGl();}
|
||||
|
||||
//models
|
||||
virtual ModelManager *newModelManager() {return new ModelManager();}
|
||||
virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();}
|
||||
virtual Model *newModel() {return new ModelGl();}
|
||||
|
||||
//text
|
||||
virtual FontManager *newFontManager() {return new FontManager();}
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return new TextRenderer2DGl();}
|
||||
virtual TextRenderer3D *newTextRenderer3D() {return new TextRenderer3DGl();}
|
||||
virtual Font2D *newFont2D() {return new Font2DGl();}
|
||||
virtual Font3D *newFont3D() {return new Font3DGl();}
|
||||
|
||||
//particles
|
||||
virtual ParticleManager *newParticleManager() {return new ParticleManager();}
|
||||
virtual ParticleRenderer *newParticleRenderer() {return new ParticleRendererGl();}
|
||||
|
||||
//shaders
|
||||
virtual ShaderManager *newShaderManager() {return new ShaderManager();}
|
||||
virtual ShaderProgram *newShaderProgram() {return new ShaderProgramGl();}
|
||||
virtual VertexShader *newVertexShader() {return new VertexShaderGl();}
|
||||
virtual FragmentShader *newFragmentShader() {return new FragmentShaderGl();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,31 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_MODELGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_MODELGL_H_
|
||||
|
||||
#include "model.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ModelGl
|
||||
// =====================================================
|
||||
|
||||
class ModelGl: public Model{
|
||||
public:
|
||||
virtual void init(){}
|
||||
virtual void end(){}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,50 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_MODELRENDERERGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_MODELRENDERERGL_H_
|
||||
|
||||
#include "model_renderer.h"
|
||||
#include "model.h"
|
||||
#include "opengl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ModelRendererGl
|
||||
// =====================================================
|
||||
|
||||
class ModelRendererGl: public ModelRenderer{
|
||||
private:
|
||||
bool rendering;
|
||||
bool duplicateTexCoords;
|
||||
int secondaryTexCoordUnit;
|
||||
GLuint lastTexture;
|
||||
|
||||
public:
|
||||
ModelRendererGl();
|
||||
virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, MeshCallback *meshCallback);
|
||||
virtual void end();
|
||||
virtual void render(const Model *model);
|
||||
virtual void renderNormalsOnly(const Model *model);
|
||||
|
||||
void setDuplicateTexCoords(bool duplicateTexCoords) {this->duplicateTexCoords= duplicateTexCoords;}
|
||||
void setSecondaryTexCoordUnit(int secondaryTexCoordUnit) {this->secondaryTexCoordUnit= secondaryTexCoordUnit;}
|
||||
|
||||
private:
|
||||
|
||||
void renderMesh(const Mesh *mesh);
|
||||
void renderMeshNormals(const Mesh *mesh);
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,69 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_OPENGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_OPENGL_H_
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "conversion.h"
|
||||
#include "gl_wrap.h"
|
||||
|
||||
using std::runtime_error;
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
using Util::intToStr;
|
||||
|
||||
// =====================================================
|
||||
// Globals
|
||||
// =====================================================
|
||||
|
||||
bool isGlExtensionSupported(const char *extensionName);
|
||||
bool isGlVersionSupported(int major, int minor, int release);
|
||||
const char *getGlVersion();
|
||||
const char *getGlRenderer();
|
||||
const char *getGlVendor();
|
||||
const char *getGlExtensions();
|
||||
const char *getGlPlatformExtensions();
|
||||
int getGlMaxLights();
|
||||
int getGlMaxTextureSize();
|
||||
int getGlMaxTextureUnits();
|
||||
int getGlModelviewMatrixStackDepth();
|
||||
int getGlProjectionMatrixStackDepth();
|
||||
void checkGlExtension(const char *extensionName);
|
||||
|
||||
void inline _assertGl(const char *file, int line){
|
||||
|
||||
GLenum error= glGetError();
|
||||
|
||||
if(error != GL_NO_ERROR){
|
||||
const char *errorString= reinterpret_cast<const char*>(gluErrorString(error));
|
||||
throw runtime_error("OpenGL error: "+string(errorString)+" at file: "+string(file)+", line "+intToStr(line));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define assertGl() ((void) 0);
|
||||
|
||||
#else
|
||||
|
||||
#define assertGl() _assertGl(__FILE__, __LINE__);
|
||||
|
||||
#endif
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,50 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_PARTICLERENDERERGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_PARTICLERENDERERGL_H_
|
||||
|
||||
#include "particle_renderer.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ParticleRendererGl
|
||||
// =====================================================
|
||||
|
||||
class ParticleRendererGl: public ParticleRenderer{
|
||||
public:
|
||||
static const int bufferSize = 1024;
|
||||
|
||||
private:
|
||||
bool rendering;
|
||||
Vec3f vertexBuffer[bufferSize];
|
||||
Vec2f texCoordBuffer[bufferSize];
|
||||
Vec4f colorBuffer[bufferSize];
|
||||
|
||||
public:
|
||||
//particles
|
||||
ParticleRendererGl();
|
||||
virtual void renderManager(ParticleManager *pm, ModelRenderer *mr);
|
||||
virtual void renderSystem(ParticleSystem *ps);
|
||||
virtual void renderSystemLine(ParticleSystem *ps);
|
||||
virtual void renderSystemLineAlpha(ParticleSystem *ps);
|
||||
virtual void renderSingleModel(AttackParticleSystem *ps, ModelRenderer *mr);
|
||||
|
||||
protected:
|
||||
void renderBufferQuads(int quadCount);
|
||||
void renderBufferLines(int lineCount);
|
||||
void setBlendMode(ParticleSystem::BlendMode blendMode);
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,111 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_SHADERGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_SHADERGL_H_
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "shader.h"
|
||||
#include "opengl.h"
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::pair;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ShaderProgramGl
|
||||
// =====================================================
|
||||
|
||||
class ShaderProgramGl: public ShaderProgram{
|
||||
private:
|
||||
typedef pair<string, int> AttributePair;
|
||||
typedef vector<AttributePair> Attributes;
|
||||
|
||||
private:
|
||||
Attributes attributes;
|
||||
GLhandleARB handle;
|
||||
VertexShader *vertexShader;
|
||||
FragmentShader *fragmentShader;
|
||||
bool inited;
|
||||
|
||||
public:
|
||||
ShaderProgramGl();
|
||||
|
||||
GLhandleARB getHandle() const {return handle;}
|
||||
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
|
||||
virtual void attach(VertexShader *vertexShader, FragmentShader *fragmentShader);
|
||||
virtual bool link(string &messages);
|
||||
virtual void activate();
|
||||
virtual void deactivate();
|
||||
|
||||
virtual void setUniform(const string &name, int value);
|
||||
virtual void setUniform(const string &name, float value);
|
||||
virtual void setUniform(const string &name, const Vec2f &value);
|
||||
virtual void setUniform(const string &name, const Vec3f &value);
|
||||
virtual void setUniform(const string &name, const Vec4f &value);
|
||||
virtual void setUniform(const string &name, const Matrix3f &value);
|
||||
virtual void setUniform(const string &name, const Matrix4f &value);
|
||||
|
||||
void bindAttribute(const string &name, int index);
|
||||
|
||||
private:
|
||||
GLint getLocation(const string &name);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ShaderGl
|
||||
// =====================================================
|
||||
|
||||
class ShaderGl: virtual public Shader{
|
||||
protected:
|
||||
GLhandleARB handle;
|
||||
ShaderSource source;
|
||||
bool inited;
|
||||
|
||||
public:
|
||||
ShaderGl();
|
||||
|
||||
const ShaderSource *getSource() const {return &source;}
|
||||
GLhandleARB getHandle() const {return handle;}
|
||||
|
||||
virtual void load(const string &path);
|
||||
virtual bool compile(string &messages);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class VertexShaderGl
|
||||
// =====================================================
|
||||
|
||||
class VertexShaderGl: public VertexShader, public ShaderGl{
|
||||
public:
|
||||
virtual void init();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class FragmentShaderGl
|
||||
// =====================================================
|
||||
|
||||
class FragmentShaderGl: public FragmentShader, public ShaderGl{
|
||||
public:
|
||||
virtual void init();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,58 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_TEXTRENDERERGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_TEXTRENDERERGL_H_
|
||||
|
||||
#include "text_renderer.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
class Font2DGl;
|
||||
class Font3DGl;
|
||||
|
||||
// =====================================================
|
||||
// class TextRenderer2DGl
|
||||
// =====================================================
|
||||
|
||||
class TextRenderer2DGl: public TextRenderer2D{
|
||||
private:
|
||||
const Font2DGl *font;
|
||||
bool rendering;
|
||||
|
||||
public:
|
||||
TextRenderer2DGl();
|
||||
|
||||
virtual void begin(const Font2D *font);
|
||||
virtual void render(const string &text, int x, int y, bool centered);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class TextRenderer3DGl
|
||||
// =====================================================
|
||||
|
||||
class TextRenderer3DGl: public TextRenderer3D{
|
||||
private:
|
||||
const Font3DGl *font;
|
||||
bool rendering;
|
||||
|
||||
public:
|
||||
TextRenderer3DGl();
|
||||
|
||||
virtual void begin(const Font3D *font);
|
||||
virtual void render(const string &text, float x, float y, float size, bool centered);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,74 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_TEXTUREGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_TEXTUREGL_H_
|
||||
|
||||
#include "texture.h"
|
||||
#include "opengl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class TextureGl
|
||||
// =====================================================
|
||||
|
||||
class TextureGl{
|
||||
protected:
|
||||
GLuint handle;
|
||||
|
||||
public:
|
||||
GLuint getHandle() const {return handle;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture1DGl
|
||||
// =====================================================
|
||||
|
||||
class Texture1DGl: public Texture1D, public TextureGl{
|
||||
public:
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture2DGl
|
||||
// =====================================================
|
||||
|
||||
class Texture2DGl: public Texture2D, public TextureGl{
|
||||
public:
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture3DGl
|
||||
// =====================================================
|
||||
|
||||
class Texture3DGl: public Texture3D, public TextureGl{
|
||||
public:
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class TextureCubeGl
|
||||
// =====================================================
|
||||
|
||||
class TextureCubeGl: public TextureCube, public TextureGl{
|
||||
public:
|
||||
virtual void init(Filter filter, int maxAnisotropy= 1);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,61 +0,0 @@
|
||||
#ifndef _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL2_H_
|
||||
#define _SHARED_GRAPHICS_GL_GRAPHICSFACTORYGL2_H_
|
||||
|
||||
#include "texture_manager.h"
|
||||
#include "model_manager.h"
|
||||
#include "particle_manager.h"
|
||||
#include "font_manager.h"
|
||||
#include "graphics_factory.h"
|
||||
#include "text_renderer_gl.h"
|
||||
#include "model_renderer_gl.h"
|
||||
#include "particle_renderer_gl.h"
|
||||
#include "context_gl.h"
|
||||
#include "model_gl.h"
|
||||
#include "texture_gl.h"
|
||||
#include "font_gl.h"
|
||||
#include "shader_gl.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsFactoryGl
|
||||
// =====================================================
|
||||
|
||||
class GraphicsFactoryGl: public GraphicsFactory{
|
||||
public:
|
||||
//context
|
||||
virtual Context *newContext() {return new ContextGl();}
|
||||
|
||||
//textures
|
||||
virtual TextureManager *newTextureManager() {return new TextureManager();}
|
||||
virtual Texture1D *newTexture1D() {return new Texture1DGl();}
|
||||
virtual Texture2D *newTexture2D() {return new Texture2DGl();}
|
||||
virtual Texture3D *newTexture3D() {return new Texture3DGl();}
|
||||
virtual TextureCube *newTextureCube() {return new TextureCubeGl();}
|
||||
|
||||
//models
|
||||
virtual ModelManager *newModelManager() {return new ModelManager();}
|
||||
virtual ModelRenderer *newModelRenderer() {return new ModelRendererGl();}
|
||||
virtual Model *newModel() {return new ModelGl();}
|
||||
|
||||
//text
|
||||
virtual FontManager *newFontManager() {return new FontManager();}
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return new TextRenderer2DGl();}
|
||||
virtual TextRenderer3D *newTextRenderer3D() {return new TextRenderer3DGl();}
|
||||
virtual Font2D *newFont2D() {return new Font2DGl();}
|
||||
virtual Font3D *newFont3D() {return new Font3DGl();}
|
||||
|
||||
//particles
|
||||
virtual ParticleManager *newParticleManager() {return new ParticleManager();}
|
||||
virtual ParticleRenderer *newParticleRenderer() {return new ParticleRendererGl();}
|
||||
|
||||
//shaders
|
||||
virtual Shadermanager *newShadermanager() {return new ShaderManager();}
|
||||
virtual ShaderProgram *newShaderProgram() {return new ShaderProgramGl();}
|
||||
virtual VertexShader *newVertexShader() {return new VertexShaderGl();}
|
||||
virtual FragmentShader *newFragmentShader() {return new FragmentShaderGl();}
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,110 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GL_SHADERGL_H_
|
||||
#define _SHARED_GRAPHICS_GL_SHADERGL_H_
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "shader.h"
|
||||
#include "opengl.h"
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using std::pair;
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
|
||||
// =====================================================
|
||||
// class ShaderProgramGl
|
||||
// =====================================================
|
||||
|
||||
class ShaderProgramGl: public ShaderProgram{
|
||||
private:
|
||||
typedef pair<string, int> AttributePair;
|
||||
typedef vector<AttributePair> Attributes;
|
||||
|
||||
private:
|
||||
Attributes attributes;
|
||||
GLhandleARB handle;
|
||||
VertexShader *vertexShader;
|
||||
FragmentShader *fragmentShader;
|
||||
bool inited;
|
||||
|
||||
public:
|
||||
ShaderProgramGl();
|
||||
|
||||
GLhandleARB getHandle() const {return handle;}
|
||||
|
||||
virtual void init();
|
||||
virtual void end();
|
||||
|
||||
virtual void attach(VertexShader *vertexShader, FragmentShader *fragmentShader);
|
||||
virtual bool link(string &messages);
|
||||
virtual void activate();
|
||||
|
||||
virtual void setUniform(const string &name, int value);
|
||||
virtual void setUniform(const string &name, float value);
|
||||
virtual void setUniform(const string &name, const Vec2f &value);
|
||||
virtual void setUniform(const string &name, const Vec3f &value);
|
||||
virtual void setUniform(const string &name, const Vec4f &value);
|
||||
virtual void setUniform(const string &name, const Matrix3f &value);
|
||||
virtual void setUniform(const string &name, const Matrix4f &value);
|
||||
|
||||
void bindAttribute(const string &name, int index);
|
||||
|
||||
private:
|
||||
GLint getLocation(const string &name);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ShaderGl
|
||||
// =====================================================
|
||||
|
||||
class ShaderGl: virtual public Shader{
|
||||
protected:
|
||||
GLhandleARB handle;
|
||||
ShaderSource source;
|
||||
bool inited;
|
||||
|
||||
public:
|
||||
ShaderGl();
|
||||
|
||||
const ShaderSource *getSource() const {return &source;}
|
||||
GLhandleARB getHandle() const {return handle;}
|
||||
|
||||
virtual void load(const string &path);
|
||||
virtual bool compile(string &messages);
|
||||
virtual void end();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class VertexShaderGl
|
||||
// =====================================================
|
||||
|
||||
class VertexShaderGl: public VertexShader, public ShaderGl{
|
||||
public:
|
||||
virtual void init();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class FragmentShaderGl
|
||||
// =====================================================
|
||||
|
||||
class FragmentShaderGl: public FragmentShader, public ShaderGl{
|
||||
public:
|
||||
virtual void init();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,88 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GRAPHICSFACTORY_H_
|
||||
#define _SHARED_GRAPHICS_GRAPHICSFACTORY_H_
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class Context;
|
||||
|
||||
class TextureManager;
|
||||
class Texture1D;
|
||||
class Texture2D;
|
||||
class Texture3D;
|
||||
class TextureCube;
|
||||
|
||||
class ModelManager;
|
||||
class ModelRenderer;
|
||||
class Model;
|
||||
|
||||
class FontManager;
|
||||
class TextRenderer2D;
|
||||
class TextRenderer3D;
|
||||
class Font2D;
|
||||
class Font3D;
|
||||
|
||||
class ParticleManager;
|
||||
class ParticleRenderer;
|
||||
|
||||
class ShaderManager;
|
||||
class ShaderProgram;
|
||||
class VertexShader;
|
||||
class FragmentShader;
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsFactory
|
||||
// =====================================================
|
||||
|
||||
class GraphicsFactory{
|
||||
public:
|
||||
virtual ~GraphicsFactory(){}
|
||||
|
||||
//context
|
||||
virtual Context *newContext() {return NULL;}
|
||||
|
||||
//textures
|
||||
virtual TextureManager *newTextureManager() {return NULL;}
|
||||
virtual Texture1D *newTexture1D() {return NULL;}
|
||||
virtual Texture2D *newTexture2D() {return NULL;}
|
||||
virtual Texture3D *newTexture3D() {return NULL;}
|
||||
virtual TextureCube *newTextureCube() {return NULL;}
|
||||
|
||||
//models
|
||||
virtual ModelManager *newModelManager() {return NULL;}
|
||||
virtual ModelRenderer *newModelRenderer() {return NULL;}
|
||||
virtual Model *newModel() {return NULL;}
|
||||
|
||||
//text
|
||||
virtual FontManager *newFontManager() {return NULL;}
|
||||
virtual TextRenderer2D *newTextRenderer2D() {return NULL;}
|
||||
virtual TextRenderer3D *newTextRenderer3D() {return NULL;}
|
||||
virtual Font2D *newFont2D() {return NULL;}
|
||||
virtual Font3D *newFont3D() {return NULL;}
|
||||
|
||||
//particles
|
||||
virtual ParticleManager *newParticleManager() {return NULL;}
|
||||
virtual ParticleRenderer *newParticleRenderer() {return NULL;}
|
||||
|
||||
//shaders
|
||||
virtual ShaderManager *newShaderManager() {return NULL;}
|
||||
virtual ShaderProgram *newShaderProgram() {return NULL;}
|
||||
virtual VertexShader *newVertexShader() {return NULL;}
|
||||
virtual FragmentShader *newFragmentShader() {return NULL;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,52 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_GRAPHICSINTERFACE_H_
|
||||
#define _SHARED_GRAPHICS_GRAPHICSINTERFACE_H_
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class GraphicsFactory;
|
||||
class Context;
|
||||
|
||||
// =====================================================
|
||||
// class GraphicsInterface
|
||||
//
|
||||
/// Interface for the graphic engine
|
||||
// =====================================================
|
||||
|
||||
class GraphicsInterface{
|
||||
private:
|
||||
GraphicsFactory *graphicsFactory;
|
||||
Context *currentContext;
|
||||
|
||||
private:
|
||||
friend class TextureManager;
|
||||
friend class FontManager;
|
||||
|
||||
private:
|
||||
GraphicsInterface();
|
||||
GraphicsInterface(GraphicsInterface &);
|
||||
void operator=(GraphicsInterface &);
|
||||
|
||||
public:
|
||||
static GraphicsInterface &getInstance();
|
||||
|
||||
void setFactory(GraphicsFactory *graphicsFactory);
|
||||
void setCurrentContext(Context *context);
|
||||
|
||||
Context *getCurrentContext() const {return currentContext;}
|
||||
GraphicsFactory *getFactory() const {return graphicsFactory;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,45 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_INTERPOLATION_H_
|
||||
#define _SHARED_GRAPHICS_INTERPOLATION_H_
|
||||
|
||||
#include "vec.h"
|
||||
#include "model.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class InterpolationData
|
||||
// =====================================================
|
||||
|
||||
class InterpolationData{
|
||||
private:
|
||||
const Mesh *mesh;
|
||||
|
||||
Vec3f *vertices;
|
||||
Vec3f *normals;
|
||||
|
||||
public:
|
||||
InterpolationData(const Mesh *mesh);
|
||||
~InterpolationData();
|
||||
|
||||
const Vec3f *getVertices() const {return vertices==NULL? mesh->getVertices(): vertices;}
|
||||
const Vec3f *getNormals() const {return normals==NULL? mesh->getNormals(): normals;}
|
||||
|
||||
void update(float t, bool cycle);
|
||||
void updateVertices(float t, bool cycle);
|
||||
void updateNormals(float t, bool cycle);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,218 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_MATHUTIL_H_
|
||||
#define _SHARED_GRAPHICS_MATHUTIL_H_
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "vec.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
const float pi= 3.1415926f;
|
||||
const float sqrt2= 1.41421356f;
|
||||
const float zero= 1e-6f;
|
||||
const float infinity= 1e6f;
|
||||
|
||||
// =====================================================
|
||||
// class Rect
|
||||
// =====================================================
|
||||
|
||||
// 0 +-+
|
||||
// | |
|
||||
// +-+ 1
|
||||
|
||||
template<typename T>
|
||||
class Rect2{
|
||||
public:
|
||||
Vec2<T> p[2];
|
||||
public:
|
||||
Rect2(){
|
||||
};
|
||||
|
||||
Rect2(const Vec2<T> &p0, const Vec2<T> &p1){
|
||||
this->p[0]= p0;
|
||||
this->p[1]= p1;
|
||||
}
|
||||
|
||||
Rect2(T p0x, T p0y, T p1x, T p1y){
|
||||
p[0].x= p0x;
|
||||
p[0].y= p0y;
|
||||
p[1].x= p1x;
|
||||
p[1].y= p1y;
|
||||
}
|
||||
|
||||
Rect2<T> operator*(T scalar){
|
||||
return Rect2<T>(
|
||||
p[0]*scalar,
|
||||
p[1]*scalar);
|
||||
}
|
||||
|
||||
Rect2<T> operator/(T scalar){
|
||||
return Rect2<T>(
|
||||
p[0]/scalar,
|
||||
p[1]/scalar);
|
||||
}
|
||||
|
||||
bool isInside(const Vec2<T> &p) const{
|
||||
return
|
||||
p.x>=this->p[0].x &&
|
||||
p.y>=this->p[0].y &&
|
||||
p.x<this->p[1].x &&
|
||||
p.y<this->p[1].y;
|
||||
}
|
||||
|
||||
void clamp(T minX, T minY,T maxX, T maxY){
|
||||
for(int i=0; i<2; ++i){
|
||||
if(p[i].x<minX){
|
||||
p[i].x= minX;
|
||||
}
|
||||
if(p[i].y<minY){
|
||||
p[i].y= minY;
|
||||
}
|
||||
if(p[i].x>maxX){
|
||||
p[i].x= maxX;
|
||||
}
|
||||
if(p[i].y>maxY){
|
||||
p[i].y= maxY;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
typedef Rect2<int> Rect2i;
|
||||
typedef Rect2<char> Rect2c;
|
||||
typedef Rect2<float> Rect2f;
|
||||
typedef Rect2<double> Rect2d;
|
||||
|
||||
// =====================================================
|
||||
// class Quad
|
||||
// =====================================================
|
||||
|
||||
// 0 +-+ 2
|
||||
// | |
|
||||
// 1 +-+ 3
|
||||
|
||||
template<typename T>
|
||||
class Quad2{
|
||||
public:
|
||||
Vec2<T> p[4];
|
||||
public:
|
||||
Quad2(){
|
||||
};
|
||||
|
||||
Quad2(const Vec2<T> &p0, const Vec2<T> &p1, const Vec2<T> &p2, const Vec2<T> &p3){
|
||||
this->p[0]= p0;
|
||||
this->p[1]= p1;
|
||||
this->p[2]= p2;
|
||||
this->p[3]= p3;
|
||||
}
|
||||
|
||||
explicit Quad2(const Rect2<T> &rect){
|
||||
this->p[0]= rect.p[0];
|
||||
this->p[1]= Vec2<T>(rect.p[0].x, rect.p[1].y);
|
||||
this->p[2]= rect.p[1];
|
||||
this->p[3]= Vec2<T>(rect.p[1].x, rect.p[0].y);
|
||||
}
|
||||
|
||||
Quad2<T> operator*(T scalar){
|
||||
return Quad2<T>(
|
||||
p[0]*scalar,
|
||||
p[1]*scalar,
|
||||
p[2]*scalar,
|
||||
p[3]*scalar);
|
||||
}
|
||||
|
||||
Quad2<T> operator/(T scalar){
|
||||
return Quad2<T>(
|
||||
p[0]/scalar,
|
||||
p[1]/scalar,
|
||||
p[2]/scalar,
|
||||
p[3]/scalar);
|
||||
}
|
||||
|
||||
Rect2<T> computeBoundingRect() const{
|
||||
return Rect2i(
|
||||
min(p[0].x, p[1].x),
|
||||
min(p[0].y, p[2].y),
|
||||
max(p[2].x, p[3].x),
|
||||
max(p[1].y, p[3].y));
|
||||
}
|
||||
|
||||
bool isInside(const Vec2<T> &pt) const{
|
||||
|
||||
if(!computeBoundingRect().isInside(pt))
|
||||
return false;
|
||||
|
||||
bool left[4];
|
||||
|
||||
left[0]= (pt.y - p[0].y)*(p[1].x - p[0].x) - (pt.x - p[0].x)*(p[1].y - p[0].y) < 0;
|
||||
left[1]= (pt.y - p[1].y)*(p[3].x - p[1].x) - (pt.x - p[1].x)*(p[3].y - p[1].y) < 0;
|
||||
left[2]= (pt.y - p[3].y)*(p[2].x - p[3].x) - (pt.x - p[3].x)*(p[2].y - p[3].y) < 0;
|
||||
left[3]= (pt.y - p[2].y)*(p[0].x - p[2].x) - (pt.x - p[2].x)*(p[0].y - p[2].y) < 0;
|
||||
|
||||
return left[0] && left[1] && left[2] && left[3];
|
||||
}
|
||||
|
||||
void clamp(T minX, T minY, T maxX, T maxY){
|
||||
for(int i=0; i<4; ++i){
|
||||
if(p[i].x<minX){
|
||||
p[i].x= minX;
|
||||
}
|
||||
if(p[i].y<minY){
|
||||
p[i].y= minY;
|
||||
}
|
||||
if(p[i].x>maxX){
|
||||
p[i].x= maxX;
|
||||
}
|
||||
if(p[i].y>maxY){
|
||||
p[i].y= maxY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float area(){
|
||||
Vec2i v0= p[3]-p[0];
|
||||
Vec2i v1= p[1]-p[2];
|
||||
|
||||
return 0.5f * ((v0.x * v1.y) - (v0.y * v1.x));
|
||||
}
|
||||
};
|
||||
|
||||
typedef Quad2<int> Quad2i;
|
||||
typedef Quad2<char> Quad2c;
|
||||
typedef Quad2<float> Quad2f;
|
||||
typedef Quad2<double> Quad2d;
|
||||
|
||||
// =====================================================
|
||||
// Misc
|
||||
// =====================================================
|
||||
|
||||
inline int next2Power(int n){
|
||||
int i;
|
||||
for (i=1; i<n; i*=2);
|
||||
return i;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T degToRad(T deg){
|
||||
return (deg*2*pi)/360;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T radToDeg(T rad){
|
||||
return (rad*360)/(2*pi);
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,162 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_MATRIX_H_
|
||||
#define _SHARED_GRAPHICS_MATRIX_H_
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "vec.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class Matrix3
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class Matrix3{
|
||||
private:
|
||||
T data[9];
|
||||
public:
|
||||
Matrix3(){};
|
||||
|
||||
Matrix3(T *p){
|
||||
for(int i=0; i<9; ++i){
|
||||
data[i]= p[i];
|
||||
}
|
||||
}
|
||||
|
||||
T *ptr(){
|
||||
return data;
|
||||
}
|
||||
|
||||
const T *ptr() const{
|
||||
return data;
|
||||
}
|
||||
|
||||
T &operator[](int i){
|
||||
return data[i];
|
||||
}
|
||||
|
||||
T &operator()(int i, int j){
|
||||
return data[i*3+j];
|
||||
}
|
||||
|
||||
Vec3<T> operator * (const Vec3<T> &v) const{
|
||||
Vec3<T> rv;
|
||||
|
||||
return Vec3f(
|
||||
data[0]*v.x + data[1]*v.y + data[2]*v.z,
|
||||
data[3]*v.x + data[4]*v.y + data[5]*v.z,
|
||||
data[6]*v.x + data[7]*v.y + data[8]*v.z);
|
||||
}
|
||||
|
||||
Matrix3<T> operator * (const Matrix3<T> &m) const{
|
||||
Matrix3<T> rm;
|
||||
|
||||
for(int i=0; i<3; ++i){
|
||||
for(int j=0; j<3; ++j){
|
||||
T acum= 0.0f;
|
||||
for(int k=0; k<3; ++k){
|
||||
acum+= data[i*3+k]*m[k*3+j];
|
||||
}
|
||||
rm[i*3+j]= acum;
|
||||
}
|
||||
}
|
||||
return rm;
|
||||
}
|
||||
|
||||
void traspose(){
|
||||
for(int i=0; i<3; ++i){
|
||||
for(int j=0; j<3; ++j){
|
||||
T tmp= data[j*3+i];
|
||||
data[j*3+i]= data[i*3+j];
|
||||
data[i*3+j]= tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
typedef Matrix3<float> Matrix3f;
|
||||
typedef Matrix3<double> Matrix3d;
|
||||
|
||||
// =====================================================
|
||||
// class Matrix4
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class Matrix4{
|
||||
private:
|
||||
T data[16];
|
||||
public:
|
||||
Matrix4(){};
|
||||
|
||||
Matrix4(T *p){
|
||||
for(int i=0; i<16; ++i){
|
||||
data[i]= p[i];
|
||||
}
|
||||
}
|
||||
|
||||
T *ptr(){
|
||||
return data;
|
||||
}
|
||||
|
||||
const T *ptr() const{
|
||||
return data;
|
||||
}
|
||||
|
||||
T &operator[](int i){
|
||||
return data[i];
|
||||
}
|
||||
|
||||
const T &operator[](int i) const{
|
||||
return data[i];
|
||||
}
|
||||
|
||||
T &operator()(int i, int j){
|
||||
return data[i*4+j];
|
||||
}
|
||||
|
||||
Vec4<T> operator * (const Vec4<T> &v) const{
|
||||
Vec4<T> rv;
|
||||
|
||||
return Vec4f(
|
||||
data[0]*v.x + data[1]*v.y + data[2]*v.z + data[3]*v.w,
|
||||
data[4]*v.x + data[5]*v.y + data[6]*v.z + data[7]*v.w,
|
||||
data[8]*v.x + data[9]*v.y + data[10]*v.z + data[11]*v.w,
|
||||
data[12]*v.x + data[13]*v.y + data[14]*v.z + data[15]*v.w);
|
||||
}
|
||||
|
||||
Matrix4<T> operator * (const Matrix4<T> &m) const{
|
||||
Matrix4<T> rm;
|
||||
|
||||
for(int i=0; i<4; ++i){
|
||||
for(int j=0; j<4; ++j){
|
||||
T acum= 0.0f;
|
||||
for(int k=0; k<4; ++k){
|
||||
acum+= data[i*4+k]*m[k*4+j];
|
||||
}
|
||||
rm[i*4+j]= acum;
|
||||
}
|
||||
}
|
||||
return rm;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef Matrix4<float> Matrix4f;
|
||||
typedef Matrix4<double> Matrix4d;
|
||||
|
||||
|
||||
}} //enmd namespace
|
||||
|
||||
#endif
|
@@ -1,172 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_MODEL_H_
|
||||
#define _SHARED_GRAPHICS_MODEL_H_
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "types.h"
|
||||
#include "pixmap.h"
|
||||
#include "texture_manager.h"
|
||||
#include "texture.h"
|
||||
#include "model_header.h"
|
||||
|
||||
using std::string;
|
||||
using std::map;
|
||||
using std::pair;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class Model;
|
||||
class Mesh;
|
||||
class ShadowVolumeData;
|
||||
class InterpolationData;
|
||||
class TextureManager;
|
||||
|
||||
// =====================================================
|
||||
// class Mesh
|
||||
//
|
||||
// Part of a 3D model
|
||||
// =====================================================
|
||||
|
||||
class Mesh{
|
||||
private:
|
||||
//mesh data
|
||||
Texture2D *textures[meshTextureCount];
|
||||
string texturePaths[meshTextureCount];
|
||||
|
||||
//vertex data counts
|
||||
uint32 frameCount;
|
||||
uint32 vertexCount;
|
||||
uint32 indexCount;
|
||||
|
||||
//vertex data
|
||||
Vec3f *vertices;
|
||||
Vec3f *normals;
|
||||
Vec2f *texCoords;
|
||||
Vec3f *tangents;
|
||||
uint32 *indices;
|
||||
|
||||
//material data
|
||||
Vec3f diffuseColor;
|
||||
Vec3f specularColor;
|
||||
float specularPower;
|
||||
float opacity;
|
||||
|
||||
//properties
|
||||
bool twoSided;
|
||||
bool customColor;
|
||||
|
||||
InterpolationData *interpolationData;
|
||||
|
||||
public:
|
||||
//init & end
|
||||
Mesh();
|
||||
~Mesh();
|
||||
void init();
|
||||
void end();
|
||||
|
||||
//maps
|
||||
const Texture2D *getTexture(int i) const {return textures[i];}
|
||||
|
||||
//counts
|
||||
uint32 getFrameCount() const {return frameCount;}
|
||||
uint32 getVertexCount() const {return vertexCount;}
|
||||
uint32 getIndexCount() const {return indexCount;}
|
||||
uint32 getTriangleCount() const;
|
||||
|
||||
//data
|
||||
const Vec3f *getVertices() const {return vertices;}
|
||||
const Vec3f *getNormals() const {return normals;}
|
||||
const Vec2f *getTexCoords() const {return texCoords;}
|
||||
const Vec3f *getTangents() const {return tangents;}
|
||||
const uint32 *getIndices() const {return indices;}
|
||||
|
||||
//material
|
||||
const Vec3f &getDiffuseColor() const {return diffuseColor;}
|
||||
const Vec3f &getSpecularColor() const {return specularColor;}
|
||||
float getSpecularPower() const {return specularPower;}
|
||||
float getOpacity() const {return opacity;}
|
||||
|
||||
//properties
|
||||
bool getTwoSided() const {return twoSided;}
|
||||
bool getCustomTexture() const {return customColor;}
|
||||
|
||||
//external data
|
||||
const InterpolationData *getInterpolationData() const {return interpolationData;}
|
||||
|
||||
//interpolation
|
||||
void buildInterpolationData();
|
||||
void updateInterpolationData(float t, bool cycle) const;
|
||||
void updateInterpolationVertices(float t, bool cycle) const;
|
||||
|
||||
//load
|
||||
void loadV2(const string &dir, FILE *f, TextureManager *textureManager);
|
||||
void loadV3(const string &dir, FILE *f, TextureManager *textureManager);
|
||||
void load(const string &dir, FILE *f, TextureManager *textureManager);
|
||||
void save(const string &dir, FILE *f);
|
||||
|
||||
private:
|
||||
void computeTangents();
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Model
|
||||
//
|
||||
// 3D Model, than can be loaded from a g3d file
|
||||
// =====================================================
|
||||
|
||||
class Model{
|
||||
private:
|
||||
TextureManager *textureManager;
|
||||
|
||||
private:
|
||||
uint8 fileVersion;
|
||||
uint32 meshCount;
|
||||
Mesh *meshes;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Model();
|
||||
virtual ~Model();
|
||||
virtual void init()= 0;
|
||||
virtual void end()= 0;
|
||||
|
||||
//data
|
||||
void updateInterpolationData(float t, bool cycle) const;
|
||||
void updateInterpolationVertices(float t, bool cycle) const;
|
||||
void buildShadowVolumeData() const;
|
||||
|
||||
//get
|
||||
uint8 getFileVersion() const {return fileVersion;}
|
||||
uint32 getMeshCount() const {return meshCount;}
|
||||
const Mesh *getMesh(int i) const {return &meshes[i];}
|
||||
|
||||
uint32 getTriangleCount() const;
|
||||
uint32 getVertexCount() const;
|
||||
|
||||
//io
|
||||
void load(const string &path);
|
||||
void save(const string &path);
|
||||
void loadG3d(const string &path);
|
||||
void saveS3d(const string &path);
|
||||
|
||||
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
|
||||
|
||||
private:
|
||||
void buildInterpolationData() const;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,118 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICTYPES_MODELHEADER_H_
|
||||
#define _SHARED_GRAPHICTYPES_MODELHEADER_H_
|
||||
|
||||
#include "types.h"
|
||||
|
||||
using Shared::Platform::uint8;
|
||||
using Shared::Platform::uint16;
|
||||
using Shared::Platform::uint32;
|
||||
using Shared::Platform::float32;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
struct FileHeader{
|
||||
uint8 id[3];
|
||||
uint8 version;
|
||||
};
|
||||
|
||||
//version 4
|
||||
|
||||
struct ModelHeader{
|
||||
uint16 meshCount;
|
||||
uint8 type;
|
||||
};
|
||||
|
||||
enum ModelType{
|
||||
mtMorphMesh
|
||||
};
|
||||
|
||||
enum MeshPropertyFlag{
|
||||
mpfCustomColor= 1,
|
||||
mpfTwoSided= 2
|
||||
};
|
||||
|
||||
enum MeshTexture{
|
||||
mtDiffuse,
|
||||
mtSpecular,
|
||||
mtNormal,
|
||||
mtReflection,
|
||||
mtColorMask,
|
||||
|
||||
meshTextureCount
|
||||
};
|
||||
|
||||
const int meshTextureChannelCount[]= {-1, 1, 3, 1, 1};
|
||||
|
||||
const uint32 meshNameSize= 64;
|
||||
const uint32 mapPathSize= 64;
|
||||
|
||||
struct MeshHeader{
|
||||
uint8 name[meshNameSize];
|
||||
uint32 frameCount;
|
||||
uint32 vertexCount;
|
||||
uint32 indexCount;
|
||||
float32 diffuseColor[3];
|
||||
float32 specularColor[3];
|
||||
float32 specularPower;
|
||||
float32 opacity;
|
||||
uint32 properties;
|
||||
uint32 textures;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
//version 3
|
||||
|
||||
//front faces are clockwise faces
|
||||
struct ModelHeaderV3{
|
||||
uint32 meshCount;
|
||||
};
|
||||
|
||||
enum MeshPropertyV3{
|
||||
mp3NoTexture= 1,
|
||||
mp3TwoSided= 2,
|
||||
mp3CustomColor= 4
|
||||
};
|
||||
|
||||
struct MeshHeaderV3{
|
||||
uint32 vertexFrameCount;
|
||||
uint32 normalFrameCount;
|
||||
uint32 texCoordFrameCount;
|
||||
uint32 colorFrameCount;
|
||||
uint32 pointCount;
|
||||
uint32 indexCount;
|
||||
uint32 properties;
|
||||
uint8 texName[64];
|
||||
};
|
||||
|
||||
//version 2
|
||||
|
||||
struct MeshHeaderV2{
|
||||
uint32 vertexFrameCount;
|
||||
uint32 normalFrameCount;
|
||||
uint32 texCoordFrameCount;
|
||||
uint32 colorFrameCount;
|
||||
uint32 pointCount;
|
||||
uint32 indexCount;
|
||||
uint8 hasTexture;
|
||||
uint8 primitive;
|
||||
uint8 cullFace;
|
||||
uint8 texName[64];
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,51 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_MODELMANAGER_H_
|
||||
#define _SHARED_GRAPHICS_MODELMANAGER_H_
|
||||
|
||||
#include "model.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class TextureManager;
|
||||
|
||||
// =====================================================
|
||||
// class ModelManager
|
||||
// =====================================================
|
||||
|
||||
class ModelManager{
|
||||
protected:
|
||||
typedef vector<Model*> ModelContainer;
|
||||
|
||||
protected:
|
||||
ModelContainer models;
|
||||
TextureManager *textureManager;
|
||||
|
||||
public:
|
||||
ModelManager();
|
||||
virtual ~ModelManager();
|
||||
|
||||
Model *newModel();
|
||||
|
||||
void init();
|
||||
void end();
|
||||
|
||||
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,58 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_MODELRENDERER_H_
|
||||
#define _SHARED_GRAPHICS_MODELRENDERER_H_
|
||||
|
||||
#include "model.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class Texture;
|
||||
|
||||
// =====================================================
|
||||
// class MeshCallback
|
||||
//
|
||||
/// This gets called before rendering mesh
|
||||
// =====================================================
|
||||
|
||||
class MeshCallback{
|
||||
public:
|
||||
virtual ~MeshCallback(){};
|
||||
virtual void execute(const Mesh *mesh)= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ModelRenderer
|
||||
// =====================================================
|
||||
|
||||
class ModelRenderer{
|
||||
protected:
|
||||
bool renderNormals;
|
||||
bool renderTextures;
|
||||
bool renderColors;
|
||||
MeshCallback *meshCallback;
|
||||
|
||||
public:
|
||||
ModelRenderer() {meshCallback= NULL;}
|
||||
|
||||
virtual ~ModelRenderer(){};
|
||||
|
||||
virtual void begin(bool renderNormals, bool renderTextures, bool renderColors, MeshCallback *meshCallback= NULL)=0;
|
||||
virtual void end()=0;
|
||||
virtual void render(const Model *model)=0;
|
||||
virtual void renderNormalsOnly(const Model *model)=0;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,435 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_PARTICLE_H_
|
||||
#define _SHARED_GRAPHICS_PARTICLE_H_
|
||||
|
||||
#include <list>
|
||||
#include <cassert>
|
||||
|
||||
#include "vec.h"
|
||||
#include "pixmap.h"
|
||||
#include "texture_manager.h"
|
||||
#include "random.h"
|
||||
|
||||
using std::list;
|
||||
using Shared::Util::Random;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class ParticleSystem;
|
||||
class FireParticleSystem;
|
||||
class UnitParticleSystem;
|
||||
class RainParticleSystem;
|
||||
class SnowParticleSystem;
|
||||
class ProjectileParticleSystem;
|
||||
class SplashParticleSystem;
|
||||
class ParticleRenderer;
|
||||
class ModelRenderer;
|
||||
class Model;
|
||||
|
||||
// =====================================================
|
||||
// class Particle
|
||||
// =====================================================
|
||||
|
||||
class Particle{
|
||||
public:
|
||||
//attributes
|
||||
Vec3f pos;
|
||||
Vec3f lastPos;
|
||||
Vec3f speed;
|
||||
Vec3f accel;
|
||||
Vec4f color;
|
||||
float size;
|
||||
int energy;
|
||||
|
||||
public:
|
||||
//get
|
||||
Vec3f getPos() const {return pos;}
|
||||
Vec3f getLastPos() const {return lastPos;}
|
||||
Vec3f getSpeed() const {return speed;}
|
||||
Vec3f getAccel() const {return accel;}
|
||||
Vec4f getColor() const {return color;}
|
||||
float getSize() const {return size;}
|
||||
int getEnergy() const {return energy;}
|
||||
};
|
||||
|
||||
class ParticleSystem;
|
||||
|
||||
// =====================================================
|
||||
// class ParticleObserver
|
||||
// =====================================================
|
||||
|
||||
class ParticleObserver{
|
||||
public:
|
||||
virtual ~ParticleObserver(){};
|
||||
virtual void update(ParticleSystem *particleSystem)= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class ParticleSystem{
|
||||
public:
|
||||
enum BlendMode{
|
||||
bmOne,
|
||||
bmOneMinusAlpha
|
||||
};
|
||||
|
||||
protected:
|
||||
enum State{
|
||||
sPause, // No updates
|
||||
sPlay,
|
||||
sFade // No new particles
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
Particle *particles;
|
||||
Random random;
|
||||
|
||||
BlendMode blendMode;
|
||||
State state;
|
||||
bool active;
|
||||
bool visible;
|
||||
int aliveParticleCount;
|
||||
int particleCount;
|
||||
|
||||
|
||||
Texture *texture;
|
||||
Vec3f pos;
|
||||
Vec4f color;
|
||||
Vec4f colorNoEnergy;
|
||||
int emissionRate;
|
||||
int maxParticleEnergy;
|
||||
int varParticleEnergy;
|
||||
float particleSize;
|
||||
float speed;
|
||||
Vec3f factionColor;
|
||||
bool teamcolorNoEnergy;
|
||||
bool teamcolorEnergy;
|
||||
|
||||
ParticleObserver *particleObserver;
|
||||
|
||||
public:
|
||||
//conmstructor and destructor
|
||||
ParticleSystem(int particleCount);
|
||||
virtual ~ParticleSystem();
|
||||
|
||||
//public
|
||||
virtual void update();
|
||||
virtual void render(ParticleRenderer *pr, ModelRenderer *mr);
|
||||
|
||||
//get
|
||||
State getState() const {return state;}
|
||||
BlendMode getBlendMode() const {return blendMode;}
|
||||
Texture *getTexture() const {return texture;}
|
||||
Vec3f getPos() const {return pos;}
|
||||
Particle *getParticle(int i) {return &particles[i];}
|
||||
const Particle *getParticle(int i) const {return &particles[i];}
|
||||
int getAliveParticleCount() const {return aliveParticleCount;}
|
||||
bool getActive() const {return active;}
|
||||
bool getVisible() const {return visible;}
|
||||
|
||||
//set
|
||||
void setState(State state);
|
||||
void setTexture(Texture *texture);
|
||||
void setPos(Vec3f pos);
|
||||
void setColor(Vec4f color);
|
||||
void setColorNoEnergy(Vec4f color);
|
||||
void setEmissionRate(int emissionRate);
|
||||
void setMaxParticleEnergy(int maxParticleEnergy);
|
||||
void setVarParticleEnergy(int varParticleEnergy);
|
||||
void setParticleSize(float particleSize);
|
||||
void setSpeed(float speed);
|
||||
void setActive(bool active);
|
||||
void setObserver(ParticleObserver *particleObserver);
|
||||
void setVisible(bool visible);
|
||||
void setBlendMode(BlendMode blendMode) {this->blendMode= blendMode;}
|
||||
void setTeamcolorNoEnergy(bool teamcolorNoEnergy) {this->teamcolorNoEnergy= teamcolorNoEnergy;}
|
||||
void setTeamcolorEnergy(bool teamcolorEnergy) {this->teamcolorEnergy= teamcolorEnergy;}
|
||||
virtual void setFactionColor(Vec3f factionColor);
|
||||
|
||||
static BlendMode strToBlendMode(const string &str);
|
||||
//misc
|
||||
void fade();
|
||||
int isEmpty() const;
|
||||
|
||||
protected:
|
||||
//protected
|
||||
Particle *createParticle();
|
||||
void killParticle(Particle *p);
|
||||
|
||||
//virtual protected
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual void updateParticle(Particle *p);
|
||||
virtual bool deathTest(Particle *p);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class FireParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class FireParticleSystem: public ParticleSystem{
|
||||
private:
|
||||
float radius;
|
||||
Vec3f windSpeed;
|
||||
|
||||
public:
|
||||
FireParticleSystem(int particleCount= 2000);
|
||||
|
||||
//virtual
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual void updateParticle(Particle *p);
|
||||
|
||||
//set params
|
||||
void setRadius(float radius);
|
||||
void setWind(float windAngle, float windSpeed);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class UnitParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class UnitParticleSystem: public ParticleSystem{
|
||||
private:
|
||||
float radius;
|
||||
Vec3f windSpeed;
|
||||
Vec3f cRotation;
|
||||
Vec3f fixedAddition;
|
||||
Vec3f oldPosition;
|
||||
public:
|
||||
enum Primitive{
|
||||
pQuad,
|
||||
pLine,
|
||||
pLineAlpha
|
||||
};
|
||||
bool relative;
|
||||
bool fixed;
|
||||
Model *model;
|
||||
Primitive primitive;
|
||||
Vec3f offset;
|
||||
Vec3f direction;
|
||||
float sizeNoEnergy;
|
||||
float gravity;
|
||||
float rotation;
|
||||
|
||||
public:
|
||||
UnitParticleSystem(int particleCount= 2000);
|
||||
|
||||
//virtual
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual void updateParticle(Particle *p);
|
||||
virtual void update();
|
||||
virtual void render(ParticleRenderer *pr, ModelRenderer *mr);
|
||||
|
||||
//set params
|
||||
void setRadius(float radius);
|
||||
void setWind(float windAngle, float windSpeed);
|
||||
|
||||
void setOffset(Vec3f offset) {this->offset= offset;}
|
||||
void setDirection(Vec3f direction) {this->direction= direction;}
|
||||
void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;}
|
||||
void setGravity(float gravity) {this->gravity= gravity;}
|
||||
void setRotation(float rotation) {this->rotation= rotation;}
|
||||
void setRelative(bool relative) {this->relative= relative;}
|
||||
void setFixed(bool fixed) {this->fixed= fixed;}
|
||||
void setPrimitive(Primitive primitive) {this->primitive= primitive;}
|
||||
|
||||
static Primitive strToPrimitive(const string &str);
|
||||
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class RainParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class RainParticleSystem: public ParticleSystem{
|
||||
private:
|
||||
Vec3f windSpeed;
|
||||
float radius;
|
||||
|
||||
public:
|
||||
RainParticleSystem(int particleCount= 4000);
|
||||
|
||||
virtual void render(ParticleRenderer *pr, ModelRenderer *mr);
|
||||
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual bool deathTest(Particle *p);
|
||||
|
||||
void setRadius(float radius);
|
||||
void setWind(float windAngle, float windSpeed);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class SnowParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class SnowParticleSystem: public ParticleSystem{
|
||||
private:
|
||||
Vec3f windSpeed;
|
||||
float radius;
|
||||
|
||||
public:
|
||||
SnowParticleSystem(int particleCount= 4000);
|
||||
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual bool deathTest(Particle *p);
|
||||
|
||||
void setRadius(float radius);
|
||||
void setWind(float windAngle, float windSpeed);
|
||||
};
|
||||
|
||||
// ===========================================================================
|
||||
// AttackParticleSystem
|
||||
//
|
||||
/// Base class for Projectiles and Splashes
|
||||
// ===========================================================================
|
||||
|
||||
class AttackParticleSystem: public ParticleSystem{
|
||||
public:
|
||||
enum Primitive{
|
||||
pQuad,
|
||||
pLine,
|
||||
pLineAlpha
|
||||
};
|
||||
|
||||
protected:
|
||||
Model *model;
|
||||
Primitive primitive;
|
||||
Vec3f offset;
|
||||
float sizeNoEnergy;
|
||||
float gravity;
|
||||
|
||||
Vec3f direction;
|
||||
|
||||
public:
|
||||
AttackParticleSystem(int particleCount);
|
||||
|
||||
virtual void render(ParticleRenderer *pr, ModelRenderer *mr);
|
||||
|
||||
Model *getModel() const {return model;}
|
||||
Vec3f getDirection() const {return direction;}
|
||||
|
||||
void setModel(Model *model) {this->model= model;}
|
||||
void setOffset(Vec3f offset) {this->offset= offset;}
|
||||
void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;}
|
||||
void setGravity(float gravity) {this->gravity= gravity;}
|
||||
void setPrimitive(Primitive primitive) {this->primitive= primitive;}
|
||||
|
||||
static Primitive strToPrimitive(const string &str);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ProjectileParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class ProjectileParticleSystem: public AttackParticleSystem{
|
||||
public:
|
||||
friend class SplashParticleSystem;
|
||||
|
||||
enum Trajectory{
|
||||
tLinear,
|
||||
tParabolic,
|
||||
tSpiral
|
||||
};
|
||||
|
||||
private:
|
||||
SplashParticleSystem *nextParticleSystem;
|
||||
|
||||
Vec3f lastPos;
|
||||
Vec3f startPos;
|
||||
Vec3f endPos;
|
||||
Vec3f flatPos;
|
||||
|
||||
Vec3f xVector;
|
||||
Vec3f yVector;
|
||||
Vec3f zVector;
|
||||
|
||||
Trajectory trajectory;
|
||||
float trajectorySpeed;
|
||||
|
||||
//parabolic
|
||||
float trajectoryScale;
|
||||
float trajectoryFrequency;
|
||||
|
||||
public:
|
||||
ProjectileParticleSystem(int particleCount= 1000);
|
||||
virtual ~ProjectileParticleSystem();
|
||||
|
||||
void link(SplashParticleSystem *particleSystem);
|
||||
|
||||
virtual void update();
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual void updateParticle(Particle *p);
|
||||
|
||||
void setTrajectory(Trajectory trajectory) {this->trajectory= trajectory;}
|
||||
void setTrajectorySpeed(float trajectorySpeed) {this->trajectorySpeed= trajectorySpeed;}
|
||||
void setTrajectoryScale(float trajectoryScale) {this->trajectoryScale= trajectoryScale;}
|
||||
void setTrajectoryFrequency(float trajectoryFrequency) {this->trajectoryFrequency= trajectoryFrequency;}
|
||||
void setPath(Vec3f startPos, Vec3f endPos);
|
||||
|
||||
static Trajectory strToTrajectory(const string &str);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class SplashParticleSystem
|
||||
// =====================================================
|
||||
|
||||
class SplashParticleSystem: public AttackParticleSystem{
|
||||
public:
|
||||
friend class ProjectileParticleSystem;
|
||||
|
||||
private:
|
||||
ProjectileParticleSystem *prevParticleSystem;
|
||||
|
||||
int emissionRateFade;
|
||||
float verticalSpreadA;
|
||||
float verticalSpreadB;
|
||||
float horizontalSpreadA;
|
||||
float horizontalSpreadB;
|
||||
|
||||
public:
|
||||
SplashParticleSystem(int particleCount= 1000);
|
||||
virtual ~SplashParticleSystem();
|
||||
|
||||
virtual void update();
|
||||
virtual void initParticle(Particle *p, int particleIndex);
|
||||
virtual void updateParticle(Particle *p);
|
||||
|
||||
void setEmissionRateFade(int emissionRateFade) {this->emissionRateFade= emissionRateFade;}
|
||||
void setVerticalSpreadA(float verticalSpreadA) {this->verticalSpreadA= verticalSpreadA;}
|
||||
void setVerticalSpreadB(float verticalSpreadB) {this->verticalSpreadB= verticalSpreadB;}
|
||||
void setHorizontalSpreadA(float horizontalSpreadA) {this->horizontalSpreadA= horizontalSpreadA;}
|
||||
void setHorizontalSpreadB(float horizontalSpreadB) {this->horizontalSpreadB= horizontalSpreadB;}
|
||||
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ParticleManager
|
||||
// =====================================================
|
||||
|
||||
class ParticleManager{
|
||||
private:
|
||||
list<ParticleSystem*> particleSystems;
|
||||
|
||||
public:
|
||||
~ParticleManager();
|
||||
void update();
|
||||
void render(ParticleRenderer *pr, ModelRenderer *mr) const;
|
||||
void manage(ParticleSystem *ps);
|
||||
void end();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,38 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_PARTICLERENDERER_H_
|
||||
#define _SHARED_GRAPHICS_PARTICLERENDERER_H_
|
||||
|
||||
#include "particle.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class ModelRenderer;
|
||||
|
||||
// =====================================================
|
||||
// class ParticleRenderer
|
||||
// =====================================================
|
||||
|
||||
class ParticleRenderer{
|
||||
public:
|
||||
//particles
|
||||
virtual ~ParticleRenderer(){};
|
||||
virtual void renderManager(ParticleManager *pm, ModelRenderer *mr)=0;
|
||||
virtual void renderSystem(ParticleSystem *ps)=0;
|
||||
virtual void renderSystemLine(ParticleSystem *ps)=0;
|
||||
virtual void renderSystemLineAlpha(ParticleSystem *ps)=0;
|
||||
virtual void renderSingleModel(AttackParticleSystem *ps, ModelRenderer *mr)=0;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,267 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_PIXMAP_H_
|
||||
#define _SHARED_GRAPHICS_PIXMAP_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "vec.h"
|
||||
#include "types.h"
|
||||
|
||||
using std::string;
|
||||
using Shared::Platform::int8;
|
||||
using Shared::Platform::uint8;
|
||||
using Shared::Platform::int16;
|
||||
using Shared::Platform::uint16;
|
||||
using Shared::Platform::int32;
|
||||
using Shared::Platform::uint32;
|
||||
using Shared::Platform::float32;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class PixmapIo
|
||||
// =====================================================
|
||||
|
||||
class PixmapIo{
|
||||
protected:
|
||||
int w;
|
||||
int h;
|
||||
int components;
|
||||
|
||||
public:
|
||||
virtual ~PixmapIo(){}
|
||||
|
||||
int getW() const {return w;}
|
||||
int getH() const {return h;}
|
||||
int getComponents() const {return components;}
|
||||
|
||||
virtual void openRead(const string &path)= 0;
|
||||
virtual void read(uint8 *pixels)= 0;
|
||||
virtual void read(uint8 *pixels, int components)= 0;
|
||||
|
||||
virtual void openWrite(const string &path, int w, int h, int components)= 0;
|
||||
virtual void write(uint8 *pixels)= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class PixmapIoTga
|
||||
// =====================================================
|
||||
|
||||
class PixmapIoTga: public PixmapIo{
|
||||
private:
|
||||
FILE *file;
|
||||
|
||||
public:
|
||||
PixmapIoTga();
|
||||
virtual ~PixmapIoTga();
|
||||
|
||||
virtual void openRead(const string &path);
|
||||
virtual void read(uint8 *pixels);
|
||||
virtual void read(uint8 *pixels, int components);
|
||||
|
||||
virtual void openWrite(const string &path, int w, int h, int components);
|
||||
virtual void write(uint8 *pixels);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class PixmapIoBmp
|
||||
// =====================================================
|
||||
|
||||
class PixmapIoBmp: public PixmapIo{
|
||||
private:
|
||||
FILE *file;
|
||||
|
||||
public:
|
||||
PixmapIoBmp();
|
||||
virtual ~PixmapIoBmp();
|
||||
|
||||
virtual void openRead(const string &path);
|
||||
virtual void read(uint8 *pixels);
|
||||
virtual void read(uint8 *pixels, int components);
|
||||
|
||||
virtual void openWrite(const string &path, int w, int h, int components);
|
||||
virtual void write(uint8 *pixels);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Pixmap1D
|
||||
// =====================================================
|
||||
|
||||
class Pixmap1D{
|
||||
protected:
|
||||
int w;
|
||||
int components;
|
||||
uint8 *pixels;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Pixmap1D();
|
||||
Pixmap1D(int components);
|
||||
Pixmap1D(int w, int components);
|
||||
void init(int components);
|
||||
void init(int w, int components);
|
||||
~Pixmap1D();
|
||||
|
||||
//load & save
|
||||
void load(const string &path);
|
||||
void loadTga(const string &path);
|
||||
void loadBmp(const string &path);
|
||||
|
||||
//get
|
||||
int getW() const {return w;}
|
||||
int getComponents() const {return components;}
|
||||
uint8 *getPixels() const {return pixels;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Pixmap2D
|
||||
// =====================================================
|
||||
|
||||
class Pixmap2D{
|
||||
protected:
|
||||
int h;
|
||||
int w;
|
||||
int components;
|
||||
uint8 *pixels;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Pixmap2D();
|
||||
Pixmap2D(int components);
|
||||
Pixmap2D(int w, int h, int components);
|
||||
void init(int components);
|
||||
void init(int w, int h, int components);
|
||||
~Pixmap2D();
|
||||
|
||||
//load & save
|
||||
void load(const string &path);
|
||||
void loadTga(const string &path);
|
||||
void loadBmp(const string &path);
|
||||
void save(const string &path);
|
||||
void saveBmp(const string &path);
|
||||
void saveTga(const string &path);
|
||||
|
||||
//get
|
||||
int getW() const {return w;}
|
||||
int getH() const {return h;}
|
||||
int getComponents() const {return components;}
|
||||
uint8 *getPixels() const {return pixels;}
|
||||
|
||||
//get data
|
||||
void getPixel(int x, int y, uint8 *value) const;
|
||||
void getPixel(int x, int y, float32 *value) const;
|
||||
void getComponent(int x, int y, int component, uint8 &value) const;
|
||||
void getComponent(int x, int y, int component, float32 &value) const;
|
||||
|
||||
//vector get
|
||||
Vec4f getPixel4f(int x, int y) const;
|
||||
Vec3f getPixel3f(int x, int y) const;
|
||||
float getPixelf(int x, int y) const;
|
||||
float getComponentf(int x, int y, int component) const;
|
||||
|
||||
//set data
|
||||
void setPixel(int x, int y, const uint8 *value);
|
||||
void setPixel(int x, int y, const float32 *value);
|
||||
void setComponent(int x, int y, int component, uint8 value);
|
||||
void setComponent(int x, int y, int component, float32 value);
|
||||
|
||||
//vector set
|
||||
void setPixel(int x, int y, const Vec3f &p);
|
||||
void setPixel(int x, int y, const Vec4f &p);
|
||||
void setPixel(int x, int y, float p);
|
||||
|
||||
//mass set
|
||||
void setPixels(const uint8 *value);
|
||||
void setPixels(const float32 *value);
|
||||
void setComponents(int component, uint8 value);
|
||||
void setComponents(int component, float32 value);
|
||||
|
||||
//operations
|
||||
void splat(const Pixmap2D *leftUp, const Pixmap2D *rightUp, const Pixmap2D *leftDown, const Pixmap2D *rightDown);
|
||||
void lerp(float t, const Pixmap2D *pixmap1, const Pixmap2D *pixmap2);
|
||||
void copy(const Pixmap2D *sourcePixmap);
|
||||
void subCopy(int x, int y, const Pixmap2D *sourcePixmap);
|
||||
|
||||
private:
|
||||
bool doDimensionsAgree(const Pixmap2D *pixmap);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Pixmap3D
|
||||
// =====================================================
|
||||
|
||||
class Pixmap3D{
|
||||
protected:
|
||||
int h;
|
||||
int w;
|
||||
int d;
|
||||
int components;
|
||||
uint8 *pixels;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Pixmap3D();
|
||||
Pixmap3D(int w, int h, int d, int components);
|
||||
Pixmap3D(int d, int components);
|
||||
void init(int w, int h, int d, int components);
|
||||
void init(int d, int components);
|
||||
~Pixmap3D();
|
||||
|
||||
//load & save
|
||||
void loadSlice(const string &path, int slice);
|
||||
void loadSliceBmp(const string &path, int slice);
|
||||
void loadSliceTga(const string &path, int slice);
|
||||
|
||||
//get
|
||||
int getW() const {return w;}
|
||||
int getH() const {return h;}
|
||||
int getD() const {return d;}
|
||||
int getComponents() const {return components;}
|
||||
uint8 *getPixels() const {return pixels;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class PixmapCube
|
||||
// =====================================================
|
||||
|
||||
class PixmapCube{
|
||||
public:
|
||||
enum Face{
|
||||
fPositiveX,
|
||||
fNegativeX,
|
||||
fPositiveY,
|
||||
fNegativeY,
|
||||
fPositiveZ,
|
||||
fNegativeZ
|
||||
};
|
||||
|
||||
protected:
|
||||
Pixmap2D faces[6];
|
||||
|
||||
public:
|
||||
//init
|
||||
void init(int w, int h, int components);
|
||||
|
||||
//load & save
|
||||
void loadFace(const string &path, int face);
|
||||
void loadFaceBmp(const string &path, int face);
|
||||
void loadFaceTga(const string &path, int face);
|
||||
|
||||
//get
|
||||
Pixmap2D *getFace(int face) {return &faces[face];}
|
||||
const Pixmap2D *getFace(int face) const {return &faces[face];}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,97 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_QUATERNION_H_
|
||||
#define _SHARED_GRAPHICS_QUATERNION_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "vec.h"
|
||||
#include "matrix.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class AxisAngle
|
||||
// =====================================================
|
||||
|
||||
class AxisAngle{
|
||||
public:
|
||||
Vec3f axis;
|
||||
float angle;
|
||||
|
||||
AxisAngle(){};
|
||||
AxisAngle(const Vec3f &axis, float angle);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class EulerAngles
|
||||
// =====================================================
|
||||
|
||||
class EulerAngles{
|
||||
public:
|
||||
float x, y, z;
|
||||
|
||||
EulerAngles(){};
|
||||
EulerAngles(float x, float y, float z);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Quaternion
|
||||
// =====================================================
|
||||
|
||||
class Quaternion{
|
||||
private:
|
||||
float w;
|
||||
Vec3f v;
|
||||
|
||||
public:
|
||||
Quaternion();
|
||||
Quaternion(float w, const Vec3f &v);
|
||||
Quaternion(const EulerAngles &eulerAngles);
|
||||
Quaternion(const AxisAngle &axisAngle);
|
||||
|
||||
//initializers
|
||||
void setMultIdentity();
|
||||
void setAddIdentity();
|
||||
void setAxisAngle(const AxisAngle &axisAngle);
|
||||
void setEuler(const EulerAngles &eulerAngles);
|
||||
|
||||
//unary operators
|
||||
float length();
|
||||
Quaternion conjugate();
|
||||
void normalize();
|
||||
|
||||
//binary operators
|
||||
Quaternion operator + (const Quaternion &q) const;
|
||||
Quaternion operator * (const Quaternion &q) const;
|
||||
void operator += (const Quaternion &q);
|
||||
void operator *= (const Quaternion &q);
|
||||
|
||||
//ternary operators
|
||||
Quaternion lerp(float t, const Quaternion &q) const;
|
||||
|
||||
//conversions
|
||||
Matrix3f toMatrix3() const;
|
||||
Matrix4f toMatrix4() const;
|
||||
AxisAngle toAxisAngle() const;
|
||||
|
||||
//local axis
|
||||
Vec3f getLocalXAxis() const;
|
||||
Vec3f getLocalYAxis() const;
|
||||
Vec3f getLocalZAxis() const;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,86 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_SHADER_H_
|
||||
#define _SHARED_GRAPHICS_SHADER_H_
|
||||
|
||||
#include "vec.h"
|
||||
#include "matrix.h"
|
||||
#include "texture.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class ShaderProgram
|
||||
// =====================================================
|
||||
|
||||
class VertexShader;
|
||||
class FragmentShader;
|
||||
|
||||
class ShaderProgram{
|
||||
public:
|
||||
virtual ~ShaderProgram(){}
|
||||
virtual void init()= 0;
|
||||
virtual void end()= 0;
|
||||
|
||||
virtual void attach(VertexShader *vs, FragmentShader *fs)= 0;
|
||||
virtual bool link(string &messages)= 0;
|
||||
virtual void activate()= 0;
|
||||
virtual void deactivate()= 0;
|
||||
|
||||
virtual void setUniform(const string &name, int value)= 0;
|
||||
virtual void setUniform(const string &name, float value)= 0;
|
||||
virtual void setUniform(const string &name, const Vec2f &value)= 0;
|
||||
virtual void setUniform(const string &name, const Vec3f &value)= 0;
|
||||
virtual void setUniform(const string &name, const Vec4f &value)= 0;
|
||||
virtual void setUniform(const string &name, const Matrix3f &value)= 0;
|
||||
virtual void setUniform(const string &name, const Matrix4f &value)= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Shader
|
||||
// =====================================================
|
||||
|
||||
class Shader{
|
||||
public:
|
||||
virtual ~Shader(){}
|
||||
virtual void init()= 0;
|
||||
virtual void end()= 0;
|
||||
|
||||
virtual void load(const string &path)= 0;
|
||||
virtual bool compile(string &messages)= 0;
|
||||
};
|
||||
|
||||
class VertexShader: virtual public Shader{
|
||||
};
|
||||
|
||||
class FragmentShader: virtual public Shader{
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ShaderSource
|
||||
// =====================================================
|
||||
|
||||
class ShaderSource{
|
||||
private:
|
||||
string pathInfo;
|
||||
string code;
|
||||
|
||||
public:
|
||||
const string &getPathInfo() const {return pathInfo;}
|
||||
const string &getCode() const {return code;}
|
||||
|
||||
void load(const string &path);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,53 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_SHADERMANAGER_H_
|
||||
#define _SHARED_GRAPHICS_SHADERMANAGER_H_
|
||||
|
||||
#include "shader.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class ShaderManager
|
||||
// =====================================================
|
||||
|
||||
class ShaderManager{
|
||||
protected:
|
||||
typedef vector<ShaderProgram*> ShaderProgramContainer;
|
||||
typedef vector<Shader*> ShaderContainer;
|
||||
|
||||
protected:
|
||||
ShaderProgramContainer shaderPrograms;
|
||||
ShaderContainer shaders;
|
||||
string logString;
|
||||
|
||||
public:
|
||||
ShaderManager(){}
|
||||
virtual ~ShaderManager();
|
||||
|
||||
ShaderProgram *newShaderProgram();
|
||||
VertexShader *newVertexShader();
|
||||
FragmentShader *newFragmentShader();
|
||||
|
||||
void init();
|
||||
void end();
|
||||
|
||||
const string &getLogString() const {return logString;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,52 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_TEXTRENDERER_H_
|
||||
#define _SHARED_GRAPHICS_TEXTRENDERER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "vec.h"
|
||||
#include "font.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class TextRenderer2D
|
||||
// =====================================================
|
||||
|
||||
class TextRenderer2D{
|
||||
public:
|
||||
virtual ~TextRenderer2D(){};
|
||||
|
||||
virtual void begin(const Font2D *font)= 0;
|
||||
virtual void render(const string &text, int x, int y, bool centered= false)= 0;
|
||||
virtual void end()= 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class TextRenderer3D
|
||||
// =====================================================
|
||||
|
||||
class TextRenderer3D{
|
||||
public:
|
||||
virtual ~TextRenderer3D(){};
|
||||
|
||||
virtual void begin(const Font3D *font)= 0;
|
||||
virtual void render(const string &text, float x, float y, float size, bool centered= false)= 0;
|
||||
virtual void end()= 0;
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,144 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_TEXTURE_H_
|
||||
#define _SHARED_GRAPHICS_TEXTURE_H_
|
||||
|
||||
#include "types.h"
|
||||
#include "pixmap.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
using Shared::Platform::uint8;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
class TextureParams;
|
||||
|
||||
// =====================================================
|
||||
// class Texture
|
||||
// =====================================================
|
||||
|
||||
class Texture{
|
||||
public:
|
||||
static const int defaultSize;
|
||||
|
||||
enum WrapMode{
|
||||
wmRepeat,
|
||||
wmClamp,
|
||||
wmClampToEdge
|
||||
};
|
||||
|
||||
enum Filter{
|
||||
fBilinear,
|
||||
fTrilinear
|
||||
};
|
||||
|
||||
enum Format{
|
||||
fAuto,
|
||||
fAlpha,
|
||||
fLuminance,
|
||||
fRgb,
|
||||
fRgba
|
||||
};
|
||||
|
||||
protected:
|
||||
string path;
|
||||
bool mipmap;
|
||||
WrapMode wrapMode;
|
||||
bool pixmapInit;
|
||||
Format format;
|
||||
|
||||
bool inited;
|
||||
|
||||
public:
|
||||
Texture();
|
||||
virtual ~Texture(){};
|
||||
|
||||
bool getMipmap() const {return mipmap;}
|
||||
WrapMode getWrapMode() const {return wrapMode;}
|
||||
bool getPixmapInit() const {return pixmapInit;}
|
||||
Format getFormat() const {return format;}
|
||||
const string getPath() const {return path;}
|
||||
|
||||
void setMipmap(bool mipmap) {this->mipmap= mipmap;}
|
||||
void setWrapMode(WrapMode wrapMode) {this->wrapMode= wrapMode;}
|
||||
void setPixmapInit(bool pixmapInit) {this->pixmapInit= pixmapInit;}
|
||||
void setFormat(Format format) {this->format= format;}
|
||||
|
||||
virtual void init(Filter filter= fBilinear, int maxAnisotropy= 1)=0;
|
||||
virtual void end()=0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture1D
|
||||
// =====================================================
|
||||
|
||||
class Texture1D: public Texture{
|
||||
protected:
|
||||
Pixmap1D pixmap;
|
||||
|
||||
public:
|
||||
void load(const string &path);
|
||||
|
||||
Pixmap1D *getPixmap() {return &pixmap;}
|
||||
const Pixmap1D *getPixmap() const {return &pixmap;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture2D
|
||||
// =====================================================
|
||||
|
||||
class Texture2D: public Texture{
|
||||
protected:
|
||||
Pixmap2D pixmap;
|
||||
|
||||
public:
|
||||
void load(const string &path);
|
||||
|
||||
Pixmap2D *getPixmap() {return &pixmap;}
|
||||
const Pixmap2D *getPixmap() const {return &pixmap;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Texture3D
|
||||
// =====================================================
|
||||
|
||||
class Texture3D: public Texture{
|
||||
protected:
|
||||
Pixmap3D pixmap;
|
||||
|
||||
public:
|
||||
void loadSlice(const string &path, int slice);
|
||||
|
||||
Pixmap3D *getPixmap() {return &pixmap;}
|
||||
const Pixmap3D *getPixmap() const {return &pixmap;}
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class TextureCube
|
||||
// =====================================================
|
||||
|
||||
class TextureCube: public Texture{
|
||||
protected:
|
||||
PixmapCube pixmap;
|
||||
|
||||
public:
|
||||
void loadFace(const string &path, int face);
|
||||
|
||||
PixmapCube *getPixmap() {return &pixmap;}
|
||||
const PixmapCube *getPixmap() const {return &pixmap;}
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,57 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_TEXTUREMANAGER_H_
|
||||
#define _SHARED_GRAPHICS_TEXTUREMANAGER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
using std::vector;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
// =====================================================
|
||||
// class TextureManager
|
||||
// =====================================================
|
||||
|
||||
//manages textures, creation on request and deletion on destruction
|
||||
class TextureManager{
|
||||
protected:
|
||||
typedef vector<Texture*> TextureContainer;
|
||||
|
||||
protected:
|
||||
TextureContainer textures;
|
||||
|
||||
Texture::Filter textureFilter;
|
||||
int maxAnisotropy;
|
||||
|
||||
public:
|
||||
TextureManager();
|
||||
~TextureManager();
|
||||
void init();
|
||||
void end();
|
||||
|
||||
void setFilter(Texture::Filter textureFilter);
|
||||
void setMaxAnisotropy(int maxAnisotropy);
|
||||
|
||||
Texture *getTexture(const string &path);
|
||||
Texture1D *newTexture1D();
|
||||
Texture2D *newTexture2D();
|
||||
Texture3D *newTexture3D();
|
||||
TextureCube *newTextureCube();
|
||||
};
|
||||
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
@@ -1,443 +0,0 @@
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
|
||||
#ifndef _SHARED_GRAPHICS_VEC_H_
|
||||
#define _SHARED_GRAPHICS_VEC_H_
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
template<typename T> class Vec2;
|
||||
template<typename T> class Vec3;
|
||||
template<typename T> class Vec4;
|
||||
|
||||
// =====================================================
|
||||
// class Vec2
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class Vec2{
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
public:
|
||||
Vec2(){
|
||||
};
|
||||
|
||||
explicit Vec2(T *p){
|
||||
this->x= p[0];
|
||||
this->y= p[1];
|
||||
}
|
||||
|
||||
explicit Vec2(T xy){
|
||||
this->x= xy;
|
||||
this->y= xy;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
explicit Vec2(const Vec2<S> &v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
}
|
||||
|
||||
Vec2(T x, T y){
|
||||
this->x= x;
|
||||
this->y= y;
|
||||
}
|
||||
|
||||
T *ptr(){
|
||||
return reinterpret_cast<T*>(this);
|
||||
}
|
||||
|
||||
const T *ptr() const{
|
||||
return reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
bool operator ==(const Vec2<T> &v) const{
|
||||
return x==v.x && y==v.y;
|
||||
}
|
||||
|
||||
bool operator !=(const Vec2<T> &v) const{
|
||||
return x!=v.x || y!=v.y;
|
||||
}
|
||||
|
||||
Vec2<T> operator +(const Vec2<T> &v) const{
|
||||
return Vec2(x+v.x, y+v.y);
|
||||
}
|
||||
|
||||
Vec2<T> operator -(const Vec2<T> &v) const{
|
||||
return Vec2(x-v.x, y-v.y);
|
||||
}
|
||||
|
||||
Vec2<T> operator -() const{
|
||||
return Vec2(-x, -y);
|
||||
}
|
||||
|
||||
Vec2<T> operator *(const Vec2<T> &v) const{
|
||||
return Vec2(x*v.x, y*v.y);
|
||||
}
|
||||
|
||||
Vec2<T> operator *(T s) const{
|
||||
return Vec2(x*s, y*s);
|
||||
}
|
||||
|
||||
Vec2<T> operator /(const Vec2<T> &v) const{
|
||||
return Vec2(x/v.x, y/v.y);
|
||||
}
|
||||
|
||||
Vec2<T> operator /(T s) const{
|
||||
return Vec2(x/s, y/s);
|
||||
}
|
||||
|
||||
Vec2<T> operator +=(const Vec2<T> &v){
|
||||
x+=v.x;
|
||||
y+=v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> operator -=(const Vec2<T> &v){
|
||||
x-=v.x;
|
||||
y-=v.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec2<T> lerp(T t, const Vec2<T> &v) const{
|
||||
return *this + (v - *this)*t;
|
||||
}
|
||||
|
||||
T dot(const Vec2<T> &v) const{
|
||||
return x*v.x+y*v.y;
|
||||
}
|
||||
|
||||
float dist(const Vec2<T> &v) const{
|
||||
return Vec2<T>(v-*this).length();
|
||||
}
|
||||
|
||||
float length() const{
|
||||
return static_cast<float>(sqrt(static_cast<float>(x*x + y*y)));
|
||||
}
|
||||
|
||||
void normalize(){
|
||||
T m= length();
|
||||
x/= m;
|
||||
y/= m;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vec2<int> Vec2i;
|
||||
typedef Vec2<bool> Vec2b;
|
||||
typedef Vec2<char> Vec2c;
|
||||
typedef Vec2<float> Vec2f;
|
||||
typedef Vec2<double> Vec2d;
|
||||
|
||||
// =====================================================
|
||||
// class Vec3
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class Vec3{
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
|
||||
public:
|
||||
Vec3(){
|
||||
};
|
||||
|
||||
explicit Vec3(T *p){
|
||||
this->x= p[0];
|
||||
this->y= p[1];
|
||||
this->z= p[2];
|
||||
}
|
||||
|
||||
explicit Vec3(T xyz){
|
||||
this->x= xyz;
|
||||
this->y= xyz;
|
||||
this->z= xyz;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
explicit Vec3(const Vec3<S> &v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
}
|
||||
|
||||
Vec3(T x, T y, T z){
|
||||
this->x= x;
|
||||
this->y= y;
|
||||
this->z= z;
|
||||
}
|
||||
|
||||
explicit Vec3(Vec4<T> v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
}
|
||||
|
||||
T *ptr(){
|
||||
return reinterpret_cast<T*>(this);
|
||||
}
|
||||
|
||||
const T *ptr() const{
|
||||
return reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
bool operator ==(const Vec3<T> &v) const{
|
||||
return x==v.x && y==v.y && z==v.z;
|
||||
}
|
||||
|
||||
bool operator !=(const Vec3<T> &v) const{
|
||||
return x!=v.x || y!=v.y || z!=v.z;
|
||||
}
|
||||
|
||||
Vec3<T> operator +(const Vec3<T> &v) const{
|
||||
return Vec3(x+v.x, y+v.y, z+v.z);
|
||||
}
|
||||
|
||||
Vec3<T> operator -(const Vec3<T> &v) const{
|
||||
return Vec3(x-v.x, y-v.y, z-v.z);
|
||||
}
|
||||
|
||||
Vec3<T> operator -() const{
|
||||
return Vec3(-x, -y, -z);
|
||||
}
|
||||
|
||||
Vec3<T> operator *(const Vec3<T> &v) const{
|
||||
return Vec3(x*v.x, y*v.y, z*v.z);
|
||||
}
|
||||
|
||||
Vec3<T> operator *(T s) const{
|
||||
return Vec3(x*s, y*s, z*s);
|
||||
}
|
||||
|
||||
Vec3<T> operator /(const Vec3<T> &v) const{
|
||||
return Vec3(x/v.x, y/v.y, z/v.z);
|
||||
}
|
||||
|
||||
Vec3<T> operator /(T s) const{
|
||||
return Vec3(x/s, y/s, z/s);
|
||||
}
|
||||
|
||||
Vec3<T> operator +=(const Vec3<T> &v){
|
||||
x+=v.x;
|
||||
y+=v.y;
|
||||
z+=v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> operator -=(const Vec3<T> &v){
|
||||
x-=v.x;
|
||||
y-=v.y;
|
||||
z-=v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3<T> lerp(T t, const Vec3<T> &v) const{
|
||||
return *this + (v - *this) * t;
|
||||
}
|
||||
|
||||
T dot(const Vec3<T> &v) const{
|
||||
return x*v.x + y*v.y + z*v.z;
|
||||
}
|
||||
|
||||
float dist(const Vec3<T> &v) const{
|
||||
return Vec3<T>(v-*this).length();
|
||||
}
|
||||
|
||||
float length() const{
|
||||
return static_cast<float>(sqrt(x*x + y*y + z*z));
|
||||
}
|
||||
|
||||
void normalize(){
|
||||
T m= length();
|
||||
x/= m;
|
||||
y/= m;
|
||||
z/= m;
|
||||
}
|
||||
|
||||
Vec3<T> getNormalized() const{
|
||||
T m= length();
|
||||
return Vec3<T>(x/m, y/m, z/m);
|
||||
}
|
||||
|
||||
Vec3<T> cross(const Vec3<T> &v) const{
|
||||
return Vec3<T>(
|
||||
this->y*v.z-this->z*v.y,
|
||||
this->z*v.x-this->x*v.z,
|
||||
this->x*v.y-this->y*v.x);
|
||||
}
|
||||
|
||||
Vec3<T> normal(const Vec3<T> &p1, const Vec3<T> &p2) const{
|
||||
Vec3<T> rv;
|
||||
rv= (p2-*this).cross(p1-*this);
|
||||
rv.normalize();
|
||||
return rv;
|
||||
}
|
||||
|
||||
Vec3<T> normal(const Vec3<T> &p1, const Vec3<T> &p2, const Vec3<T> &p3, const Vec3<T> &p4) const{
|
||||
Vec3<T> rv;
|
||||
|
||||
rv= this->normal(p1, p2);
|
||||
rv= rv + this->normal(p2, p3);
|
||||
rv= rv + this->normal(p3, p4);
|
||||
rv= rv + this->normal(p4, p1);
|
||||
rv.normalize();
|
||||
return rv;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef Vec3<int> Vec3i;
|
||||
typedef Vec3<bool> Vec3b;
|
||||
typedef Vec3<char> Vec3c;
|
||||
typedef Vec3<float> Vec3f;
|
||||
typedef Vec3<double> Vec3d;
|
||||
|
||||
// =====================================================
|
||||
// class Vec4
|
||||
// =====================================================
|
||||
|
||||
template<typename T>
|
||||
class Vec4{
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
T w;
|
||||
public:
|
||||
Vec4(){
|
||||
};
|
||||
|
||||
explicit Vec4(T *p){
|
||||
this->x= p[0];
|
||||
this->y= p[1];
|
||||
this->z= p[2];
|
||||
this->w= p[3];
|
||||
}
|
||||
|
||||
explicit Vec4(T xyzw){
|
||||
this->x= xyzw;
|
||||
this->y= xyzw;
|
||||
this->z= xyzw;
|
||||
this->w= xyzw;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
explicit Vec4(const Vec4<S> &v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
this->w= v.w;
|
||||
}
|
||||
|
||||
Vec4(T x, T y, T z, T w){
|
||||
this->x= x;
|
||||
this->y= y;
|
||||
this->z= z;
|
||||
this->w= w;
|
||||
}
|
||||
|
||||
Vec4(Vec3<T> v, T w){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
this->w= w;
|
||||
}
|
||||
|
||||
explicit Vec4(Vec3<T> v){
|
||||
this->x= v.x;
|
||||
this->y= v.y;
|
||||
this->z= v.z;
|
||||
this->w= 1;
|
||||
}
|
||||
|
||||
T *ptr(){
|
||||
return reinterpret_cast<T*>(this);
|
||||
}
|
||||
|
||||
const T *ptr() const{
|
||||
return reinterpret_cast<const T*>(this);
|
||||
}
|
||||
|
||||
bool operator ==(const Vec4<T> &v) const{
|
||||
return x==v.x && y==v.y && z==v.z && w==v.w;
|
||||
}
|
||||
|
||||
bool operator !=(const Vec4<T> &v) const{
|
||||
return x!=v.x || y!=v.y || z!=v.z || w!=v.w;
|
||||
}
|
||||
|
||||
Vec4<T> operator +(const Vec4<T> &v) const{
|
||||
return Vec4(x+v.x, y+v.y, z+v.z, w+v.w);
|
||||
}
|
||||
|
||||
Vec4<T> operator -(const Vec4<T> &v) const{
|
||||
return Vec4(x-v.x, y-v.y, z-v.z, w-v.w);
|
||||
}
|
||||
|
||||
Vec4<T> operator -() const{
|
||||
return Vec4(-x, -y, -z, -w);
|
||||
}
|
||||
|
||||
Vec4<T> operator *(const Vec4<T> &v) const{
|
||||
return Vec4(x*v.x, y*v.y, z*v.z, w*v.w);
|
||||
}
|
||||
|
||||
Vec4<T> operator *(T s) const{
|
||||
return Vec4(x*s, y*s, z*s, w*s);
|
||||
}
|
||||
|
||||
Vec4<T> operator /(const Vec4<T> &v) const{
|
||||
return Vec4(x/v.x, y/v.y, z/v.z, w/v.w);
|
||||
}
|
||||
|
||||
Vec4<T> operator /(T s) const{
|
||||
return Vec4(x/s, y/s, z/s, w/s);
|
||||
}
|
||||
|
||||
Vec4<T> operator +=(const Vec4<T> &v){
|
||||
x+=v.x;
|
||||
y+=v.y;
|
||||
z+=v.z;
|
||||
w+=w.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> operator -=(const Vec4<T> &v){
|
||||
x-=v.x;
|
||||
y-=v.y;
|
||||
z-=v.z;
|
||||
w-=w.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec4<T> lerp(T t, const Vec4<T> &v) const{
|
||||
return *this + (v - *this) *t;
|
||||
}
|
||||
|
||||
T dot(const Vec4<T> &v) const{
|
||||
return x*v.x + y*v.y + z*v.z + w*v.w;
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vec4<int> Vec4i;
|
||||
typedef Vec4<bool> Vec4b;
|
||||
typedef Vec4<char> Vec4c;
|
||||
typedef Vec4<float> Vec4f;
|
||||
typedef Vec4<double> Vec4d;
|
||||
|
||||
}} //enmd namespace
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user