Map not updating correctly with camera

Started by
-1 comments, last by ChristianFrantz 10 years, 9 months ago

As of yesterday, I've rewritten my whole method of drawing cubes and chunks so I can get some culling to work. Both frustum and occlusion culling work fine, but so much has changed in the code that when I move the player, the camera doesn't look right at all. Before all the changes, my third person camera worked fine. Nothing has changed within my player or camera class. My player model is just a sphere right now, so nothing too confusing.

Imagine a first person camera with it's crosshairs. My player model would be the crosshairs of that camera. You can move around the map as if you're using a first person camera, but the sphere is always drawn behind the map so you can rarely see it. I don't know why this is happening, but I'm pretty sure it's because of some of the matrices used in the new class. Normally with a third person camera, you'd press left or right and the camera would rotate around the player without actually moving the player. This isn't happening anymore


WorldMatrix = Matrix.CreateWorld(Vector3.Zero, Vector3.Forward, Vector3.Up);    //Quad's created position and scale.
            WorldMatrix *= Matrix.CreateScale(VoxelScale);                                  //Resize the quad to match defined scale.

            TopQuadWorldMatrix = WorldMatrix * Matrix.CreateTranslation(new Vector3(0f, VoxelScale / 2, 0f));
            BottomQuadWorldMatrix = WorldMatrix * Matrix.CreateRotationX(MathHelper.Pi) * Matrix.CreateTranslation(new Vector3(0f, -VoxelScale / 2, 0f));
            FarQuadWorldMatrix = WorldMatrix * Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateTranslation(new Vector3(0f, 0f, -VoxelScale / 2));
            NearQuadWorldMatrix = WorldMatrix * Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateTranslation(new Vector3(0f, 0f, VoxelScale / 2));
            LeftQuadWorldMatrix = WorldMatrix * Matrix.CreateRotationZ(MathHelper.PiOver2) * Matrix.CreateTranslation(new Vector3(-VoxelScale / 2, 0f, 0f));
            RightQuadWorldMatrix = WorldMatrix * Matrix.CreateRotationZ(-MathHelper.PiOver2) * Matrix.CreateTranslation(new Vector3(VoxelScale / 2, 0f, 0f));

Matrices used to draw the cubes.


 Effect.Projection = CamerasProjectionMatrix;
            Effect.View = CamerasViewMatrix;

These two lines are in my draw method of the cubes class. Both the variables are set in the update method of my main game class:


CubeGrid.ProjectionMatrix = Camera.proj;
            CubeGrid.ViewMatrix = Camera.view;
            CubeGrid.CamerasViewFrustrum = Camera.frustum;

As you can see, there's a lot going on in this new class and there may be more than one error that I can't find.

If you see a post from me, you can safely assume its C# and XNA :)

This topic is closed to new replies.

Advertisement