• Create Account

## Relative to the Camera

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1montify  Members

592
Like
0Likes
Like

Posted 27 March 2014 - 12:31 PM

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, 27 March 2014 - 12:47 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.