• Create Account

# wildboar

Member Since 29 Dec 2009
Offline Last Active Jul 12 2016 06:12 AM

### In Topic: Field of view check

23 March 2013 - 02:47 PM

Thanks for the info

PrevVel is actually a velocity vector for the main player, it is assumed to be above 0.

### In Topic: Barycentric UV Help

03 January 2013 - 10:21 AM

then try to apply the formula (make sure to associate the correct uv coordinates with the correct barycentric coordinate, otherwise it'll be off)

Sorry what do you mean by that? any sample code would be apreciated. I just added w /= d and v /= d before the if(GetUV) and it produces numbers below 1 now how a uv should be.

### In Topic: Barycentric UV Help

03 January 2013 - 09:50 AM

I actually did not write that function, its in a library called recast (for navmesh generation).

I have modified it like this and left some comments can you have a quick look please:

```static bool intersectSegmentTriangle(const float* sp, const float* sq,
const float* a, const float* b, const float* c,
float &t, bool GetUV,
const float* ta, const float* tb, const float* tc)
{
float v, w;
float ab[3], ac[3], qp[3], ap[3], norm[3], e[3];
rcVsub(ab, b, a);
rcVsub(ac, c, a);
rcVsub(qp, sp, sq);

// Compute triangle normal. Can be precalculated or cached if
// intersecting multiple segments against the same triangle
rcVcross(norm, ab, ac);

// Compute denominator d. If d <= 0, segment is parallel to or points
// away from triangle, so exit early
float d = rcVdot(qp, norm);
if (d <= 0.0f) return false;

// Compute intersection t value of pq with plane of triangle. A ray
// intersects iff 0 <= t. Segment intersects iff 0 <= t <= 1. Delay
// dividing by d until intersection has been found to pierce triangle
rcVsub(ap, sp, a);
t = rcVdot(ap, norm);
if (t < 0.0f) return false;
if (t > d) return false; // For segment; exclude this code line for a ray test

// Compute barycentric coordinate components and test if within bounds
rcVcross(e, qp, ap);
v = rcVdot(ac, e);
if (v < 0.0f || v > d) return false;
w = -rcVdot(ab, e);
if (w < 0.0f || v + w > d) return false;

// Segment/ray intersects triangle. Perform delayed division
t /= d; //d ends up 3676338.0 here

//It is about to return true so it means its a triangle hit but the v + w end up as 1315396.8 + 1609470.5 = 3676338.0

if(GetUV)
{
Vector2 v1 = Vector2(ta[0], ta[1]);
Vector2 v2 = Vector2(tb[0], tb[1]);
Vector2 v3 = Vector2(tc[0], tc[1]);

Vector2 UV = v * v1 + w * v2 + (1 - v - w) * v3;
}

return true;
}```

### In Topic: Barycentric UV Help

03 January 2013 - 09:38 AM

Ok so if those values are correct, how am I supposed to get my uv coordinate? it comes out with crazy numbers with that formula you showed me.

### In Topic: Barycentric UV Help

03 January 2013 - 09:30 AM

Thanks for the help I am trying that line of code you showed me, however after debugging I noticed that v and w are giving me very strange values:

v:  1213134.3

w: 1669297.8

Now the raycast itself is actually working so I am really confused? what values should v and w normally be?

PARTNERS