I have a tabletop that can rotate around OX and OZ axis and a ball on this tabletop. I need to have the ball moving around the plane accordingly to its tilt. The ball does not need to have acceleration (velocity is constant at a certain tilt).
Here is how I want the ball to move.
The sphere mesh is created like this:
{
glm::mat4 modelMatrix = glm::mat4(1);
modelMatrix = glm::translate(modelMatrix, glm::vec3(speedOX, speedOY + 0.5f, speedOZ));
RenderSimpleMesh(meshes["sphere"], shaders["ShaderLab8"], modelMatrix, glm::vec3(0, 1, 1));
}
Where speedOX speedOY speedOZ is the translation vec3 for the sphere.
The plane mesh is created like this
{
glm::mat4 modelMatrix = glm::mat4(1);
modelMatrix = glm::translate(modelMatrix, glm::vec3(0, 0.01f, 0));
modelMatrix = glm::rotate(modelMatrix, RADIANS(anglePlaneOX), glm::vec3(1, 0, 0));
modelMatrix = glm::rotate(modelMatrix, RADIANS(anglePlaneOY), glm::vec3(0, 1, 0));
modelMatrix = glm::rotate(modelMatrix, RADIANS(anglePlaneOZ), glm::vec3(0, 0, 1));
modelMatrix = glm::scale(modelMatrix, glm::vec3(0.125f));
RenderSimpleMesh(meshes["plane"], shaders["ShaderLab8"], modelMatrix, glm::vec3(0.5, 0.5, 0.5));
}
The plane moves by hitting WASD keys.
if (window->KeyHold(GLFW_KEY_W) && (anglePlaneOX > -90.0f)) {
anglePlaneOX -= deltaTime * DELTA_SLOPE;
/*update speedOX speedOY speedOZ */
}
if (window->KeyHold(GLFW_KEY_S) && (anglePlaneOX < 90.0f)) {
anglePlaneOX += deltaTime * DELTA_SLOPE;
/*update speedOX speedOY speedOZ */
}
if (window->KeyHold(GLFW_KEY_D) && (anglePlaneOZ > -90.0f)) {
anglePlaneOZ -= deltaTime * DELTA_SLOPE;
/*update speedOX speedOY speedOZ */
}
if (window->KeyHold(GLFW_KEY_A) && (anglePlaneOZ < 90.0f)) {
anglePlaneOZ += deltaTime * DELTA_SLOPE;
/*update speedOX speedOY speedOZ */
}
I couldn't really find the math behind moving the ball accordingly to the tilt of the plane.
Note: the ball does not to rotate per se as I'm not doing any crazy shadowing over the ball. I just want it move (translate) on the moving plane. Also it seems that the ball "sinks" a bit in the plane as showed in the image.