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 should rotate deg each second around the y axis
The block at should rotate deg each second around the zaxis
The block at should rotate deg each second around the x axis
The block at should rotate deg each second around the y axis
Source code given:
#include GLMgtctypeptrhpp
#include
#include "learnopenglshaderh
#include csartifacth
#include cswindowh
#include csbufferutilities.h
static std::vector artifactlist;
static Shader shader;
void init
shader new Shadermoreshapesvertexshader.glsl
moreshapesfragmentshader.glsl;
shaderuse;
glEnableGLPROGRAMPOINTSIZE;
glEnableGLDEPTHTEST;
cs::Shape b new cs::Block;
Define transformation for each artifact
std::vector positions
glm::vecfff
glm::vecfff
glm::vecfff
glm::vecfff
;
std::vector rotations
glm::vecfff Rotate degrees around the xaxis
glm::vecfff Rotate degrees around the yaxis
glm::vecfff Rotate degrees around the zaxis
glm::vecfff Rotate degrees around the xaxis
;
Loop to create four artifacts
for int i ; i ; i
Create a transformation object
auto transformation new cs::TransformationAnimationRotating;
transformationmultiplyScalefff;
Set position for each artifact
transformationmultiplyTranslationpositionsix positionsiy positionsiz;
Apply rotation for each artifact
transformationmultiplyRotationrotationsix glm::vec; Rotate around xaxis
transformationmultiplyRotationrotationsiy glm::vec; Rotate around yaxis
transformationmultiplyRotationrotationsiz glm::vec; Rotate around zaxis
auto artf new cs::Artifacttransformation;
artftheShape b;
artifactlist.pushbackartf;
cs::initBuffersshaderID artifactlist, bposition", bcolor";
void render
for auto artf : artifactlist
auto modelmatrix artfworldTransformationgetMatrix;
shadersetMatutransform", modelmatrix;
glDrawArraysGLTRIANGLES, artftheShapebufferStart, artftheShapebufferSize;
int main
glfwInit;
cs::setOpenglVersion;
GLFWwindow window cs::setupWindowMore Shapes", ;
glfwMakeContextCurrentwindow;
gladLoadGLglfwGetProcAddress;
init;
while glfwWindowShouldClosewindow
glClearBufferfvGLCOLOR, cs::X::grayasFloatArray;
glClearGLDEPTHBUFFERBIT;
render;
glfwSwapBufferswindow;
glfwPollEvents;
glfwDestroyWindowwindow;
glfwTerminate;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
