Hello
Looking for some good ideas for the problem below.
Currently I have a lot of data that is being manipulated and stored in the final std::vector (cuboids with different set of coordinates).
Then I use OpenGl to create the models and can view them.
1 2 3 4 5 6 7 8 9 10 11 12
for (int32_t i = 0; i < unitBox.number_of_polymers(); i++)
{
for (int32_t j = 0; j < unitBox.polymer(i).number_of_monomers(); j++)
{
float rx, ry, rz, teta;
unitBox.polymer(i).get_rotation(rx, ry, rz, teta, j);
float x, y, z;
unitBox.polymer(i).position(x, y, z, j);
glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(x, y, z))* glm::rotate(glm::mat4(1.0f), teta, glm::vec3(rx, ry, rz)) * glm::scale(glm::mat4(1.0f),glm::vec3(unitBox.polymer(i).monomer(j).length(), unitBox.polymer(i).monomer(j).width(), unitBox.polymer(i).monomer(j).height()));
modelMatrices.push_back(model);
}
}
Now it would be very convenient to see the dynamics of how the data of unitBox is changing over time. What could be the simple approaches to achieve this? For example, is it possible to make a copies of UnitBox during the calculation, and then source OpenGl with vector of UnitBox'es so it could run every each of them as frame?
Thanks,
I don't have experience in OpenGL, so grain of salt, but it looks like your above code is creating a model object with a given amount of rotational positions (rx, ry, rz) provided by a unitBox object.
From there, place your code inside another loop that controls time, call each of these outer loops a frame. (To save on CPU load, it is a good idea to use a delay mechanism such as SDL_Delay(), or whatever your window creator has to offer to sync to a desired frame rate).
Create three new variables in unitBox for rotational speed in (x, y, z), then add the respective speeds to the rotational position of the unitBox's rx, ry, rz variables each frame until your desired rotation is hit.
Make sure the speed is slow enough that it takes 60 or so frames to reach your desired rotation.
Something like speedRX = desiredDeltaRotationX/(60.0f * desiredTimeInSeconds);
This also makes certain that all rotations reach their goal at the same time.
After you have that working, it would also be nice to apply acceleration over time...
I would tend toward trashing the old vector of data from previous frames, it is useful if all you want is to repeat the same rotation over and over, but if you're allowing the viewer to modify the rotation, scale, and position of the object such as in a game, then the old data will be changed randomly and often enough that holding on to the old data just causes a memory leak.