Migrating from MDX

Started by
0 comments, last by theblackdesert 12 years, 2 months ago
I got the quest to migrate an MDX Apllication to SlimDX in order to make it work with .NET 4.0.
Im almost finished without understanding DirectX completely ( I will do so after fixing this last problem ) per se. But there is a last problem using Vector3.Project/Unproject Matrix.Multiply or something else im not sure (i wouldnt ask i if knew wheres the problem).

The Problem is:
Im rendering black Text boxes.
createWorldMatrix() generates the WorldMatrix for each TextComponent but when i start to turn the scene the text starts to hop up and down.

I think the first part of my code is correct:
Matrix mScaling = Matrix.Scaling (scaling, scaling, scaling);
Matrix mRotation = TransformUtilities.GetRotationMatrixFromDirectionUpVector(-1.0f * camera.Direction, camera.UpVector);
Matrix mTranslation = Matrix.Translation(textPosition);
Matrix mWorld = mScaling;
mWorld = Matrix.Multiply(mWorld, mRotation);
mWorld = Matrix.Multiply(mWorld, mTranslation);
MoveTextDirections dir = MoveTextDirections.None;
Rectangle tRect = transformTextRectangle (_device, mWorld);


This places the TextComponents on the right place ().
Then there is an Algorhitm which moves tRect until it fits with the other TextRectangles using .NET Standard classes so the problem wont be there.

Then there is the following code which seems to include the error:

//####Just for style-reasons####
Matrix WorldViewProjection = device.GetTransform(TransformState.World) * device.GetTransform(TransformState.View) * device.GetTransform(TransformState.Projection);
int Width = device.Viewport.Width; int Height = device.Viewport.Height;
int ViewportX = device.Viewport.X; int ViewportY = device.Viewport.Y;
float MinZ = device.Viewport.MinZ; float MaxZ = device.Viewport.MaxZ;
//##############################
Vector3 rCenterScreen = new Vector3(tRect.Left + tRect.Width / 2, tRect.Top + tRect.Height / 2, 0.0f);
Vector3 rCenterWorld = Vector3.Unproject(rCenterScreen, ViewportX, ViewportY, Width, Height, MinZ, MaxZ, WorldViewProjection);
rCenterWorld = Vector3.TransformCoordinate(rCenterWorld, mWorld);
Vector3 rCamScreen = new Vector3(tRect.Left + tRect.Width / 2, tRect.Top + tRect.Height / 2, -1.0f);
Vector3 rCamWorld = Vector3.Unproject(rCamScreen, ViewportX, ViewportY, Width, Height, MinZ, MaxZ, WorldViewProjection);
rCamWorld = Vector3.TransformCoordinate(rCamWorld, mWorld);
Plane pText = DirectXConverter.PlaneFromPointNormal(textPosition, camera.Direction);
textPosition = DirectXConverter.PlaneIntersectLine(pText, rCenterWorld, rCamWorld);
mTranslation = Matrix.Translation(textPosition);
mWorld = mScaling;
mWorld = Matrix.Multiply(mWorld, mRotation);
mWorld = Matrix.Multiply(mWorld, mTranslation);
return mWorld;


The Text is on the right start position if i comment the algorhythm and the 2nd code out.
Im gonna add the original source before i started migrating. Please say if you need more information and what information is needed. The Debugoutput gives me nothing useable.
Im sorry for my Bad English/

Original Source: http://pastebin.com/ZrviCsSF
Advertisement
Problem solved:

I used Device.GetTransform(TransformState.World) instead of my mWorld in the Unproject Method...

silly me..

This topic is closed to new replies.

Advertisement