Logo

¡Bienvenido a Stratos!

Acceder

Foros





Draw a 3d coordinate above a 2d coordinate

Iniciado por tirengarfio, 24 de Julio de 2006, 01:58:57 PM

« anterior - próximo »

tirengarfio

Hi,

I got to render an object 3D above an 2d image.

Now i want to render a coordinate of the object 3D, for example (0,0,0)in a coordinate of the 2d image, for example at the (23,21) pixel.

I know it is possible but i dont know how.

Someone can help me?

Elvis Enmanuel

Given 2d coordinates (x & y) you can obtain a 3d ray using the inverse of the camera matrix:

mInvWorldSpaceMat = (mWordMatrix * mViewMatrix).inverse();


SRay const CCamera::getRayInWorldSpace(Int x,Int y,SMatrix4x4 *invWorldSpaceMat) {
   SVector v;
   SRay ray;

   /**
    * Compute the vector of the pick ray in screen space
    */
   v.x = ((( 2.0f * (Float)(x - mRect.x)) / mRect.width)  - 1.0f);
   v.y = -((( 2.0f * (Float)(y - mRect.y)) / mRect.height) - 1.0f);
   v.z = 1.0f;

   /**
    * Transform the screen space pick ray into 3D space
    */
   ray.dir = CMatrix::ref()->vectorTransform(v,invWorldSpaceMat);
   ray.src = vector(invWorldSpaceMat->M30,invWorldSpaceMat->M31,invWorldSpaceMat->M32);

   return ray;
}

With this ray u can check the intersection with a transformed plane and obtains the intersection point in 3d coordinates for your object.

ains