Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7855449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:23:22+00:00 2026-06-02T20:23:22+00:00

I have a square area on which I have to determine where the mouse

  • 0

I have a square area on which I have to determine where the mouse pointing.
With D3DXIntersectTri I can tell IF the mouse pointing on it, but I have trouble calculating the x,y,z coordinates.

The drawing from vertex buffer, which initialized with the vertices array:

vertices[0].position = D3DXVECTOR3(-10, 0,  -10);
vertices[1].position = D3DXVECTOR3(-10, 0,   10);
vertices[2].position = D3DXVECTOR3( 10, 0,  -10);
vertices[3].position = D3DXVECTOR3( 10, 0,  -10);
vertices[4].position = D3DXVECTOR3(-10, 0,   10);
vertices[5].position = D3DXVECTOR3( 10, 0,   10);

I have this method so far, this is not giving me the right coordinates (works only on a small part of the area, near two of the edges and more less accurate inside):

BOOL Area::getcoord( Ray& ray, D3DXVECTOR3& coord)
{
    D3DXVECTOR3 rayOrigin, rayDirection;
    rayDirection = ray.direction;
    rayOrigin = ray.origin;

    float d;

    D3DXMATRIX matInverse;
    D3DXMatrixInverse(&matInverse, NULL, &matWorld);

    // Transform ray origin and direction by inv matrix
    D3DXVECTOR3 rayObjOrigin,rayObjDirection;

    D3DXVec3TransformCoord(&rayOrigin, &rayOrigin, &matInverse);
    D3DXVec3TransformNormal(&rayDirection, &rayDirection, &matInverse);
    D3DXVec3Normalize(&rayDirection,&rayDirection);

    float u, v;
    BOOL isHit1, isHit2;

    D3DXVECTOR3 p1, p2, p3;
    p1 = vertices[3].position;
    p2 = vertices[4].position;
    p3 = vertices[5].position;

    isHit1 = D3DXIntersectTri(&p1, &p2, &p3, &rayOrigin, &rayDirection, &u, &v, &d);
    isHit2 = FALSE;

    if(!isHit1)
    {
        p1 = vertices[0].position;
        p2 = vertices[1].position;
        p3 = vertices[2].position;
        isHit2 = D3DXIntersectTri(&p1, &p2, &p3, &rayOrigin, &rayDirection, &u, &v, &d);
    }

    if(isHit1) 
    {
        coord.x = 1 * ((1-u-v)*p3.x + u*p3.y + v*p3.z);
        coord.y = 0.2f;
        coord.z = -1 * ((1-u-v)*p1.x + u*p1.y + v*p1.z);
        D3DXVec3TransformCoord(&coord, &coord, &matInverse);
    }

    if(isHit2) 
    {
        coord.x = -1 * ((1-u-v)*p3.x + u*p3.y + v*p3.z);
        coord.y = 0.2f;
        coord.z = 1 * ((1-u-v)*p1.x + u*p1.y + v*p1.z);
        D3DXVec3TransformCoord(&coord, &coord, &matWorld);
    }
    return isHit1 || isHit2;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:23:23+00:00Added an answer on June 2, 2026 at 8:23 pm

    Barycentric coordinates don’t work the way you used them. u and v define the weight of the source vectors. So if you want to calculate the hit point, you will have to compute

    coord = u * p1 + v * p2 + (1 - u - v) * p3
    

    Alternatively you can use the d ray parameter:

    coord = rayOrigin + d * rDirection
    

    Both ways should result in the same coordinate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a square 400 x 400 with a plane projection attached to it
I have 3 square. smallest square s3 is inside s2. s2 is in side
Lets say I have a non-square image.. If I increment the width and I
I have a 2 dimensional array forming a table: [color][number][shape ] ------------------------- [black][10 ][square
anyone have experience doing this? when i say imaginary i mean the square root
Let's say I have a super type (Shape) and two children (like Square, Circle).
I have a <div> , and in jQuery I want to divide this square
i have a container div which is position:relative and the squares are position:absolute because
I have an orthogonal perspective which I initialize like so: gl.glViewport(0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
I have a picture control which is called IDC_PICTURECONTROL , and a LPPICTURE which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.