find the center of the rotated cube c++/glm

I have a cube and I need to find its center after the rotation has been applied. So as you can see, my idea is to find the center point of that figure, and rotate that point, and get then its coordinates. But the results are incorrect. Where is my mistake / misunderstanding? Thanks,

1
2
3
4
5
6
7
8
9
10
11
12
13
void
    Cube::position_center(float& cx, float& cy, float& cz) const
    {
// finding the center of the stationary cube     
    cx = _origin_x + 0.5 * _cube.length();
    cy = _origin_y + 0.5 * _cube.width();
    cz = _origin_z + 0.5 * _cube.height();
//applying rotation to that point
    glm::mat4 rot_mat = glm::rotate(glm::mat4(1.0f), 1.0f, glm::vec3 (1.0f, 1.0f, 0.0f));
    glm::vec3 point = glm::vec3(glm::vec4(glm::vec3 (cx, cy, cz), 0.0f) * rot_mat);
    cx = point.x;
    cy = point.y;
    cz = point.z;}
> But the results are incorrect.
provide a testcase: input, current output, expected output.

¿what's your cube representation? ¿one point and a length? ¿eight points? ¿four?


> I have a cube and I need to find its center after the rotation has been applied.
you are trying to do too many things at once
¿why does `postion_center()' rotate a point?

apart, ¿how do you choose the rotation angle/axis? ¿does it pass by {0,0,0} or do you also translate it?
I don't remember much GL but the center of a cube that didn't move wouldn't change.
Also posted here: https://stackoverflow.com/questions/66535518/find-the-center-of-the-rotated-cube-c-glm
Sounds like some sort of translation is happening in addition to the rotation.
Please provide a testcase like ne555 said.

The axis of rotation (normal) is glm::vec3 (1.0f, 1.0f, 0.0f) in the code.
https://glm.g-truc.net/0.9.3/api/a00199.html

(On an unrelated note, the glm website's naming scheme is awful.)
Last edited on
Topic archived. No new replies allowed.