I'm currently trying to create a camera and entity/model matrix for my 2D game similar to that of Unity3D. I've already tried to find answers to this question on stackoverflow/gamedev but i couldn't find an answer that explains how to center the camera and image.
- Have a camera matrix wich is centered at the position of the camera.
- Have a entity matrix wich draws everything centered
camera: matrix = Matrix.translation(Screen.width * 0.5, Screen.height * 0.5) * Matrix.rotation(camera.rotation_radians) * Matrix.scale(camera.scale.x, camera.scale.y) * Matrix.translation(camera.x, camera.y); entity: matrix = Matrix.rotation(entity.rotation_radians) * Matrix.scale(entity.scale.x, entity.scale.y) * Matrix.translation(entity.x, entity.y); image component draw function: setMatrix(camera.matrix * entity.matrix); drawImage(x=0, y=0, image) // position is already included in the entity matrix
- Image rotates around the upper-left corner of the screen not around it's center
- Image is not centered. The image's origin is at its upper-left corner.
- The camera matrix seems to be correct.
- What is the correct multiplication order for the entity/model matrix?
- Can i use a single matrix for all components of a entity or do i need to calculate in the width/height of the image/text/animation component.