Re: How to render a 3d model by 2d position
- From: "Robert Dunlop [MS MVP]" <rdunlop@xxxxxxxx>
- Date: Sat, 28 May 2005 10:15:19 -0700
"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.
.
- References:
- How to render a 3d model by 2d position
- From: m(_ _)m
- How to render a 3d model by 2d position
- Prev by Date: Re: execute buffers... ?
- Next by Date: Depth Buffer (z and w)
- Previous by thread: Re: How to render a 3d model by 2d position
- Next by thread: DirectDraw and multithreading
- Index(es):
Relevant Pages
|