# Relative to the Camera

This topic is 2035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello.

Im working on a Procedural Planet, but i have (like all the others) floating precision problems.

So i read this great Article (http://britonia.wordpress.com/2009/05/23/scale-and-32-bit-imprecision/).

This guy told me i render everything relative to the Camera (That means, the Camera Position is always at Vector3.Zero)

The first deviation is, i generate the Sphere with the Mathlab funktion (http://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html), so the sphere-center must always stay at the World Origin (0,0,0).

Britonia say i should create a new Worldmatrix with  position - cameraPosition, but here this function from Mathproofs doesen't match not longer..

So i build a second "WorldMatrix"

worldNew = Matrix.CreateTranslation(position - cam.Position) * Matrix.CreateFromYawPitchRoll(cam.deltaX * 0.0005f, cam.deltaY * 0.0005f, 0);


So i multiply this new Matrix in the Shader with the View matrix like:

float4x4 xx = mul(View, worldNew);


and now the output.Position is:

output.Position = mul(mul(scaled, xx), Projection);


------------------------------

So it works, the Camera is at 0,0,0 and my Planet are in front of me.

Now the problem join in:

Before i move the Camera to look/move around.

Now instead to move the Camera i must move the Object in the Scene (in my case the Planet)

  private void MoveForwBackw(float amount)
{
Forward.Normalize();
Position += Forward * amount;
}

private void MoveLeftRight(float amount)
{
Right = Vector3.Cross(Up, Forward);
Right.Normalize();
Position += Right * amount;
}


Forward, Backward, Left, Right work fine, but when the Mouse come in, the Y Axis on my Camera is always Zero  (i mean the Camera don't follow the perspective of my mouse.

here at 0:10sec:

The View Matrix is:

View = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);


So whats my line, somebody have an idea how to fix this Problem, maybe i need a Forward and Upvector for my ViewMatrix?

Or anybody has another option to solve the floating imprecision?

best regards

Edited by montify

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 9
• 11
• 15
• 21
• 26