Jump to content

  • Log In with Google      Sign In   
  • Create Account

Migrating from MDX


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.

  • You cannot reply to this topic
1 reply to this topic

#1 theblackdesert   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 February 2012 - 04:24 AM

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

Sponsor:

#2 theblackdesert   Members   -  Reputation: 100

Like
0Likes
Like

Posted 23 February 2012 - 03:51 AM

Problem solved:

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

silly me..




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.



PARTNERS