Question: Please help: add rotation animation to the blocks by using the animation transform. The center of rotation for each block should be the center of

Please help:
add rotation animation to the blocks by using the animation transform.
The center of rotation for each block should be the center of the block
The block at (-.5,-.5,0) should rotate 30\deg each second around the y axis
The block at (-.5,.5,0) should rotate 60\deg each second around the z-axis
The block at (.5,-.5,0) should rotate 90\deg each second around the x axis
The block at (.5,.5,0) should rotate 120\deg each second around the y axis
Source code given:
#include "GLM/gtc/type_ptr.hpp"
#include
#include "learnopengl/shader_4722.h"
#include "cs4722/artifact.h"
#include "cs4722/window.h"
#include "cs4722/buffer_utilities.h"
static std::vector artifact_list;
static Shader *shader;
void init()
{
shader = new Shader("../01-more-shapes/vertex_shader.glsl",
"../01-more-shapes/fragment_shader.glsl");
shader->use();
glEnable(GL_PROGRAM_POINT_SIZE);
glEnable(GL_DEPTH_TEST);
cs4722::Shape* b = new cs4722::Block();
// Define transformation for each artifact
std::vector positions ={
glm::vec3(-0.5f,-0.5f,0.0f),
glm::vec3(-0.5f,0.5f,0.0f),
glm::vec3(0.5f,-0.5f,0.0f),
glm::vec3(0.5f,0.5f,0.0f)
};
std::vector rotations ={
glm::vec3(45.0f,0.0f,0.0f),// Rotate 45 degrees around the x-axis
glm::vec3(0.0f,315.0f,0.0f),// Rotate 315 degrees around the y-axis
glm::vec3(0.0f,0.0f,90.0f),// Rotate 90 degrees around the z-axis
glm::vec3(270.0f,0.0f,0.0f)// Rotate 270 degrees around the x-axis
};
// Loop to create four artifacts
for (int i =0; i <4; i++)
{
// Create a transformation object
auto transformation = new cs4722::TransformationAnimationRotating();
transformation->multiplyScale(.75f,.25f,.5f);
// Set position for each artifact
transformation->multiplyTranslation(positions[i].x, positions[i].y, positions[i].z);
// Apply rotation for each artifact
transformation->multiplyRotation(rotations[i].x, glm::vec3(1,0,0)); // Rotate around x-axis
transformation->multiplyRotation(rotations[i].y, glm::vec3(0,1,0)); // Rotate around y-axis
transformation->multiplyRotation(rotations[i].z, glm::vec3(0,0,1)); // Rotate around z-axis
auto* artf = new cs4722::Artifact(transformation);
artf->theShape = b;
artifact_list.push_back(artf);
}
cs4722::initBuffers(shader->ID, artifact_list, "b_position", "b_color");
}
void render()
{
for (auto artf : artifact_list){
auto model_matrix = artf->worldTransformation->getMatrix();
shader->setMat4("u_transform", model_matrix);
glDrawArrays(GL_TRIANGLES, artf->theShape->bufferStart, artf->theShape->bufferSize);
}
}
int main()
{
glfwInit();
cs4722::setOpenglVersion(3,3);
GLFWwindow* window = cs4722::setupWindow("More Shapes", .6,1);
glfwMakeContextCurrent(window);
gladLoadGL(glfwGetProcAddress);
init();
while (!glfwWindowShouldClose(window))
{
glClearBufferfv(GL_COLOR, 0, cs4722::X11::gray50.asFloatArray());
glClear(GL_DEPTH_BUFFER_BIT);
render();
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!