Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


anders211

Member Since 14 Feb 2012
Offline Last Active Mar 22 2015 01:31 AM

Topics I've Started

how to get unit vector perpendicular to normal surface

21 March 2015 - 11:44 AM

I have normal vector to the surface. And I want to receive vector perpendicular to this normal vector.

This perpendicular  vector has to be normalized and lie towards x and z direction as normal one.

 

http://oi61.tinypic.com/4lsfb8.jpg

 

Any ideas for 3 equations which will serve to find the solution? I have only one as on the picture, so I need to have 2 more ones.


coordinates transformation

07 March 2015 - 05:34 PM

I have bounce ball physic implemented when normal to the bouncing surface is (0,1,0). Instead of writing new algorithm which would work for other normal vectors I could resuse my algorithm and transform input data like velocity vector.

http://zapisz.net/images/453_problem.jpg


Bounce from ground produces opposite dependency

11 February 2015 - 04:14 PM

Hi
I have a problem. I have left-handed system. And formulas/dependency for movement before bounce impact are:
Vz ~ r*Wx
Vx ~ -r*Wz
In other words: ball which goes into Z+,X+ direction has positive value speeds and positive angular Wx speed and negative value of Wz.
However during bounce ground impact equation gives opposite results:
Vz ~ -r*Wx
Vx ~ r*Wz
Here are details:
Some comment to picture: After bounce with top spin V speed decreases and W speed increases. Wx has to have negative value in order to increase.
 
You know I might tune in manual well formulas obtained from bounce ground impact and replace Wx1,Wx2 with Wz2,Wz1 and everything would be OK. However I am planning to reuse this piece of SW for bounce from wall, for bounce from some slippery slope, so I cannot afford on such workaround because earlier or later I will get lost.
Does anybody have idea how to solve this problem and where I made a mistake that I got opposite direction?

algorithm for point in triangle doesn't work

06 January 2015 - 04:18 PM

In website there is on many sites some popular barycentric algorithm for detecting point in triangle:

bool isPointInTriangle(D3DXVECTOR3 P, D3DXVECTOR3 A, D3DXVECTOR3 B, D3DXVECTOR3 C)
{       
D3DXVECTOR3 v0 = C - A;
D3DXVECTOR3 v1 = B - A;
D3DXVECTOR3 v2 = P - A;


float dot00 = D3DXVec3Dot(&v0, &v0);
float dot01 = D3DXVec3Dot(&v0, &v1);
float dot02 = D3DXVec3Dot(&v0, &v2);
float dot11 = D3DXVec3Dot(&v1, &v1);
float dot12 = D3DXVec3Dot(&v1, &v2);


// Compute barycentric coordinates
float invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
float u = (dot11 * dot02 - dot01 * dot12) * invDenom;
float v = (dot00 * dot12 - dot01 * dot02) * invDenom;


// Check if point is in triangle
return (u >= 0) && (v >= 0) && (u + v < 1);
}

However it is wrong.

It doesn't work for this input data:

D3DXVECTOR3 P(0.379488, 0.113208, 0.0695381);
D3DXVECTOR3 A(0.293016, 0.294949, 0.0872371);
D3DXVECTOR3 B(0.282774, 0.126041, 0.122983);
D3DXVECTOR3 C(0.26794, 0.127092, 0.0825565);

Point P has x coordinate=0.379488 which isn't in a range of x coordinates of A,B,C. So based on this without any calculation I know that for sure point P is outside the triangle. However algorithm return true that point is inside triangle.

The same is with P.y and P.z coordinate.

Could anybody who has in his code algorithm for detecting point in triangle check how your algorithm behaves for the above input data? 

how to detect collision between point and triangle in a mesh?

24 October 2014 - 04:11 PM

Hi

I know algorithm how to detect if point is inside triangle (in details - at plane created by vertices of triangle and bounded to triangle area). Here is my implementation:

bool isPointInTriangle(D3DXVECTOR3 P, D3DXVECTOR3 A, D3DXVECTOR3 B, D3DXVECTOR3 C)
{       
D3DXVECTOR3 v0 = C - A;
D3DXVECTOR3 v1 = B - A;
D3DXVECTOR3 v2 = P - A;


float dot00 = D3DXVec3Dot(&v0, &v0);
float dot01 = D3DXVec3Dot(&v0, &v1);
float dot02 = D3DXVec3Dot(&v0, &v2);
float dot11 = D3DXVec3Dot(&v1, &v1);
float dot12 = D3DXVec3Dot(&v1, &v2);


// Compute barycentric coordinates
float invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
float u = (dot11 * dot02 - dot01 * dot12) * invDenom;
float v = (dot00 * dot12 - dot01 * dot02) * invDenom;


// Check if point is in triangle
return (u >= 0) && (v >= 0) && (u + v < 1);
}

However I don't know how to use it in order to detect collision, because if You make collision algorithm You are in fact not interested if point is in triangle. You are in fact interested if point is on positive half space of triangle - none collision. If point is in negative half of space or in triangle then we have collision.

Here is my implementation of half space test:

Collision::PlaneSide Collision::HalfSpaceTest(const D3DXVECTOR3& vecTestPoint, const D3DXVECTOR3& vecNormal, const D3DXVECTOR3& vecPointOnPlane, const float offset)
{
    //n o v = |n||v|cosL = 1|v|cosL = distance


//Calculate a vector from the point on the plane to our test point
    D3DXVECTOR3 vecTemp(vecTestPoint - vecPointOnPlane);


    //Calculate the distance: dot product of the new vector with the plane's normal
    float dist(D3DXVec3Dot(&vecTemp, &vecNormal) - offset);


    if(dist > COLLISION_EPSILON)
    {
        //Point is in front of the plane
        return FRONT_PLANE;
}
else if(dist < -COLLISION_EPSILON)
{
//Point is behind the plane
return BEHIND_PLANE;
}
//If neither of these were true, then the point is on the plane
    return ON_PLANE;
}

And I have a problem how to connect those two algorithms. I suppose firstly I have to execute half space test. And if half space test returns that point is BEHIND_PLANE (negative half space) or ON_PLANE then I need to detect somehow if point come through this part of space which belongs to this specific triangle.

Could somebody help me to clear it?

 


PARTNERS