mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
code cleanup
This commit is contained in:
@@ -11,6 +11,7 @@ include_directories(/usr/include/cppunit)
|
||||
link_directories(/usr/lib/)
|
||||
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
set(gui text.cpp)
|
||||
set(utils util.cpp)
|
||||
set(math quaternion.cpp vector.cpp matrix.cpp ray.cpp)
|
||||
|
||||
@@ -7,12 +7,6 @@ namespace vb01{
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
Animation::~Animation(){
|
||||
}
|
||||
|
||||
void Animation::update(){
|
||||
}
|
||||
|
||||
KeyframeChannel* Animation::getKeyframeChannel(Animatable *animatable, KeyframeChannelType type){
|
||||
KeyframeChannel *k = nullptr;
|
||||
|
||||
|
||||
+1
-2
@@ -12,8 +12,7 @@ namespace vb01{
|
||||
class Animation{
|
||||
public:
|
||||
Animation(std::string);
|
||||
~Animation();
|
||||
void update();
|
||||
~Animation(){}
|
||||
KeyframeChannel* getKeyframeChannel(Animatable*, KeyframeChannel::Type);
|
||||
std::vector<KeyframeChannel> getKeyframeChannelsByAnimatable(Animatable*);
|
||||
inline void addKeyframeChannels(std::vector<KeyframeChannel> keyframeChannels){this->keyframeChannels.assign(keyframeChannels.begin(), keyframeChannels.end());}
|
||||
|
||||
@@ -5,12 +5,6 @@
|
||||
using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
AnimationController::AnimationController(){
|
||||
}
|
||||
|
||||
AnimationController::~AnimationController(){
|
||||
}
|
||||
|
||||
void AnimationController::update(){
|
||||
for(AnimationChannel *channel : channels){
|
||||
channel->update();
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace vb01{
|
||||
|
||||
class AnimationController{
|
||||
public:
|
||||
AnimationController();
|
||||
~AnimationController();
|
||||
AnimationController(){}
|
||||
~AnimationController(){}
|
||||
void update();
|
||||
Animation* getAnimation(std::string);
|
||||
inline std::vector<Animation*> getAnimations(){return animations;}
|
||||
|
||||
@@ -8,10 +8,7 @@ namespace vb01{
|
||||
|
||||
class IkSolver{
|
||||
public:
|
||||
IkSolver();
|
||||
~IkSolver(){}
|
||||
static void calculateFabrik(int, Bone**, Vector3[], Vector3);
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ namespace vb01{
|
||||
float KeyframeChannel::interpolateBezier(vector<float> points, float ratio){
|
||||
int numPoints = points.size();
|
||||
vector<float> newPoints;
|
||||
|
||||
for(int i = 0; i < numPoints - 1; i++)
|
||||
newPoints.push_back(points[i] + (points[i + 1] - points[i]) * ratio);
|
||||
|
||||
@@ -80,7 +79,4 @@ namespace vb01{
|
||||
}
|
||||
return keyframeChannel.keyframes[pastKeyframeId + (last ? 0 : 1)];
|
||||
}
|
||||
|
||||
void KeyframeChannel::transform(){
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@ namespace vb01{
|
||||
static KeyframeChannel::Type getKeyframeChannelType(std::string);
|
||||
static float interpolate(Keyframe, Keyframe, float);
|
||||
static Keyframe findKeyframe(float, KeyframeChannel, bool);
|
||||
static void transform();
|
||||
};
|
||||
|
||||
typedef KeyframeChannel::Type KeyframeChannelType;
|
||||
|
||||
@@ -76,14 +76,12 @@ namespace vb01{
|
||||
Root *root = Root::getSingleton();
|
||||
Node *rootNode = root->getRootNode();
|
||||
|
||||
Camera *cam=root->getCamera();
|
||||
float fov = cam->getFov(), width = root->getWidth(), height = root->getHeight();
|
||||
|
||||
vector<Node*> descendants;
|
||||
rootNode->getDescendants(descendants);
|
||||
descendants.push_back(rootNode);
|
||||
vector<Light*> lights;
|
||||
vector<Material*> materials;
|
||||
|
||||
for(Node *d : descendants){
|
||||
for(Light *l : d->getLights())
|
||||
lights.push_back(l);
|
||||
@@ -147,17 +145,13 @@ namespace vb01{
|
||||
depthMapShader->setFloat(farPlane, "farPlane");
|
||||
depthMapShader->setVec3(position, "lightPos");
|
||||
if(type == POINT){
|
||||
vec3 dirs[] = {vec3(1, 0, 0), vec3(-1, 0, 0), vec3(0, 1, 0), vec3(0, -1, 0), vec3(0, 0, 1), vec3(0, 0, -1)};
|
||||
for(int i = 0; i < 6; i++){
|
||||
vec3 upVec;
|
||||
if(1 < i && i < 4)
|
||||
upVec = vec3(0, 0, -1);
|
||||
else
|
||||
upVec = vec3(0, -1, 0);
|
||||
|
||||
vec3 dirs[] = {
|
||||
vec3(1, 0, 0), vec3(-1, 0, 0), vec3(0, 1, 0), vec3(0, -1, 0), vec3(0, 0, 1), vec3(0, 0, -1)
|
||||
};
|
||||
|
||||
depthMapShader->setMat4(proj * lookAt(lightPos, lightPos + dirs[i], upVec), "shadowMat[" + to_string(i) + "]");
|
||||
}
|
||||
}
|
||||
|
||||
+4
-24
@@ -16,31 +16,11 @@ namespace vb01{
|
||||
Material(Type = MATERIAL_2D);
|
||||
~Material();
|
||||
void update();
|
||||
inline void addDiffuseMap(std::string diffuseMap, bool flip = false){
|
||||
std::string p[]{diffuseMap};
|
||||
diffuseMapTextures.push_back(new Texture(p, 1, Texture::DIFFUSE, flip));
|
||||
}
|
||||
inline void addDiffuseMap(std::string diffuseMap[], int numFrames){diffuseMapTextures.push_back(new Texture(diffuseMap, numFrames));}
|
||||
inline void addDiffuseMap(std::string diffuseMap[6]){diffuseMapTextures.push_back(new Texture(diffuseMap));}
|
||||
inline void addDiffuseMap(Texture *texture){diffuseMapTextures.push_back(texture);}
|
||||
inline void setDiffuseMap(Texture *texture, int i){diffuseMapTextures[i]=texture;}
|
||||
inline void addNormalMap(std::string normalMap){
|
||||
std::string p[]{normalMap};
|
||||
normalMapTextures.push_back(new Texture(p, 1));
|
||||
}
|
||||
inline void addNormalMap(std::string normalMap[], int numFrames){normalMapTextures.push_back(new Texture(normalMap, numFrames));}
|
||||
inline void setNormalMap(Texture *texture, int i){normalMapTextures[i] = texture;}
|
||||
inline void addSpecularMap(std::string specularMap){
|
||||
std::string p[]{specularMap};
|
||||
specularMapTextures.push_back(new Texture(p, 1));
|
||||
}
|
||||
inline void addSpecularMap(std::string specularMap[], int numFrames){specularMapTextures.push_back(new Texture(specularMap, numFrames));}
|
||||
inline void setSpecularMap(Texture *texture, int i){specularMapTextures[i] = texture;}
|
||||
inline void addParallaxMap(std::string parallaxMap){
|
||||
std::string p[]{parallaxMap};
|
||||
parallaxMapTextures.push_back(new Texture(p, 1));
|
||||
}
|
||||
inline void addParallaxMap(std::string parallaxMap[], int numFrames){parallaxMapTextures.push_back(new Texture(parallaxMap, numFrames));}
|
||||
inline void addDiffuseMap(std::string diffuseMap[6]){diffuseMapTextures.push_back(new Texture(diffuseMap));}
|
||||
inline void addNormalMap(Texture *texture){normalMapTextures.push_back(texture);}
|
||||
inline void addSpecularMap(Texture *texture){specularMapTextures.push_back(texture);}
|
||||
inline void addParallaxMap(Texture *texture){parallaxMapTextures.push_back(texture);}
|
||||
inline void setDiffuseColor(Vector4 diffuse){this->diffuseColor = diffuse;}
|
||||
inline void setSpecularColor(Vector4 specular){this->specularColor = specular;}
|
||||
inline void setLightingEnabled(bool lighting){this->lightingEnabled = lighting;}
|
||||
|
||||
@@ -122,9 +122,7 @@ namespace vb01{
|
||||
void Mesh::update(){
|
||||
Root *root = Root::getSingleton();
|
||||
Camera *cam = root->getCamera();
|
||||
float fov = cam->getFov(), width = root->getWidth(), height = root->getHeight();
|
||||
float nearPlane = cam->getNearPlane(), farPlane = cam->getFarPlane();
|
||||
Vector3 dir = cam->getDirection(), up = cam->getUp(), camPos = Vector3::VEC_ZERO, pos = Vector3::VEC_ZERO, scale = Vector3::VEC_IJK;
|
||||
Vector3 camPos = Vector3::VEC_ZERO, pos = Vector3::VEC_ZERO, scale = Vector3::VEC_IJK;
|
||||
Quaternion orient = Quaternion::QUAT_W;
|
||||
|
||||
if(node){
|
||||
@@ -140,19 +138,20 @@ namespace vb01{
|
||||
model = translate(model, vec3(pos.x, pos.y, pos.z));
|
||||
model = rotate(model, orient.getAngle(), vec3(rotAxis.x, rotAxis.y, rotAxis.z));
|
||||
model = glm::scale(model, vec3(scale.x, scale.y, scale.z));
|
||||
|
||||
Vector3 dir = cam->getDirection(), up = cam->getUp();
|
||||
mat4 view = lookAt(vec3(camPos.x, camPos.y, camPos.z), vec3(camPos.x + dir.x, camPos.y + dir.y, camPos.z + dir.z), vec3(up.x, up.y, up.z));
|
||||
|
||||
float fov = cam->getFov(), width = root->getWidth(), height = root->getHeight(), nearPlane = cam->getNearPlane(), farPlane = cam->getFarPlane();
|
||||
mat4 proj = perspective(radians(fov), width / height, nearPlane, farPlane);
|
||||
|
||||
material->update();
|
||||
Shader *shader = material->getShader();
|
||||
|
||||
if(reflect){
|
||||
if(reflect)
|
||||
updateReflection(shader, pos, width, height);
|
||||
}
|
||||
|
||||
if(skeleton)
|
||||
updateSkeleton(shader);
|
||||
|
||||
if(numShapeKeys > 0)
|
||||
updateShapeKeys(shader);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace vb01{
|
||||
|
||||
void animate(float, KeyframeChannel);
|
||||
};
|
||||
|
||||
struct Vertex{
|
||||
Vector3 pos, norm, tan, biTan;
|
||||
Vector2 uv;
|
||||
|
||||
@@ -20,11 +20,6 @@ namespace vb01{
|
||||
|
||||
class Node : public Animatable{
|
||||
public:
|
||||
struct Transform{
|
||||
Vector3 position = Vector3::VEC_ZERO, scale = Vector3::VEC_IJK;
|
||||
Quaternion orientation = Quaternion::QUAT_W;
|
||||
};
|
||||
|
||||
Node(Vector3 = Vector3::VEC_ZERO, Quaternion = Quaternion::QUAT_W, Vector3 = Vector3::VEC_IJK, std::string = "", AnimationController *c = nullptr);
|
||||
virtual ~Node();
|
||||
void attachMesh(Mesh*);
|
||||
|
||||
+11
-6
@@ -105,17 +105,22 @@ namespace vb01{
|
||||
while(!heap){
|
||||
bool end = true;
|
||||
for(int i = 0; 2 * i + 1 + offset < numParticles; i++){
|
||||
if(2 * i + 2 + offset < numParticles && (particles[i + offset]->d < particles[2 * i + 1 + offset]->d || particles[i + offset]->d < particles[2 * i + 2 + offset]->d)){
|
||||
bool leftChild = particles[2 * i + 1 + offset]->d > particles[2 * i + 2 + offset]->d;
|
||||
if(2 * i + 2 + offset < numParticles && (particles[i + offset]->distToCamPlane < particles[2 * i + 1 + offset]->distToCamPlane ||
|
||||
particles[i + offset]->distToCamPlane < particles[2 * i + 2 + offset]->distToCamPlane))
|
||||
{
|
||||
bool leftChild = particles[2 * i + 1 + offset]->distToCamPlane > particles[2 * i + 2 + offset]->distToCamPlane;
|
||||
swap(particles[i + offset], leftChild ? particles[2 * i + 1 + offset] : particles[2 * i + 2 + offset]);
|
||||
}
|
||||
else if(2 * i + 2 + offset == numParticles && particles[i + offset]->d < particles[2 * i + 1 + offset]->d)
|
||||
else if(2 * i + 2 + offset == numParticles && particles[i + offset]->distToCamPlane < particles[2 * i + 1 + offset]->distToCamPlane)
|
||||
swap(particles[i + offset], particles[2 * i + 1 + offset]);
|
||||
}
|
||||
for(int i = 0; 2 * i + 1 < numParticles; i++){
|
||||
if(2 * i + 2 + offset < numParticles && (particles[i + offset]->d < particles[2 * i + 1 + offset]->d || particles[i + offset]->d < particles[2 * i + 2 + offset]->d))
|
||||
if(2 * i + 2 + offset < numParticles && (particles[i + offset]->distToCamPlane < particles[2 * i + 1 + offset]->distToCamPlane ||
|
||||
particles[i + offset]->distToCamPlane < particles[2 * i + 2 + offset]->distToCamPlane))
|
||||
{
|
||||
end = false;
|
||||
else if(2 * i + 2 + offset == numParticles && particles[i + offset]->d < particles[2 * i + 1 + offset]->d)
|
||||
}
|
||||
else if(2 * i + 2 + offset == numParticles && particles[i + offset]->distToCamPlane < particles[2 * i + 1 + offset]->distToCamPlane)
|
||||
end = false;
|
||||
}
|
||||
if(end)
|
||||
@@ -185,7 +190,7 @@ namespace vb01{
|
||||
|
||||
dir = dir.norm() * speed + gravity;
|
||||
particles[i]->trans = particles[i]->trans + dir;
|
||||
particles[i]->d = cos(camDir.getAngleBetween((particles[i]->trans - camPos).norm())) * camPos.getDistanceFrom(particles[i]->trans);
|
||||
particles[i]->distToCamPlane = cos(camDir.getAngleBetween((particles[i]->trans - camPos).norm())) * camPos.getDistanceFrom(particles[i]->trans);
|
||||
|
||||
float lifePercentage = (float)(getTime() - particles[i]->time) / particles[i]->timeToLive;
|
||||
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ namespace vb01{
|
||||
int VAO;
|
||||
s64 time = 0, timeToLive = 0;
|
||||
Vector3 trans;
|
||||
float d;
|
||||
float distToCamPlane;
|
||||
};
|
||||
|
||||
void makeHeap(int);
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace vb01{
|
||||
particleEmitter->particles = new ParticleEmitter::Particle*[numParticles];
|
||||
for(int i = 0; i < numParticles; i++){
|
||||
ParticleEmitter::Particle *particle = new ParticleEmitter::Particle;
|
||||
particle->d = rand() % 1000;
|
||||
particle->distToCamPlane = rand() % 1000;
|
||||
particleEmitter->particles[i] = particle;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace vb01{
|
||||
for(int i = 1; i < numParticles; i++){
|
||||
ParticleEmitter::Particle *prevPart = particleEmitter->particles[i - 1];
|
||||
ParticleEmitter::Particle *currPart = particleEmitter->particles[i];
|
||||
CPPUNIT_ASSERT(prevPart->d >= currPart->d);
|
||||
CPPUNIT_ASSERT(prevPart->distToCamPlane >= currPart->distToCamPlane);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define ROOT_H
|
||||
|
||||
#include "camera.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -47,7 +48,7 @@ namespace vb01{
|
||||
Box *skybox = nullptr;
|
||||
Quad *guiPlane = nullptr;
|
||||
int width, height, blurLevel = 10;
|
||||
unsigned int FBO, RBO, pingpongBuffers[2];
|
||||
u32 FBO, RBO, pingpongBuffers[2];
|
||||
GLFWwindow *window;
|
||||
Node *rootNode, *guiNode;
|
||||
Camera *camera;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace vb01{
|
||||
void loadShaders();
|
||||
void pushShader(u32&, std::string&, int, ErrorType);
|
||||
void checkCompileErrors(u32, ErrorType);
|
||||
unsigned int id;
|
||||
u32 id;
|
||||
bool geometry = false;
|
||||
std::string vString, fString, gString;
|
||||
|
||||
|
||||
+6
-3
@@ -17,6 +17,11 @@ namespace vb01{
|
||||
}
|
||||
|
||||
void Skeleton::update(){
|
||||
updateIk();
|
||||
controller->update();
|
||||
}
|
||||
|
||||
void Skeleton::updateIk(){
|
||||
for(Bone *b : bones){
|
||||
if(b->getIkTarget()){
|
||||
const int chainLength = b->getIkChainLength();
|
||||
@@ -29,12 +34,10 @@ namespace vb01{
|
||||
delete[] boneChain;
|
||||
}
|
||||
}
|
||||
for(Bone *b : bones){
|
||||
for(Bone *b : bones)
|
||||
if(b->getIkTarget())
|
||||
solveIk(b);
|
||||
}
|
||||
controller->update();
|
||||
}
|
||||
|
||||
void Skeleton::solveIk(Bone *ikBone){
|
||||
const int chainLength = ikBone->getIkChainLength();
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace vb01{
|
||||
inline std::string getName(){return name;}
|
||||
inline int getNumBones(){return bones.size();}
|
||||
private:
|
||||
void updateIk();
|
||||
void solveIk(Bone*);
|
||||
void transformIkChain(int, Bone*[], Vector3[], Bone*);
|
||||
Bone** getIkBoneChain(Bone*);
|
||||
|
||||
Reference in New Issue
Block a user