Render 3d object with screen coordinates

Started by
21 comments, last by kobingo 18 years, 9 months ago
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
Advertisement
By the way, I use C# with managed directx...
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?
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Can you please explain this with a little bit of code?
How do I setup the plane I should use (which coordinates) and how do I know which Z value to intersect with?
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
Don't think that would result in very good quality...
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;}

Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.

This topic is closed to new replies.

Advertisement