Jump to content
  • Advertisement
Sign in to follow this  
kobingo

Render 3d object with screen coordinates

This topic is 4870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey! I wish to render my 3d objects with untransformed vertices, but be able to give the renderfunction x, y screen coordinates, and then somehow recalculate where in the world to draw the object. I don't want to care about the camera position. I have tried to use the picking method, but it seems it doesn't really work with what i'm trying to achive. I would like to have a function RenderObject(int x, int y) - and then have the object drawn exactly at that position on my screen. Can anyone give a helping hand? Thanks in advance! /Jens

Share this post


Link to post
Share on other sites
Advertisement
You have to setup an orthographic view, here is the code in C++, you could easily change it into C#


void OrthoView(float WindowWidth, float WindowHeight)
{
D3DXMATRIX Ortho2D;
D3DXMATRIX Identity;

D3DXMatrixOrthoLH(&Ortho2D, WindowWidth, WindowHeight, 0.0f, 1.0f);
D3DXMatrixIdentity(&Identity);

g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &Ortho2D);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &Identity);
g_pd3dDevice->SetTransform(D3DTS_VIEW, &Identity);
}



The above code was from


If you need to read more into it.

Hope this helps.

Thanks for the tip, but I would like to have a perspective view. Wouldn't it look flat (and boring) with a orthographic view?

Share this post


Link to post
Share on other sites
A bit tricky but pretty similar to picking.

Use the x,y coordinate of the target position, and unproject it two times with a Z of 0 and a Z of 1. This gives you a ray in 3d space. Intersect the ray with a plane in a particular Z. The intersection point is your target position.

This will probably trouble you with the size (width/height) of the displayed object.

Share this post


Link to post
Share on other sites
How do I setup the plane I should use (which coordinates) and how do I know which Z value to intersect with?

Share this post


Link to post
Share on other sites
Why dont you try rendering the object into a secondary texture... like a 256x256 texture. Then use this texture as the source for your sprite. Its a common technique.

Luck!
Guimo

Share this post


Link to post
Share on other sites
Project() and Unproject() will work.

C# code:


public Vector3 WorldToScreenPosition(Vector3 worldPosition)
{
Vector3 screenPosition = worldPosition.Project(this.CurrentDevice.Viewport, this.CurrentGraphicsManager.Camera.ProjectionMatrix,
this.CurrentGraphicsManager.Camera.ViewMatrix, Matrix.Identity);

return screenPosition;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!