Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Barycentric coordinate method?

Author
Message
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 21st Jul 2010 00:25
Is there a way in DBP to find the barycentric coordinates (in UV terms) of a collision on a mesh.

If you don't know what the heck I'm talking about:
It's a method using the weighted center of an object; in this case it's a mesh. In C++/DX the "rayintersectmesh" command will store that info if needed.... And I would like to be able to use it.

I'm going to use this to determine the center of a water disturbance to create waves. The water "plane" will not be a regularly shaped plane object. I could do the math myself, but if DBP is doing it anyway, it would use precious ticks for me to do it.

The fastest code is the code never written.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Jul 2010 03:30
I don't think directly, but you can get the exact point of collision, so determine which polygon it is then calculate the UV coordinates from there.


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 21st Jul 2010 05:00
Yea..... I was wanting to be as lazy as possible. I guess I'll have to come up with it on my own.

The fastest code is the code never written.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 21st Jul 2010 09:06
Just out of curiosity, could you give an explanation as to what barycentric coordinates are?
I looked it up on wikipedia and wolfram but I don't feel like making sense of mathy lingo ATM.


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 21st Jul 2010 15:31
If you had a mesh that was an irregular shape like in the shape of a star, the UV coordinates would be hard to find at the point of collision..... If you had a flat, rectangular image and you clicked with the mouse on it, you would be able to use simple math to determine what pixil of that image you were on. In DirectX, the "rayintersect" command will return a variety of info including the Barycentric UV coordinates of the face that was intersected, taking into account that you could even have an unwraped mesh.

If you are unsure what unwraped is: Each face of a mesh can have it's own UV coordinates. In fact they do; It's just that most people make them uniform so that the image goes smoothly accross each face of the mesh.

My problem is not that complicated.... I would be using it to determine the UV coordinates on a trapezoid-- not that hard. I just didn't want to do the math if DBP got the info already.

The fastest code is the code never written.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Jul 2010 17:15
DBPro does not get that information, sadly

If you use sparky's dll, you can get the exact point of collision, and also the index of the face which the ray hit. It shouldn't be too hard to interpolate the UV coordinates of the vertices for that face to find the UV at the point of intersection.

There are some commands in the 3D maths section to deal with barycentric coordinates.

[b]
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 21st Jul 2010 17:49
I didn't even look in the math help section.... That's usually my first option when dealing with math.

The fastest code is the code never written.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Jul 2010 02:04
UPDATE:
For those of you wondering, BCC VECTOR2 in the help is actually what I was looking for. Now to figure out how to use it for my purposes.

The fastest code is the code never written.

Login to post a reply

Server time is: 2026-07-25 05:32:42
Your offset time is: 2026-07-25 05:32:42