Re: How to render a 3d model by 2d position



"m(_ _)m" <mm@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B8E1DEAC-2A3D-47E4-866B-B4972CEFB30B@xxxxxxxxxxxxxxxx
>I want render a arrow that always lead player go to destination.
> Now I needt to rotate arrowhead to point the place where desctination is.
> But I can't let arrow always on the same position of screen.
> And I dont's know where the camera look at.
> Have any method to render the 3d model by 2d position?
> thank for any advice :)

I would break this task into two steps:

1. Figuring out the proper location for the arrow, which should be a
position in world space that has a fixed relation to the viewer.
2. Determine the proper orientation of the arrow so that it points to the
destination.

The first step can be accomplished using an inverse of the view matrix. The
resulting matrix will allow you to transform a vector representing the
desired location in view space to world coordinates. These coordinates will
then be guaranteed to transform to the location in view space that you
specified, when the view matrix is applied during transformation. The code
to get this location might look something like this:

D3DXMATRIX invView;
D3DXMatrixInverse(&invView,NULL,&viewMatrix);
D3DXVECTOR3 vView,vWorld;
vView.x=5.0f; // distance right/left of view center
vView.y=5.0f; // distance up/down of view center
vView.z=20.0f; // distance forward from camera;
D3DXVec3TransformCoord(&vWorld,&vView,&invView);

You'll have to set up vView appropriately for the scaling and z range of the
projection matrix you are using.

Next, you need to create a world matrix for your object that translates it
to the calculated coordinates and properly orients it so that its Z axis
transforms to align with a vector between the arrow's location in world
space and its destination (and appropriately rotates the X and Y axis of the
arrow to match). I could step you through the math, but you can take an
easy shortcut: use the D3DXMatrixLookAtLH function, which does exactly the
opposite of what you need, and invert the matrix it generates:

D3DXMATRIX tempMat,arrowMat;
D3DXMatrixLookAtLH(&tempMat,&vWorld,&Destination,&D3DXVECTOR3(0.0f,1.0f,0.0f));
D3DXMatrixInverse(&arrowMat,NULL,&tempMat);

--
Robert Dunlop
The X-Zone
http://www.directxzone.com/
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do not
reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation
with Microsoft.


.



Relevant Pages

  • can javascript do this
    ... selected by clicking an arrow. ... and another arrow to take the selected items from the destination box and put ... them back in the source textbox. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Linking from shape to shapes in Visio
    ... When you use the Search function to find something on a page it points at the ... place you have identified in the search with an arrow. ... the functionality of going to a destination looks as though it is there. ... Electronics for Visio http://www.electronics.sandrila.co.uk/ ...
    (microsoft.public.visio)
  • Re: Draw a scaled arrow
    ... I am already using a transform to scale and translate the image when it ... In the example below, each arrow is rotated about its tip, then scaled, ... home dot woh dot rr dot com slash jbmatthews ...
    (comp.lang.java.programmer)
  • Re: How to change Mouse behavior
    ... as far as changing the movement of mouse goes driver for the monitor handles ... > arrow at the desired target. ... > event and transform it to draw the screen. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to change Mouse behavior
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... > arrow at the desired target. ... > event and transform it to draw the screen. ...
    (microsoft.public.dotnet.languages.csharp)

Quantcast