Draw a 3D cube at bottom left / Camera perspective follows


I am not 100% on how to structure this question, so I will give it a go and accept the flames that follow.

At present, I can easily draw a 3D cube at origin (0,0) with the camera directly in front. This gives the impression of a flat object, as you can not see the item as 3D. Performing rotation, the cube rotates and stops when it appears flat again.

I am trying to do all this, but I do not want the cube to draw at origin (0,0). I would love for it to draw in the bottom left area of the screen. I have tried doing transformations, and whilst this does move the cube, you can then see the cube is 3D, as the camera perspective has changed.

Moving the camera to match the new position of the cube, fixes the perspective issue, but the item then appears back at the origin.

Clearly I have no idea what I am doing.

All I want, is to draw a cube, that is 3D, but looks 2D, in the bottom left of the screen. Then, when I rotate the cube, it will rotate looking all 3D and amazing, but stop so the face showing looks 2D again.

If I have worded that in the worst way possible, I apologise! :slight_smile:

Edit 1: To add reason to my madness, the end goal is to draw different textures on the cube, and rotate to each texture. Sort of like how a playing card can be flipped. But not with a card texture. I would like to end up having multiple cubes at different locations, all with a camera perspective of being directly in front of each cube.

Edit 2: I have tried with Viewports and this did provide a result I was after. I am fairly sure that viewports are not the correct way to achieve this goal though. But happy to be told otherwise :slight_smile:

Edit 3: After further trial and error, I am more concrete that Viewports are in fact the way to solve this.




I think what you are looking for is Matrix.CreateOthographic(…)

if (UseOthorgraphic)
                projectionMatrix = Matrix.CreateScale(1, -1, 1) * Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, FarClipPlane); // FarClipPlane here is distance in depth you can see
                projectionMatrix = Matrix.CreatePerspectiveFieldOfView(fovInDegrees * (float)((3.14159265358f) / 180f), gd.Viewport.Width / gd.Viewport.Height, NearClipPlane, FarClipPlane);

Are you drawing the cubes with spriteBatch or using a custom effect ?
Do the cube images need to be continuous or are they all separate individual images ?