   Looking for Proper Transformation Matrix (c#)
  I''m developing a space sim in managed directx (c#) that takes place in the solar system. I want to leave the player at the origin, have him face 0,0,1 and rotate + translate the world around him. The reason I''m doing this is because of floating point innaccuracy - it''s really noticeable even near earth. It''s almost working perfectly. The only thing that doesn''t work is that the orientation of all the other objects in game don''t change. Here''s me code so far:   protected override void Update(){Int32 delta;Matrix transformation;lights = null;device = Kernel.Current.Device; // get a reference to the devicedelta = Environment.TickCount - lastTick;viewFrustum = Frustum.Empty;viewable = null;currentGameTime += TimeSpan.FromMilliseconds(delta * GAMESPEED);SetView();transformation = Matrix.Identity;transformation = Matrix.Multiply(transformation, Matrix.Invert(Matrix.Translation(Player.CurrentVehicle.CurrentPosition)));transformation = Matrix.Multiply(transformation, Matrix.Invert(Matrix.RotationQuaternion(Player.CurrentVehicle.CurrentRotation)));foreach (GameObject go in CurrentScene.GameObjects)go.CurrentPosition = Vector3.TransformCoordinate(go.CurrentPosition, transformation);Player.CurrentVehicle.CurrentPosition = Vector3.Empty;Player.CurrentVehicle.CurrentRotation = Quaternion.RotationYawPitchRoll(0,0,0);lastTick += delta;}private void SetView(){if (CurrentScene != null){    // Set up our view matrix. A view matrix can be defined given an eye point,// a point to lookat, and a direction for which way is up. Here, we set the// eye five units back along the z-axis and up three units, look at the // origin, and define "up" to be in the y-direction.Kernel.Current.Device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-20),  new Vector3(0,0,1), new Vector3(0,1,0));// For the projection matrix, we set up a perspective transform (which// transforms geometry from 3D view space to 2D viewport space, with// a perspective divide making objects smaller in the distance). To build// a perpsective transform, we need the field of view (1/4 pi is common),// the aspect ratio, and the near and far clipping planes (which define at// what distances geometry should be no longer be rendered).Kernel.Current.Device.Transform.Projection = Matrix.PerspectiveFovLH( FOV, device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight, 1.0f, Single.MaxValue);}} Unfortunately i''m *extremeley* bad with math. Any help would be greatly appreciated. 
  "I want to leave the player at the origin, have him face 0,0,1 and rotate + translate the world around him."Thats what the view matrix is for"The reason I'm doing this is because of floating point innaccuracy"I doubt what you're experiencing is floating point inaccuracy.Ok, transforms.  DirectX is always left to right so your translation should always be on the right of the rotation or after it.Model Transform = Scale * Rotation * TranslationYou've got a transform here with Trans^-1 * Rotation^-1.  Which is basicaly correct for a VIEW matrix, but you are only transforming object positions and not the objects themselves.Think of the viewing camera as just another object in the scene.  It has an orientation and a translation.  Maybe its tied to player.currentvehicle, so that the camera is positioned exactly at the play vehicle's position and orientation.cameratrans = rotation * translationor simply cameratrans = player.vehicle.transformNow all you have to do to is this:Kernel.Current.Device.Transform.View = cameratrans.inversewhich is the same as thisKernel.Current.Device.Transform.View = player.currentvehicle.transform.inverseSo you are not using the view matrix for what it was intended. If you do it this way, not only will object positions be transformed, but meshes will be oriented to look as if the vehicle was actually the camera you were looking through. Also, usually you will want an offset so that you can actually see your vehicle too:cameratrans = Matrix.Translation(0,0,10) * player.currentvehicle.transform;Since the translation is before the vehicle translation,  it translates in the vehicles object space.  So 10 z units always means 10 units behind (in a right handed coordinate system) the vehicle no matter how the vehicle is oriented or where it is at.  If you are using a left handed coordinate system and z points in the same direction your vehicle is pointing, you would translate by -10 z or whatever.One more thing.  Don't forget about the model transform.  This is supposed to be each game objects orientation before drawing the game object. so you want:foreach (GameObject go in CurrentScene.GameObjects){Kernel.Current.Device.Transform.Model =go.rotation * go.position// Draw here}Hope this helps [edited by - Ironpoint on February 16, 2004 9:43:00 PM];  Sorry, but it doesn''t help me one bit. In my game world, if the sun were to be at the center, earth would be at [2.3423492 * 10^8, 0, 1.47307888 * 10^9], which is beyond the range of floating point accuracy (I shudder to think what would happen at jupiter). Plus I''ve read in other threads that the best way to combat this is to leave the camera at the origin. i think what I''m looking for is an inverse of an arcball, but like I said math ain''t my bag. ;  So you want a full-scale simulation of the solar system that lets you specify your position to within like 1mm?! Well at the very least you might want to look at using doubles (or long 80bit floats) not floats and making a matrix system using this. But I doubt you can get enough accuracy if I''ve understand your plan correctly. You might need to measure distance using a segment:offset scheme. E.g one vector telling you the position to the nearest light minute and another telling you how far from that point you are in metres.Am I on the right frequency here? ;  Don''t forget, 200 bit precision is enough to specify any position within the knowns universe down to Planck length scale.;  It looks like you would benefit trom using doubles (~15 decimals of precision as opposed to ~7). OpenGL can handle them as far as I know.   [ Galactic Conquest | Bananas | My dead site | www.sgi.com | Goegel ] ;  What do you think the range of floating point accuracy is, anyway?