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 / Search UV coordinates inside the triangle.

Author
Message
OldPMan
TGC Store Seller
17
Years of Service
User Offline
Joined: 10th Aug 2008
Location:
Posted: 24th Oct 2010 15:24
please help move this code into DBPro.
I do not know how to do it.


Vector3 A = new Vector3(1, 0, 0); Vector2 Auv = new Vector2(0, 0);
Vector3 B = new Vector3(10f, 4f, 4f); Vector2 Buv = new Vector2(1, 0);
Vector3 C = new Vector3(0, 6f, 13f); Vector2 Cuv = new Vector2(0.5f, 1);
Vector3 D = new Vector3(4, 3, 5);
Vector3 N = Vector3.Normalize(Vector3.Cross(B - A, C - A));
float AreaABC = Vector3.Dot(N, Vector3.Cross(B - A, C - A));
float AreaPBC = Vector3.Dot(N, Vector3.Cross(B - D, C - D));
float AreaPCA = Vector3.Dot(N, Vector3.Cross(C - D, A - D));
float b = AreaPCA / AreaABC;float a = AreaPBC / AreaABC;
float c = 1.0f - a - b;
Vector2 Duv = a * Auv + b * Buv + c * Cuv;

.....already beside..... for all
OldPMan
TGC Store Seller
17
Years of Service
User Offline
Joined: 10th Aug 2008
Location:
Posted: 24th Oct 2010 16:36 Edited at: 24th Oct 2010 16:37
I tried to do it myself.
it seems I have failed.
tell me where I was wrong



.....already beside..... for all
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Oct 2010 16:40 Edited at: 24th Oct 2010 16:43
** deleted **

Your latest post makes my comments irrelevant.

What were the values of VAR, CPV, etc? Presumably you used make vector3 to create those vectors first?
OldPMan
TGC Store Seller
17
Years of Service
User Offline
Joined: 10th Aug 2008
Location:
Posted: 24th Oct 2010 16:43 Edited at: 24th Oct 2010 16:44
all set



.....already beside..... for all
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Oct 2010 16:44
Our posts seem to be crossing.

What exactly is going wrong?
OldPMan
TGC Store Seller
17
Years of Service
User Offline
Joined: 10th Aug 2008
Location:
Posted: 24th Oct 2010 16:51
Quote: "Our posts seem to be crossing."

ou

I myself can not understand.
I have two source code to mine in C + +
and I can not move them in DBPro.
something I did wrong.

I chose a simpler version of it in the first post.

.....already beside..... for all
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Oct 2010 16:55
I don't think that snippet calculates the triangle area correctly.

Try this. You can work out for yourself the correct triangle area very easily - it is in fact 4.5.

Login to post a reply

Server time is: 2026-07-22 03:52:00
Your offset time is: 2026-07-22 03:52:00