Home Game Development c# – Include camera movement and calculation in the 3D game

c# – Include camera movement and calculation in the 3D game

0
c# – Include camera movement and calculation in the 3D game

[ad_1]

I was sent here by softwareengineering.stackexchange.com.

I am writing a WinForms .NET application using C#. I use SkiaSharp for drawing for performance reasons.

I can already create a cuboid, rotate it, project its points, and draw. For this, I use the approach that I have a “window” on which the light beams of the rotated solid behind it hit. In front of the window is a camera. This is supposed to be a 1st person camera.
Here the projection formula:

SKPoint projected = new SKPoint(Convert.ToSingle((CameraPos.x - WindowPos.x) / (CameraPos.x - rotatedVector.x) * rotatedVector.y),
                                Convert.ToSingle((CameraPos.x - WindowPos.x) / (CameraPos.x - rotatedVector.x) * (-rotatedVector.z)));

I use many, many vectors for this. The vectors are sorted from back to front before projecting and drawing.

My question to you is that I now want to move and rotate the camera (that works) and accordingly the world changes with it. One sees then other things and the things differently. What is the formula for this?

In and of itself, I have no difficulty or panic about math and vectors – I just want it to be right in the end.

For testing, I’m using this online tool, where

quader(-1|-2|0 1|4|2){00b800}

vektor(7|0|1 -7|2|1){0091ff}
vektor(7|0|1 -7|2|-1){0091ff}
vektor(7|0|1 -7|-2|1){0091ff}
vektor(7|0|1 -7|-2|-1){0091ff}

vektor(5|5|1 -5|-7|1){ff006a}
vektor(5|5|1 -5|-7|-1){ff006a}
vektor(5|5|1 -5|-3|1){ff006a}
vektor(5|5|1 -5|-3|-1){ff006a}
vektor(5|5|1 -6|-3|-1){000000}
vektor(5|5|1 -6|-3|1){000000}

Imagine standing at position one, where the light blue arrows start from. I’m looking straight at the body. But if you move and rotate the camera, you’ll look like I illustrated the magenta arrows. Now you can even see one side of the box that was not visible from position 1. Besides, the cuboid is crooked as seen from position 2. I can’t find the formula to calculate the whole thing.

Online tool for demo purposes
Online tool for demo purposes

[ad_2]