How can I calculate point of UV texture pressed on object?

How can I calculate point of UV texture pressed on object?

For example: I have a ball textured by Earth uv map and I pressed any city and I'd like to get a possition that city on Earth bitmp?

I'm going to try explain :) I have a code:

bool    draw;
int     old_position_X;
int     old_position_Y;

void __fastcall TForm1::Image3D(TObject *Sender, TShiftState Shift, float X,
          float Y, TVector3D &RayPos, TVector3D &RayDir)
{
    if (Shift.Contains(ssLeft))
    {
        if (draw==true)
        {
            TVector3D HitPos;
            Image3D->Context->Pick(X, Y, TProjection::pjCamera, RayPos, RayDir);
            RayCastPlaneIntersect(RayPos, RayDir, Image3D->AbsolutePosition, Image3D->AbsoluteDirection, HitPos) ;
            HitPos.X -= Image3D->Position->X;
            HitPos.Y -= Image3D->Position->Y;

            int w=Image3D->Bitmap->Width;
            int h=Image3D->Bitmap->Height;
            int x=(w/Image3D->Width)*(HitPos.X+Image3D->Width/2.0);
            int y=(h/Image3D->Height)*(HitPos.Y+Image3D->Height/2.0);

            Image3D->Bitmap->Canvas->BeginScene();
            Image3D->Bitmap->Canvas->Stroke->Kind=TBrushKind::bkSolid;
            Image3D->Bitmap->Canvas->Stroke->Color=claRed;
            Image3D->Bitmap->Canvas->DrawLine(TPointF(old_position_X,old_position_Y),TPointF(x,y),1.0);
            Image3D->Bitmap->Canvas->EndScene();

            old_position_X=x;
            old_position_Y=y;
        }
    }
    else
    {
        draw=false;
    }

}

I can zoom, rotate and move the Image3D and that code make me paint on the Image3D.

By the way I don't understand why I have to divide Image3D width and height by 2 but thats work :) I don't understand dependence between 3D object values (scale, positions etc) and pixels... Especially scale X,Y,Z and Width, Height of 3D objects... And dependence with size of textures and scale of 3D objects...

And now, I'd like to make the same on imported models. How to calculate that position on texture. I don't expect exactly the code but I would ask for guidance, example code etc

anybody?

Answers


The usual way to that is:

  1. Calculate which triangle you have hit, using the ray.
  2. Get the UV coordinates of its three vertices and interpolate.

Need Your Help

how to write html on image using gd library php?

php gd graphic

im using IMAGETTFTEXT function in php for writing text on some images.now i want to write html tags on my image,for example IMG tag.

Get result from shell script objective-c

objective-c shell scripting nsstring

I would like to run a shell script, from a file or from an objective-c string (within the code). I would also like the shell script's result to be stored to a variable. I would not like the shell