mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-06-13 22:04:36 -06:00
SurfaceCtrl: all public part of each class have been move at the begining of class
git-svn-id: svn://ultimatepp.org/upp/trunk@15114 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
6131ba1c9b
commit
620e301ad3
10 changed files with 247 additions and 266 deletions
|
|
@ -6,32 +6,6 @@
|
|||
namespace Upp{
|
||||
|
||||
class BoundingBox {
|
||||
private:
|
||||
bool loaded = false;
|
||||
|
||||
glm::vec3 min;
|
||||
glm::vec3 max;
|
||||
|
||||
GLuint BoundingBoxVAO = 0;
|
||||
GLuint BoundingBoxVBO = 0;
|
||||
|
||||
void loadBoundingBox(){
|
||||
Vector<float> BoundingBoxVertices = GetVertices();
|
||||
|
||||
if(BoundingBoxVAO > 0) glDeleteVertexArrays(1,&BoundingBoxVAO);
|
||||
if(BoundingBoxVBO > 0) glDeleteBuffers(1,&BoundingBoxVBO);
|
||||
|
||||
glGenVertexArrays(1,&BoundingBoxVAO);
|
||||
glGenBuffers(1,&BoundingBoxVBO);
|
||||
|
||||
glBindVertexArray(BoundingBoxVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER,BoundingBoxVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER,BoundingBoxVertices.GetCount() * sizeof(float),&(BoundingBoxVertices[0]),GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float),(void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public:
|
||||
BoundingBox(){
|
||||
loaded = false;
|
||||
|
|
@ -43,12 +17,12 @@ class BoundingBox {
|
|||
BoundingBox(glm::vec3 min_, glm::vec3 max_){
|
||||
min = min_;
|
||||
max = max_;
|
||||
loadBoundingBox();
|
||||
LoadBoundingBox();
|
||||
}
|
||||
BoundingBox(float minX,float minY, float minZ, float maxX,float maxY,float maxZ){
|
||||
min = glm::vec3(minX,minY,minZ);
|
||||
max = glm::vec3(maxX,maxY,maxZ);
|
||||
loadBoundingBox();
|
||||
LoadBoundingBox();
|
||||
}
|
||||
|
||||
BoundingBox& operator=(const BoundingBox& copy){
|
||||
|
|
@ -60,7 +34,7 @@ class BoundingBox {
|
|||
return *this;
|
||||
}
|
||||
|
||||
BoundingBox& ReloadBoundingBox(){loadBoundingBox();return *this;}
|
||||
BoundingBox& ReloadBoundingBox(){LoadBoundingBox();return *this;}
|
||||
BoundingBox& UnloadBoundingBox(){glDeleteVertexArrays(1,&BoundingBoxVAO);glDeleteBuffers(1,&BoundingBoxVBO);loaded =false;return *this;}
|
||||
|
||||
Vector<float> GetVertices(){
|
||||
|
|
@ -94,13 +68,13 @@ class BoundingBox {
|
|||
BoundingBox& SetBoundingBox(glm::vec3 min_, glm::vec3 max_){
|
||||
min = min_;
|
||||
max = max_;
|
||||
loadBoundingBox();
|
||||
LoadBoundingBox();
|
||||
return *this;
|
||||
}
|
||||
BoundingBox& SetBoundingBox(float minX,float minY, float minZ, float maxX,float maxY,float maxZ){
|
||||
min = glm::vec3(minX,minY,minZ);
|
||||
max = glm::vec3(maxX,maxY,maxZ);
|
||||
loadBoundingBox();
|
||||
LoadBoundingBox();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -175,6 +149,31 @@ class BoundingBox {
|
|||
}
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
bool loaded = false;
|
||||
|
||||
glm::vec3 min;
|
||||
glm::vec3 max;
|
||||
|
||||
GLuint BoundingBoxVAO = 0;
|
||||
GLuint BoundingBoxVBO = 0;
|
||||
|
||||
void LoadBoundingBox(){
|
||||
Vector<float> BoundingBoxVertices = GetVertices();
|
||||
|
||||
if(BoundingBoxVAO > 0) glDeleteVertexArrays(1,&BoundingBoxVAO);
|
||||
if(BoundingBoxVBO > 0) glDeleteBuffers(1,&BoundingBoxVBO);
|
||||
|
||||
glGenVertexArrays(1,&BoundingBoxVAO);
|
||||
glGenBuffers(1,&BoundingBoxVBO);
|
||||
|
||||
glBindVertexArray(BoundingBoxVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER,BoundingBoxVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER,BoundingBoxVertices.GetCount() * sizeof(float),&(BoundingBoxVertices[0]),GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float),(void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
loaded = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
#define SHADER(version, shader) "#version " #version "\n" STRINGIFY(shader)
|
||||
|
||||
namespace Upp{
|
||||
enum class Camera_Movement {FORWARD,BACKWARD,LEFT,RIGHT};// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
|
||||
enum class CameraMovementDirection {FORWARD,BACKWARD,LEFT,RIGHT};// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
|
||||
enum class CameraType{PERSPECTIVE = 0 ,ORTHOGRAPHIC = 1};//,CT_FRUSTUM = 2}; //Type of camera rendering
|
||||
enum class DrawType { TRIANGLE, QUAD };
|
||||
enum class TexturesMaterial { WATER, STONE, BRICK, METAL, WOOD};
|
||||
|
|
|
|||
|
|
@ -4,13 +4,7 @@
|
|||
#include "Object3D.h"
|
||||
|
||||
namespace Upp{
|
||||
class MagicCamera : public UOGL_Camera{
|
||||
private:
|
||||
bool OnObject = false;
|
||||
glm::vec3 focus;
|
||||
|
||||
glm::vec3 UnProject2(float winX, float winY,float winZ)const noexcept;
|
||||
bool PickFocus(float x, float y);
|
||||
class MagicCamera : public UOGL_Camera{
|
||||
public:
|
||||
MagicCamera(){}
|
||||
MagicCamera& Init(){transform.SetPosition(0, 0, 20); focus = glm::vec3(0.0f,0.0f,0.0f); return *this;}
|
||||
|
|
@ -33,9 +27,15 @@ namespace Upp{
|
|||
MagicCamera& MouseWheelMouvement(float xoffset,float yoffset)noexcept; //Rotate arround axis
|
||||
MagicCamera& ProcessMouseScroll(float zdelta, float multiplier = 1.0f)noexcept; //Zoom or move via MouseWheel depending on OnObject Boolean
|
||||
|
||||
|
||||
MagicCamera& ProcessKeyboardMouvement(Camera_Movement direction){return *this;} //Handler for keyboard, Useless in this kind of camera
|
||||
MagicCamera& ProcessKeyboardMouvement(CameraMovementDirection direction){return *this;} //Handler for keyboard, Useless in this kind of camera
|
||||
bool ProcessKeyBoard(unsigned long Key,int count)noexcept{return true;} //Handler for keyboard, Useless in this kind of camera
|
||||
|
||||
private:
|
||||
bool OnObject = false;
|
||||
glm::vec3 focus;
|
||||
|
||||
glm::vec3 UnProject2(float winX, float winY,float winZ)const noexcept;
|
||||
bool PickFocus(float x, float y);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,6 @@
|
|||
namespace Upp{
|
||||
|
||||
struct Material{
|
||||
private:
|
||||
glm::vec3 Diffuse = glm::vec3(0.30f, 0.30f, 0.30f);
|
||||
glm::vec3 Specular = glm::vec3(0.1f, 0.1f, 0.1f);
|
||||
float Shininess = 12.0f;
|
||||
bool update = true;
|
||||
public:
|
||||
Material(){}
|
||||
Material(const glm::vec3& diffuse_, const glm::vec3& speculare_, float shininess_){Diffuse = diffuse_;Specular = speculare_;Shininess = shininess_;}
|
||||
|
|
@ -23,32 +18,15 @@ struct Material{
|
|||
|
||||
bool ShouldBeUpdated()const noexcept{return update;}
|
||||
void HaveBeenUpdated()noexcept{update = false;}
|
||||
private:
|
||||
glm::vec3 Diffuse = glm::vec3(0.30f, 0.30f, 0.30f);
|
||||
glm::vec3 Specular = glm::vec3(0.1f, 0.1f, 0.1f);
|
||||
float Shininess = 12.0f;
|
||||
bool update = true;
|
||||
};
|
||||
|
||||
//Mesh contain vertex and how it's read
|
||||
class Mesh : public Moveable<Mesh>{
|
||||
private:
|
||||
String name =""; //Possible name of Mesh
|
||||
bool loaded = false;
|
||||
|
||||
Vector<GLfloat> vertices;
|
||||
Vector<GLfloat> normals;
|
||||
Vector<GLfloat> colors;
|
||||
Vector<GLfloat> texCoords;
|
||||
|
||||
GLuint vao = 0;
|
||||
GLuint verticesVBO = 0;
|
||||
GLuint normalsVBO = 0;
|
||||
GLuint colorsVBO = 0;
|
||||
GLuint texCoordsVBO = 0;
|
||||
|
||||
Material material; //The material object is a representation of material property of the object (it change how light affect it)
|
||||
|
||||
unsigned int textureIndice = 0;
|
||||
|
||||
/**
|
||||
All stuff about texture
|
||||
**/
|
||||
public:
|
||||
Mesh(){}
|
||||
Mesh(Mesh&& obj){*this = pick(obj);}
|
||||
|
|
@ -193,11 +171,25 @@ class Mesh : public Moveable<Mesh>{
|
|||
}
|
||||
loaded = false;
|
||||
}
|
||||
|
||||
private:
|
||||
String name =""; //Possible name of Mesh
|
||||
bool loaded = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Vector<GLfloat> vertices;
|
||||
Vector<GLfloat> normals;
|
||||
Vector<GLfloat> colors;
|
||||
Vector<GLfloat> texCoords;
|
||||
|
||||
GLuint vao = 0;
|
||||
GLuint verticesVBO = 0;
|
||||
GLuint normalsVBO = 0;
|
||||
GLuint colorsVBO = 0;
|
||||
GLuint texCoordsVBO = 0;
|
||||
|
||||
Material material; //The material object is a representation of material property of the object (it change how light affect it)
|
||||
|
||||
unsigned int textureIndice = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -323,7 +323,7 @@ bool Object3D::InitMaterials(const aiScene* pScene, const String& Filename){
|
|||
if (pMaterial->GetTexture(aiTextureType_NONE, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS)
|
||||
LOG("None texture : " + AppendFileName(GetFileFolder(Filename), String(Path.data)));
|
||||
}else{
|
||||
for(int e = 0; e < pMaterial->mNumProperties; e++){
|
||||
/*for(int e = 0; e < pMaterial->mNumProperties; e++){
|
||||
aiMaterialProperty* aiMp = pMaterial->mProperties[e];
|
||||
LOG("Property number " + AsString(e) +" :");
|
||||
LOG("mKey : " + String((*aiMp).mKey.data));
|
||||
|
|
@ -334,7 +334,7 @@ bool Object3D::InitMaterials(const aiScene* pScene, const String& Filename){
|
|||
String str = String((*aiMp).mData);
|
||||
LOG("mData count : " + AsString(str.GetCount()));
|
||||
LOG("---------------------------------");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -37,64 +37,9 @@ struct Texture : public Moveable<Texture>{
|
|||
id = t.id;
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class Object3D : public Upp::Moveable<Object3D>{
|
||||
private:
|
||||
static int GlobalID;
|
||||
int ID;
|
||||
|
||||
Transform transform;
|
||||
BoundingBox boundingBox;
|
||||
Material material; //The material object is a representation of material property of the object (it change how light affect it)
|
||||
|
||||
Vector<Mesh> meshes;
|
||||
Vector<Texture> textures; //Vector carrying all texture of the object, every meshes refer to it via one iterator
|
||||
Vector<OpenGLProgram> program;
|
||||
VectorMap<String,Value> objectValues; //In case data need to be used in Init() Clear() and Draw();
|
||||
|
||||
bool loaded = false;
|
||||
bool moved = false;
|
||||
bool visible = true;
|
||||
bool showBoundingBox = false;
|
||||
|
||||
int programNoLight = 0;//The program will draw figure without light
|
||||
int programLine = 0;//THe program will draw figure line
|
||||
int programNormal = 0;//The program will draw Normal
|
||||
int programLight = 0;//the program will draw figure with light
|
||||
|
||||
GLenum drawType = GL_TRIANGLES;
|
||||
|
||||
//All this value are here by default
|
||||
Color lineColor = Black();
|
||||
float lineOpacity = 0.5f;
|
||||
float lineWidth = 1.0f;
|
||||
|
||||
Color normalColor = Red();
|
||||
float normalOpacity = 1.0f;
|
||||
float normalLength = 1.0f;
|
||||
|
||||
bool showMesh = true;
|
||||
bool showMeshLine = false;
|
||||
bool showMeshNormal = false;
|
||||
bool showLight = true;
|
||||
public:
|
||||
Function <void(Object3D& obj)> WhenInit;
|
||||
Function <void(const glm::mat4& projectionMatrix,const glm::mat4& viewMatrix,const glm::vec3& viewPosition,Object3D& obj)> WhenDraw;
|
||||
Function <void(Object3D& obj)> WhenClear;
|
||||
Function <void(Object3D& obj)> WhenReload;
|
||||
private:
|
||||
bool UpdateBuffer(GLuint buffer, int SurfaceCount , int SurfaceNumber,int count ,int numberOfElement, const float * data)noexcept;
|
||||
Vector<float> ReadBuffer(GLuint buffer, int SurfaceCount , int SurfaceNumber,int count, int numberOfElement)noexcept;
|
||||
//Texture loading function
|
||||
//Return position of the texture object carrying this texture
|
||||
int LoadTexture(const Image& img , const String& name, int indiceWhereInsert = -1);
|
||||
|
||||
//Assimp loading function
|
||||
bool InitFromScene(const aiScene* pScene, const String& Filename);
|
||||
void InitMesh(unsigned int Index, const aiMesh* paiMesh);
|
||||
bool InitMaterials(const aiScene* pScene, const String& Filename);
|
||||
public:
|
||||
Object3D();
|
||||
Object3D(Object3D&& obj):ID(GlobalID++){*this = pick(obj);}
|
||||
|
|
@ -105,6 +50,11 @@ class Object3D : public Upp::Moveable<Object3D>{
|
|||
|
||||
int GetID()const{return ID;}
|
||||
|
||||
Function <void(Object3D& obj)> WhenInit;
|
||||
Function <void(const glm::mat4& projectionMatrix,const glm::mat4& viewMatrix,const glm::vec3& viewPosition,Object3D& obj)> WhenDraw;
|
||||
Function <void(Object3D& obj)> WhenClear;
|
||||
Function <void(Object3D& obj)> WhenReload;
|
||||
|
||||
bool IsLoaded(){return loaded;}
|
||||
Object3D& Show(){visible = true;return *this;}
|
||||
Object3D& Hide(){visible = false;return *this;}
|
||||
|
|
@ -221,18 +171,62 @@ class Object3D : public Upp::Moveable<Object3D>{
|
|||
void Draw(const glm::mat4& projectionMatrix,const glm::mat4& viewMatrix,const glm::vec3& viewPosition)noexcept{WhenDraw(projectionMatrix,viewMatrix,viewPosition, *this);}
|
||||
void Clear(){WhenClear(*this); loaded = false;}
|
||||
void Reload(){WhenReload(*this);}
|
||||
|
||||
|
||||
private:
|
||||
static int GlobalID;
|
||||
int ID;
|
||||
|
||||
Transform transform;
|
||||
BoundingBox boundingBox;
|
||||
Material material; //The material object is a representation of material property of the object (it change how light affect it)
|
||||
|
||||
Vector<Mesh> meshes;
|
||||
Vector<Texture> textures; //Vector carrying all texture of the object, every meshes refer to it via one iterator
|
||||
Vector<OpenGLProgram> program;
|
||||
VectorMap<String,Value> objectValues; //In case data need to be used in Init() Clear() and Draw();
|
||||
|
||||
bool loaded = false;
|
||||
bool moved = false;
|
||||
bool visible = true;
|
||||
bool showBoundingBox = false;
|
||||
|
||||
int programNoLight = 0;//The program will draw figure without light
|
||||
int programLine = 0;//THe program will draw figure line
|
||||
int programNormal = 0;//The program will draw Normal
|
||||
int programLight = 0;//the program will draw figure with light
|
||||
|
||||
GLenum drawType = GL_TRIANGLES;
|
||||
|
||||
//All this value are here by default
|
||||
Color lineColor = Black();
|
||||
float lineOpacity = 0.5f;
|
||||
float lineWidth = 1.0f;
|
||||
|
||||
Color normalColor = Red();
|
||||
float normalOpacity = 1.0f;
|
||||
float normalLength = 1.0f;
|
||||
|
||||
bool showMesh = true;
|
||||
bool showMeshLine = false;
|
||||
bool showMeshNormal = false;
|
||||
bool showLight = true;
|
||||
|
||||
bool UpdateBuffer(GLuint buffer, int SurfaceCount , int SurfaceNumber,int count ,int numberOfElement, const float * data)noexcept;
|
||||
Vector<float> ReadBuffer(GLuint buffer, int SurfaceCount , int SurfaceNumber,int count, int numberOfElement)noexcept;
|
||||
//Texture loading function
|
||||
//Return position of the texture object carrying this texture
|
||||
int LoadTexture(const Image& img , const String& name, int indiceWhereInsert = -1);
|
||||
|
||||
//Assimp loading function
|
||||
bool InitFromScene(const aiScene* pScene, const String& Filename);
|
||||
void InitMesh(unsigned int Index, const aiMesh* paiMesh);
|
||||
bool InitMaterials(const aiScene* pScene, const String& Filename);
|
||||
|
||||
};
|
||||
|
||||
class Skybox {
|
||||
private:
|
||||
unsigned int ID = 0;
|
||||
GLuint VBO, VAO;
|
||||
bool show = false;
|
||||
|
||||
OpenGLProgram program;
|
||||
Skybox& Init(const Vector<Image>& images); //Load this vector of image as Skybox
|
||||
public:
|
||||
|
||||
Skybox(){}
|
||||
~Skybox(){Clear();}
|
||||
|
||||
|
|
@ -243,7 +237,13 @@ class Skybox {
|
|||
Skybox& Init(const Image& skybox_right,const Image& skybox_left,const Image& skybox_top,const Image& skybox_bottom,const Image& skybox_front,const Image& skybox_back); //Load all image provided as skybox
|
||||
Skybox& Clear();
|
||||
Skybox& Draw(const glm::mat4& projectionMatrix,const glm::mat4& viewMatrix);
|
||||
|
||||
private:
|
||||
unsigned int ID = 0;
|
||||
GLuint VBO, VAO;
|
||||
bool show = false;
|
||||
|
||||
OpenGLProgram program;
|
||||
Skybox& Init(const Vector<Image>& images); //Load this vector of image as Skybox
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,18 @@
|
|||
//#include <GLCtrl_glad/GLCtrl_glad.h>
|
||||
namespace Upp{
|
||||
class OpenGLShader{
|
||||
public:
|
||||
OpenGLShader(GLenum type,const char * data) : shaderType{type} {
|
||||
ID = glCreateShader(shaderType);
|
||||
glShaderSource(ID, 1, &data, NULL);
|
||||
glCompileShader(ID);
|
||||
if(CheckForCompilationError())compiled = true;
|
||||
}
|
||||
~OpenGLShader(){glDeleteShader(ID);}
|
||||
|
||||
GLuint GetID()const noexcept{return ID;}
|
||||
GLenum GetType()const noexcept{return shaderType;}
|
||||
bool IsCompiled()const noexcept{return compiled;}
|
||||
private:
|
||||
GLenum shaderType;
|
||||
GLuint ID = 0;
|
||||
|
|
@ -40,49 +52,8 @@ class OpenGLShader{
|
|||
}
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
OpenGLShader(GLenum type,const char * data) : shaderType{type} {
|
||||
ID = glCreateShader(shaderType);
|
||||
glShaderSource(ID, 1, &data, NULL);
|
||||
glCompileShader(ID);
|
||||
if(CheckForCompilationError())compiled = true;
|
||||
}
|
||||
~OpenGLShader(){glDeleteShader(ID);}
|
||||
|
||||
GLuint GetID()const noexcept{return ID;}
|
||||
GLenum GetType()const noexcept{return shaderType;}
|
||||
bool IsCompiled()const noexcept{return compiled;}
|
||||
};
|
||||
class OpenGLProgram : public Moveable<OpenGLProgram>{
|
||||
private:
|
||||
GLuint vertex = 0;
|
||||
GLuint TCS = 0; //Tesselation control shader
|
||||
GLuint TES = 0; //Tesselation evaluation shader
|
||||
GLuint geometry = 0;
|
||||
GLuint fragment = 0;
|
||||
|
||||
String name="";
|
||||
GLuint ID = 0;
|
||||
bool linked = false;
|
||||
bool copied = false; //if the shader is copied then is deletion wont occure a clear in OpenGL data
|
||||
|
||||
GLint GetUniformLocation(Upp::String name){
|
||||
GLint location = glGetUniformLocation(ID, name.ToStd().c_str());
|
||||
if(location == -1)RLOG("Warning : uniform named " + name +" can't be find in program number " + AsString(ID));
|
||||
return location;
|
||||
}
|
||||
|
||||
bool CheckForLinkingError()noexcept{
|
||||
int success;
|
||||
char infoLog[512];
|
||||
glGetProgramiv(ID, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(ID, 512, NULL, infoLog);
|
||||
LOG("ERROR::SHADER::PROGRAM::LINKING_FAILED\n" + String(infoLog));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
class OpenGLProgram : public Moveable<OpenGLProgram>{
|
||||
public:
|
||||
OpenGLProgram(){}
|
||||
OpenGLProgram(const String& n){name = n;}
|
||||
|
|
@ -172,6 +143,37 @@ class OpenGLShader{
|
|||
OpenGLProgram& SetMat2(Upp::String name, const glm::mat2 &mat)noexcept{if(linked)glUniformMatrix2fv(GetUniformLocation(name), 1, GL_FALSE, &mat[0][0]);return *this;}
|
||||
OpenGLProgram& SetMat3(Upp::String name, const glm::mat3 &mat)noexcept{if(linked)glUniformMatrix3fv(GetUniformLocation(name), 1, GL_FALSE, &mat[0][0]);return *this;}
|
||||
OpenGLProgram& SetMat4(Upp::String name, const glm::mat4 &mat)noexcept{if(linked)glUniformMatrix4fv(GetUniformLocation(name), 1, GL_FALSE, &mat[0][0]);return *this;}
|
||||
|
||||
|
||||
private:
|
||||
GLuint vertex = 0;
|
||||
GLuint TCS = 0; //Tesselation control shader
|
||||
GLuint TES = 0; //Tesselation evaluation shader
|
||||
GLuint geometry = 0;
|
||||
GLuint fragment = 0;
|
||||
|
||||
String name="";
|
||||
GLuint ID = 0;
|
||||
bool linked = false;
|
||||
bool copied = false; //if the shader is copied then is deletion wont occure a clear in OpenGL data
|
||||
|
||||
GLint GetUniformLocation(Upp::String name){
|
||||
GLint location = glGetUniformLocation(ID, name.ToStd().c_str());
|
||||
if(location == -1)RLOG("Warning : uniform named " + name +" can't be find in program number " + AsString(ID));
|
||||
return location;
|
||||
}
|
||||
|
||||
bool CheckForLinkingError()noexcept{
|
||||
int success;
|
||||
char infoLog[512];
|
||||
glGetProgramiv(ID, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(ID, 512, NULL, infoLog);
|
||||
LOG("ERROR::SHADER::PROGRAM::LINKING_FAILED\n" + String(infoLog));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,41 +12,6 @@ static const String GetSurfaceCtrlDirectory(){
|
|||
}
|
||||
|
||||
class SurfaceCtrl : public GLCtrl{
|
||||
typedef SurfaceCtrl CLASSNAME;
|
||||
private:
|
||||
bool loaded = false;
|
||||
Object3DProvider objProvider;
|
||||
|
||||
Upp::Vector<Object3D> allObjects;
|
||||
Upp::Vector<int> allSelected;
|
||||
|
||||
Object3D Axis;
|
||||
Object3D CameraFocus;
|
||||
Skybox skybox;
|
||||
|
||||
MagicCamera camera;
|
||||
|
||||
OpenGLProgram DrawMeshNoLight;
|
||||
OpenGLProgram DrawMeshLight;
|
||||
OpenGLProgram DrawMeshLine;
|
||||
OpenGLProgram DrawMeshNormal;
|
||||
|
||||
bool showAxis = true;
|
||||
bool depthAxis = false;
|
||||
bool showCameraFocus = false;
|
||||
|
||||
float sizeW = 800.0f;
|
||||
float sizeH = 600.0f;
|
||||
|
||||
bool TimerStarted = false;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> start,end; //High resolution clock
|
||||
double DeltaTime=0.0f,LastTime=0.0f,lastFrame =0.0f,Timer=0.0f;
|
||||
int bufferFrame =0,frameCount = 0; //used to calculate FPS
|
||||
void ProcessTime()noexcept;
|
||||
|
||||
bool fastMode = false;
|
||||
|
||||
void InitShader(); //Load default shader
|
||||
public:
|
||||
SurfaceCtrl();
|
||||
~SurfaceCtrl();
|
||||
|
|
@ -81,9 +46,9 @@ class SurfaceCtrl : public GLCtrl{
|
|||
Skybox& GetSkybox()noexcept{return skybox;}
|
||||
|
||||
//Change Object selected
|
||||
void MoveAllSelectedObjects(glm::vec3 move)noexcept; //Move all selected object
|
||||
void RotateAllSelectedObjects(glm::quat rotation)noexcept; //Rotate all selected object
|
||||
void DeleteAllSelectedObjects()noexcept; //Delete all selected object
|
||||
void MoveAllSelectedObjects(glm::vec3 move)noexcept;
|
||||
void RotateAllSelectedObjects(glm::quat rotation)noexcept;
|
||||
void DeleteAllSelectedObjects()noexcept;
|
||||
|
||||
//Camera getter
|
||||
const MagicCamera& GetCamera()const noexcept{return camera;}
|
||||
|
|
@ -125,16 +90,8 @@ class SurfaceCtrl : public GLCtrl{
|
|||
virtual void GLResize(int w, int h); //Action on resize
|
||||
|
||||
//Input event
|
||||
/*virtual void MouseMove(Point p, dword); //Action on mouse move
|
||||
virtual void MouseWheel(Point p,int zdelta,dword keyflags); //action on Mouse wheel
|
||||
virtual void LeftDown(Point p, dword); //Action on Left Down mouse
|
||||
virtual void LeftUp(Point p, dword); //Action on Up down mouse
|
||||
virtual void MiddleDown(Point p, dword keyflags); //Action Middle down (wheel down) mouse
|
||||
virtual void MiddleUp(Point p, dword keyflags);//Action Middle up (wheel up) mouse
|
||||
virtual void MouseLeave(); //action when mouse leave*/
|
||||
virtual bool Key(dword key,int count); //Action when key press
|
||||
|
||||
|
||||
int buttonRotation = Ctrl::MIDDLE;
|
||||
int buttonDrag = Ctrl::LEFT;
|
||||
int buttonMenu = Ctrl::RIGHT;
|
||||
|
|
@ -147,13 +104,46 @@ class SurfaceCtrl : public GLCtrl{
|
|||
void OnTypeImage(FileSel *_fs);
|
||||
|
||||
virtual Image HandleEvent(int event, Point p, int zdelta, dword);
|
||||
|
||||
|
||||
|
||||
|
||||
//Menu bar
|
||||
Image MouseEvent(int event, Point p, int zdelta, dword keyflags);
|
||||
void ContextMenu(Bar& bar,const Point& p);
|
||||
|
||||
private:
|
||||
typedef SurfaceCtrl CLASSNAME;
|
||||
bool loaded = false;
|
||||
Object3DProvider objProvider;
|
||||
|
||||
Upp::Vector<Object3D> allObjects;
|
||||
Upp::Vector<int> allSelected;
|
||||
|
||||
Object3D Axis;
|
||||
Object3D CameraFocus;
|
||||
Skybox skybox;
|
||||
|
||||
MagicCamera camera;
|
||||
|
||||
OpenGLProgram DrawMeshNoLight;
|
||||
OpenGLProgram DrawMeshLight;
|
||||
OpenGLProgram DrawMeshLine;
|
||||
OpenGLProgram DrawMeshNormal;
|
||||
|
||||
bool showAxis = true;
|
||||
bool depthAxis = false;
|
||||
bool showCameraFocus = false;
|
||||
|
||||
float sizeW = 800.0f;
|
||||
float sizeH = 600.0f;
|
||||
|
||||
bool TimerStarted = false;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> start,end; //High resolution clock
|
||||
double DeltaTime=0.0f,LastTime=0.0f,lastFrame =0.0f,Timer=0.0f;
|
||||
int bufferFrame =0,frameCount = 0; //used to calculate FPS
|
||||
void ProcessTime()noexcept;
|
||||
|
||||
bool fastMode = false;
|
||||
|
||||
void InitShader(); //Load default shader
|
||||
};
|
||||
#include "Object3D.h"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,24 +6,6 @@
|
|||
*/
|
||||
namespace Upp{
|
||||
class Transform{
|
||||
private:
|
||||
glm::vec3 Front = glm::vec3(0.0f, 0.0f, -1.0f);
|
||||
glm::vec3 Up = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
glm::vec3 Right = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
|
||||
glm::vec3 WorldFront = glm::vec3(0.0, 0.0, -1.0);
|
||||
glm::vec3 WorldUp = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
glm::vec3 WorldRight = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
|
||||
glm::vec3 Position = glm::vec3(0.0f);
|
||||
glm::quat Rotation = Transform::GetQuaterion(0.0f,glm::vec3(0.0f,0.0f,0.0f));
|
||||
glm::vec3 Scale = glm::vec3(1.0f);
|
||||
|
||||
void RecalculateFURW(){
|
||||
Front = glm::rotate(glm::inverse(Rotation), WorldFront);
|
||||
Right = glm::rotate(glm::inverse(Rotation), WorldRight);
|
||||
Up = glm::rotate(glm::inverse(Rotation), WorldUp);
|
||||
}
|
||||
public:
|
||||
Transform(){}
|
||||
Transform(const Transform& _transform){*this = _transform;}
|
||||
|
|
@ -108,6 +90,24 @@ class Transform{
|
|||
ret.z = (vector[0]*matrix[0][2]+vector[1]*matrix[1][2]+vector[2]*matrix[2][2]+matrix[3][2])/w;
|
||||
return ret;
|
||||
}
|
||||
private:
|
||||
glm::vec3 Front = glm::vec3(0.0f, 0.0f, -1.0f);
|
||||
glm::vec3 Up = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
glm::vec3 Right = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
|
||||
glm::vec3 WorldFront = glm::vec3(0.0, 0.0, -1.0);
|
||||
glm::vec3 WorldUp = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
glm::vec3 WorldRight = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
|
||||
glm::vec3 Position = glm::vec3(0.0f);
|
||||
glm::quat Rotation = Transform::GetQuaterion(0.0f,glm::vec3(0.0f,0.0f,0.0f));
|
||||
glm::vec3 Scale = glm::vec3(1.0f);
|
||||
|
||||
void RecalculateFURW(){
|
||||
Front = glm::rotate(glm::inverse(Rotation), WorldFront);
|
||||
Right = glm::rotate(glm::inverse(Rotation), WorldRight);
|
||||
Up = glm::rotate(glm::inverse(Rotation), WorldUp);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,26 +7,7 @@
|
|||
namespace Upp{
|
||||
|
||||
class UOGL_Camera{
|
||||
protected:
|
||||
Transform transform; //The Camera Transform object
|
||||
|
||||
CameraType type = CameraType::PERSPECTIVE;
|
||||
|
||||
float MaxFOV = 160.0f;
|
||||
float MinFOV = 10.0f;
|
||||
bool LimiteFOV = true;
|
||||
float FOV =45.0f;
|
||||
|
||||
float DrawDisanceMax = 10000.0f;
|
||||
float DrawDistanceMin = 0.1f;
|
||||
|
||||
float MouvementSpeed = 0.09f;
|
||||
float MouseSensitivity = 0.08f;
|
||||
float ZoomSpeed = 10.0f;
|
||||
|
||||
Upp::Sizef ScreenSize;
|
||||
public:
|
||||
|
||||
Point lastPress;
|
||||
bool MouseLeftPressed = false;
|
||||
bool MouseMiddlePressed = false;
|
||||
|
|
@ -149,7 +130,24 @@ class UOGL_Camera{
|
|||
|
||||
Upp::Sizef GetScreenSize()const noexcept{return ScreenSize;}
|
||||
UOGL_Camera& SetScreenSize(float width, float height)noexcept{ScreenSize = Sizef(width,height);return *this;}
|
||||
protected:
|
||||
Transform transform; //The Camera Transform object
|
||||
|
||||
CameraType type = CameraType::PERSPECTIVE;
|
||||
|
||||
float MaxFOV = 160.0f;
|
||||
float MinFOV = 10.0f;
|
||||
bool LimiteFOV = true;
|
||||
float FOV =45.0f;
|
||||
|
||||
float DrawDisanceMax = 10000.0f;
|
||||
float DrawDistanceMin = 0.1f;
|
||||
|
||||
float MouvementSpeed = 0.09f;
|
||||
float MouseSensitivity = 0.08f;
|
||||
float ZoomSpeed = 10.0f;
|
||||
|
||||
Upp::Sizef ScreenSize;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue