Add head rotation
This commit is contained in:
parent
f8fe94529f
commit
7b82b5c386
14
src/cv.cpp
14
src/cv.cpp
|
@ -62,17 +62,29 @@ void cvFrame() {
|
|||
|
||||
//send control information to graphics
|
||||
float faceSize = landmarks[biggestFace][14].x - landmarks[biggestFace][2].x;
|
||||
updateModel(glm::vec2(
|
||||
updateModel(
|
||||
//head position
|
||||
glm::vec2(
|
||||
(landmarks[biggestFace][2].x + landmarks[biggestFace][14].x) / 2
|
||||
* 2 / (float)frame.cols - 1,
|
||||
(landmarks[biggestFace][2].y + landmarks[biggestFace][14].y) / 2
|
||||
* 2 / (float)frame.rows - 1
|
||||
),
|
||||
|
||||
//face position
|
||||
glm::vec2(
|
||||
landmarks[biggestFace][30].x * 2 / (float)frame.cols - 1,
|
||||
landmarks[biggestFace][30].y * 2 / (float)frame.rows - 1
|
||||
),
|
||||
|
||||
//rotation
|
||||
atanf((float)(landmarks[biggestFace][14].y - landmarks[biggestFace][2].y) /
|
||||
(float)(landmarks[biggestFace][2].x - landmarks[biggestFace][14].x)),
|
||||
|
||||
//scale
|
||||
faceSize * 6 / (float)frame.cols,
|
||||
|
||||
//mouth open/closed state
|
||||
(landmarks[biggestFace][66].y - landmarks[biggestFace][62].y) / faceSize > 0.04f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,11 +175,11 @@ void initModel () {
|
|||
|
||||
}
|
||||
|
||||
void updateModel(glm::vec2 headPos, glm::vec2 facePos, float scale, bool mouthOpen) {
|
||||
void updateModel(glm::vec2 headPos, glm::vec2 facePos, float rotation, float scale, bool mouthOpen) {
|
||||
//calculate transforms
|
||||
parts[0].setTransform(headPos, scale);
|
||||
parts[1].setTransform(facePos, scale);
|
||||
parts[2].setTransform(facePos, scale);
|
||||
parts[0].setTransform(headPos, rotation, scale);
|
||||
parts[1].setTransform(facePos, rotation, scale);
|
||||
parts[2].setTransform(facePos, rotation, scale);
|
||||
|
||||
//set mouth texture to open or closed
|
||||
parts[2].selectTexture(mouthOpen ? 1 : 0);
|
||||
|
|
|
@ -16,6 +16,6 @@ void initShader();
|
|||
|
||||
void printShaderCompileLog(GLuint shader);
|
||||
|
||||
void updateModel(glm::vec2 headPos, glm::vec2 facePos, float scale, bool mouthOpen);
|
||||
void updateModel(glm::vec2 headPos, glm::vec2 facePos, float rotation, float scale, bool mouthOpen);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,8 +29,9 @@ void ModelPart::bindAndDraw() {
|
|||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
void ModelPart::setTransform(glm::vec2 position, float scale) {
|
||||
void ModelPart::setTransform(glm::vec2 position, float rotation, float scale) {
|
||||
transMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(position.x, -position.y, 0.0f));
|
||||
transMatrix = glm::rotate(transMatrix, rotation, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
transMatrix = glm::scale(transMatrix, glm::vec3(scale, scale, scale));
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class ModelPart {
|
|||
|
||||
void bindAndDraw();
|
||||
|
||||
void setTransform(glm::vec2 position, float scale);
|
||||
void setTransform(glm::vec2 position, float rotation, float scale);
|
||||
|
||||
void addTexture(const char* texPath, size_t slot);
|
||||
|
||||
|
|
Loading…
Reference in a new issue