I'm trying to write a physics simulator in c++ with opengl and I need to be able to scale objects (mostly cubes right now) along the axis that the camera is facing.
I can draw objects perfectly fine using this as my Model Matrix:
mat4 Model = Translate(cube.Position - float3(gl.Position.x, gl.Position.y, -gl.Position.z)) * Rotate(cube.Rotation) * Scale(cube.Scale);
Where gl.Position is the cam's position, float3 is a vec3 like class I wrote, etc...
So i tried to modify that line to include a scaling factor before all else (where stuff at the end is applied first):
mat4 Model = Translate(cube.Position - float3(gl.Position.x, gl.Position.y, -gl.Position.z)) * Rotate(cube.Rotation) * Scale(cube.Scale) * (Rotate(float3(gl.Rotation.x, gl.Rotation.y, gl.Rotation.z)) * Scale(float3(1.0f, 1.0f, sqrt(1 - (velocity * velocity)))) * Rotate(float3(tau - gl.Rotation.x, tau - gl.Rotation.y, tau - gl.Rotation.z)));
It's the last part that is important, where I rotate the object, scale it, then rotate it back.. the sqrt(1 - (velocity * velocity)) is the physics part (Lorentz contraction) and gl.Rotation is a vec3 where each axis holds the pitch, yaw, and roll in radians of the cam. My translate, rotate, etc. functions work properly, but I need help with the theory of creating a matrix to scale.