-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 586b78c
Showing
60 changed files
with
82,550 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
#define GLM_ENABLE_EXPERIMENTAL | ||
#include <glm/glm.hpp> | ||
#include <glm/gtc/matrix_transform.hpp> | ||
#include <glm/gtc/type_ptr.hpp> | ||
#include <math.h> /* pow */ | ||
#include <Eigen/Dense> | ||
#include <list> | ||
class Bone_Animation | ||
{ | ||
public: | ||
Bone_Animation(); | ||
~Bone_Animation(); | ||
|
||
void init(); | ||
void update(float delta_time); | ||
void forward_kinematics(float angleX, float angleY, float angleZ, float anglePurpleX, float anglePurpleY, | ||
float anglePurpleZ, float angleBlueX, float angleBlueY, | ||
float angleBlueZ); | ||
void RotatePurple(float angleX, float angleY, float angleZ); | ||
|
||
glm::tvec4<float>* rot = new glm::tvec4<float>[9]; | ||
|
||
|
||
Eigen::MatrixXf jacobian = Eigen::MatrixXf::Zero(3, 9); | ||
Eigen::MatrixXf anglesVector = Eigen::MatrixXf::Zero(9, 1); | ||
Eigen::MatrixXf goalVector = Eigen::MatrixXf::Zero(3, 1); | ||
bool is_bone_move; | ||
float prevDist = 100; | ||
|
||
|
||
|
||
//float distance(float x1, float y1, | ||
// float z1, float x2, | ||
// float y2, float z2); | ||
|
||
|
||
//void forwardKinematics(float yellowXangle, float yellowYangle, float yellowZangle, | ||
// float purpleXangle, float purpleYangle, float purpleZangle, float blueXangle, | ||
// float blueYangle, float blueZangle); | ||
Eigen::MatrixXf get_transpose(int id); | ||
|
||
void reset(); | ||
|
||
void shouldStop(); | ||
void computeAngles(); | ||
void setJacobian(int id); | ||
|
||
glm::mat4 get_yellow_mat() { return m_yellow_mat; }; | ||
glm::mat4 get_pink_mat() { return m_pink_mat; }; | ||
glm::mat4 get_blue_mat() { return m_blue_mat; }; | ||
glm::mat4 get_target_mat() { return m_target_mat; }; | ||
|
||
public: | ||
|
||
// Here the head of each vector is the root bone | ||
std::vector<glm::vec3> scale_vector; | ||
std::vector<glm::vec3> rotation_degree_vector; | ||
std::vector<glm::vec4> colors; | ||
|
||
glm::vec3 root_position; | ||
glm::vec3 yellow_position; | ||
glm::vec3 pink_position; | ||
glm::vec3 blue_position; | ||
|
||
float yellowXangle; | ||
float yellowYangle; | ||
float yellowZangle = 30; | ||
|
||
|
||
float purpleXangle; | ||
float purpleYangle; | ||
float purpleZangle = 30; | ||
|
||
|
||
float blueXangle; | ||
float blueYangle; | ||
float blueZangle = 30; | ||
|
||
glm::vec3 yellowRot; | ||
glm::vec3 pinkRot; | ||
glm::vec3 blueRot; | ||
|
||
|
||
glm::vec3 lastTargetPosition, goal, v1, v2, v3, v4, v5, v6, v7,v8,v9, anglesVectorZ, anglesVectorX, anglesVectorY; | ||
|
||
float alphaYellow, alphaPink, alphaPurple; | ||
float angles[9]; | ||
float time, errorFactor, alpha, limitS0, limitS1, limitS2; | ||
|
||
glm::vec3 pink_position_end, blue_position_end, yellow_position_end, target, red_position_end; | ||
|
||
bool stop, positionChanged; | ||
|
||
|
||
|
||
private: | ||
glm::mat4 m_yellow_mat; | ||
glm::mat4 m_pink_mat; | ||
glm::mat4 m_target_mat; | ||
|
||
glm::mat4 m_blue_mat; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#pragma once | ||
|
||
#include <algorithm> | ||
|
||
#define GLM_ENABLE_EXPERIMENTAL | ||
#include <GL/glew.h> | ||
#include <glm/glm.hpp> | ||
#include <glm/gtc/matrix_transform.hpp> | ||
|
||
enum Camera_Movement { | ||
FORWARD, | ||
BACKWARD, | ||
LEFT, | ||
RIGHT, | ||
UP, | ||
DOWN, | ||
ROTATE_X_UP, | ||
ROTATE_X_DOWN, | ||
ROTATE_Y_UP, | ||
ROTATE_Y_DOWN, | ||
ROTATE_Z_UP, | ||
ROTATE_Z_DOWN, | ||
}; | ||
|
||
class Camera { | ||
public: | ||
// Camera view parameters | ||
glm::vec3 ori_position; | ||
glm::vec3 ori_front; | ||
glm::vec3 ori_up; | ||
glm::vec3 ori_right; | ||
|
||
glm::vec3 position; | ||
glm::vec3 front; | ||
glm::vec3 up; | ||
glm::vec3 right; | ||
|
||
// Camera projection parameters | ||
float ori_zoom; | ||
float zoom; | ||
|
||
float near; | ||
float far; | ||
|
||
unsigned int width; | ||
unsigned int height; | ||
|
||
// Camera projection matrix: used for projection | ||
glm::mat4 proj_mat; | ||
|
||
// Camera view matrix: used for changing camera rotation and position | ||
glm::mat4 view_mat; | ||
|
||
// Camera parameter initialization | ||
Camera( | ||
glm::vec3 position_ = glm::vec3(0, 5, 20), | ||
glm::vec3 front_ = glm::vec3(0, 0, -1), | ||
glm::vec3 up_ = glm::vec3(0, 1, 0), | ||
glm::vec3 right_ = glm::vec3(1, 0, 0), | ||
float zoom_ = 45.0, | ||
float near_ = 0.1, | ||
float far_ = 100, | ||
unsigned int width_ = 1600, | ||
unsigned int height_ = 900 | ||
) | ||
{ | ||
this->ori_position = position_; | ||
this->ori_front = front_; | ||
this->ori_up = up_; | ||
this->ori_right = right_; | ||
this->ori_zoom = zoom_; | ||
this->near = near_; | ||
this->far = far_; | ||
this->width = width_; | ||
this->height = height_; | ||
} | ||
|
||
void init() { | ||
reset(); | ||
}; | ||
|
||
void reset() { | ||
this->position = ori_position; | ||
|
||
this->front = ori_front; | ||
this->up = ori_up; | ||
this->right = ori_right; | ||
this->zoom = ori_zoom; | ||
} | ||
|
||
void process_keyboard(Camera_Movement direction, float delta_time) | ||
{ | ||
float move_velocity = delta_time * 10; | ||
float rotate_velocity = delta_time * 50; | ||
|
||
if (direction == FORWARD) | ||
this->position += this->front * move_velocity; | ||
if (direction == BACKWARD) | ||
this->position -= this->front * move_velocity; | ||
if (direction == LEFT) | ||
this->position -= this->right * move_velocity; | ||
if (direction == RIGHT) | ||
this->position += this->right * move_velocity; | ||
if (direction == UP) | ||
this->position += this->up * move_velocity; | ||
if (direction == DOWN) | ||
this->position -= this->up * move_velocity; | ||
if (direction == ROTATE_X_UP) | ||
rotate_x(rotate_velocity); | ||
if (direction == ROTATE_X_DOWN) | ||
rotate_x(-rotate_velocity); | ||
if (direction == ROTATE_Y_UP) | ||
rotate_y(rotate_velocity); | ||
if (direction == ROTATE_Y_DOWN) | ||
rotate_y(-rotate_velocity); | ||
if (direction == ROTATE_Z_UP) | ||
rotate_z(rotate_velocity); | ||
if (direction == ROTATE_Z_DOWN) | ||
rotate_z(-rotate_velocity); | ||
} | ||
|
||
// Rotate specific angle along local camera system(LCS) | ||
void rotate_x(float angle) | ||
{ | ||
glm::vec3 up = this->up; | ||
glm::mat4 rotation_mat(1); | ||
rotation_mat = glm::rotate(rotation_mat, glm::radians(angle), this->right); | ||
this->up = glm::normalize(glm::vec3(rotation_mat * glm::vec4(up, 1.0))); | ||
this->front = glm::normalize(glm::cross(this->up, this->right)); | ||
} | ||
|
||
void rotate_y(float angle) | ||
{ | ||
glm::vec3 front = this->front; | ||
glm::mat4 rotation_mat(1); | ||
rotation_mat = glm::rotate(rotation_mat, glm::radians(angle), this->up); | ||
this->front = glm::normalize(glm::vec3(rotation_mat * glm::vec4(front, 1.0))); | ||
this->right = glm::normalize(glm::cross(this->front, this->up)); | ||
} | ||
|
||
void rotate_z(float angle) | ||
{ | ||
glm::vec3 right = this->right; | ||
glm::mat4 rotation_mat(1); | ||
rotation_mat = glm::rotate(rotation_mat, glm::radians(angle), this->front); | ||
this->right = glm::normalize(glm::vec3(rotation_mat * glm::vec4(right, 1.0))); | ||
this->up = glm::normalize(glm::cross(this->right, this->front)); | ||
} | ||
|
||
// Get camera view matrix | ||
glm::mat4 get_view_mat() | ||
{ | ||
this->view_mat = glm::lookAt(this->position, this->position + this->front, this->up); | ||
return this->view_mat; | ||
} | ||
|
||
// Get camera projection matrix | ||
glm::mat4 get_projection_mat() | ||
{ | ||
this->proj_mat = glm::perspective(this->zoom, (float)this->width / (float)this->height, this->near, this->far); | ||
return this->proj_mat; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#pragma once | ||
|
||
#define GLM_ENABLE_EXPERIMENTAL | ||
#include <glm/glm.hpp> | ||
#include <glm/gtc/matrix_transform.hpp> | ||
#include <glm/gtc/type_ptr.hpp> | ||
|
||
class Lighting { | ||
|
||
struct Direction_Light { | ||
|
||
bool status; | ||
glm::vec3 direction; | ||
|
||
glm::vec4 ambient; | ||
glm::vec4 diffuse; | ||
glm::vec4 specular; | ||
|
||
}; | ||
|
||
|
||
struct Point_Light { | ||
|
||
bool status; | ||
glm::vec3 position; | ||
float constant; | ||
float linear; | ||
float quadratic; | ||
|
||
glm::vec4 ambient; | ||
glm::vec4 diffuse; | ||
glm::vec4 specular; | ||
|
||
}; | ||
|
||
public: | ||
|
||
Direction_Light direction_light; | ||
Point_Light point_light; | ||
|
||
Lighting() { | ||
|
||
} | ||
|
||
~Lighting() {} | ||
|
||
void init() | ||
{ | ||
direction_light.status = true; | ||
direction_light.direction = glm::vec3(-1.0f, -1.0f, -1.0f); | ||
direction_light.ambient = glm::vec4(0.5f, 0.5f, 0.5f, 1.0f); | ||
direction_light.diffuse = glm::vec4(0.6f, 0.6f, 0.6f, 1.0f); | ||
direction_light.specular = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); | ||
|
||
point_light.status = true; | ||
point_light.position = glm::vec3(1.2f, 1.0f, 2.0f); | ||
point_light.ambient = glm::vec4(0.1f, 0.1f, 0.1f, 1.0f); | ||
point_light.diffuse = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); | ||
point_light.specular = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); | ||
point_light.constant = 1.0f; | ||
point_light.linear = 0.09f; | ||
point_light.quadratic = 0.032f; | ||
}; | ||
}; |
Oops, something went wrong.