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 / VertexData Get Polygon at Point

Author
Message
DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Jun 2012 06:16
I was thinking this was going to be easy but I guess not.

I am given a point in 3d space that is retrieved from pick object so it is on the surface of the object. Using that point I want to figure out what the polygon index is and the indexes of that polygon.

I've tried several methods that didn't exactly work. The first method I thought I could simply just get the 3 closest vertexes to the point but it didn't return the correct vertexes. Another idea which I have no idea how to accomplish is testing to see if the point is within a polygon (triangle) and test each one. I don't know how to test if a point is within a polygon though I do know where is a 2d point in triangle function.

Any ideas of how to accomplish this? I'm trying to find the simplest and most efficient way of doing this to max out the speed. This calculation will be used a lot so I want it to be fast.

Thanks,

DigitalFury

Zombie Video Game!
paul5147
19
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 29th Jun 2012 07:55
Try using Sparkys collision dll for doing a raycast collision because that gives you the face hit/poly of the object that was hit as well as the 3d point which you can then use to retieve the vertex data directly from that poly.
You simply do a check to see if the object has index data or not.If it does then get the vertex data stored in the face that was retuned,else just multiply the face by 3 and get those vertex positions.
I have an example i can post up later for you if you want.
DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Jun 2012 09:14 Edited at: 29th Jun 2012 09:16
@paul5147 - I can't really use raycasts. A collision system would be a lot to add on for just one calculation. You can post an example though if I have no choice i'll use it.

Thanks,

DigitalFury

Zombie Video Game!
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 29th Jun 2012 10:37
Check this thread:

http://forum.thegamecreators.com/?m=forum_view&t=197498&b=1

Scroll down to The Comet's example program where he paints onto surfaces by detecting where the cursor intersects an object and manipulating the texture. It does use Sparky's as Paul mention above though. This is the only easy way I know of.

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Jun 2012 12:48
Quote: "I don't know how to test if a point is within a polygon though I do know where is a 2d point in triangle function."


It's practically the same thing and you've already got the code if I recall correctly. Have a look at Russia's old thread that you showed me.
DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Jun 2012 19:22
Looks like this is on it's way to working but still needs to be tested:


@Fallout - I'll have to take a look at that code. It seems fairly complicated so it may take some time to understand.

The code:



@Green Gandalf - I do have the 2d point triangle function so what do I do with it? I don't remember showing you Russia's old thread could you point me to it?

Thanks,

DigitalFury

Zombie Video Game!
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Jun 2012 20:31
Quote: "I don't remember showing you Russia's old thread could you point me to it?"


Gladly. Here it is - copied from one of your emails to me.

RUSSIA's old thread

The relevant bit is one of my posts on the previous page of that thread - around 23 October 2010.

I thought I was disorganised ...
DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Jun 2012 20:42
Found it!:


It will require a bit of re-writing but that should be it.

Thanks,

DigitalFury

Zombie Video Game!
DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Jun 2012 21:12 Edited at: 29th Jun 2012 21:25
@DigitalFury - Did some testing and it didn't seem to work!



The poly is always 1 for some reason.

This is the pick object data:


Which I get from:


This is the polygon it should return:


Any ideas why?

DigitalFury

Zombie Video Game!
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 29th Jun 2012 22:18
does your object have indexdata?

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 29th Jun 2012 23:00 Edited at: 29th Jun 2012 23:00
I used make object plain so it should.

DigitalFury

Zombie Video Game!
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 00:10
check if it does have. If it does your vertex accesing code is wrong

if it does have indices then you need to replace all of this
Get VertexData Position x/y/z(Index)
to this
Get VertexData Position x/y/z(get indexdata(Index))

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Jun 2012 00:50
@Brendy boy - I'm a little confused you can't use the index data as a parameter in Get VertexData Position X, Y, Z.

DigitialFury

Zombie Video Game!
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 00:57 Edited at: 30th Jun 2012 01:00
of course you can, did you try?

EDIT:
i just checked, plain doesn't have indices so that isn't the problem with your code, something else is, unless you're creating plain with IanM's matrix untils plugin

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Jun 2012 00:59
Well I can't,

Quote: "Parameter for 'Get VertexData Position X' do not match 'Vertex Index' at line 382."


DigitalFury

Zombie Video Game!
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 01:01
Quote: "Well I can't,"

i told you to check first if plain has indexdata

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Jun 2012 01:34
@Brendy boy - I'm confused. There is no command Get VertexData Position X(VertexIndex, Index). I believe that DBP objects are indexed. How do I check if it is indexed?

DigitalFury

Zombie Video Game!
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jun 2012 01:53
Did you actually check that the functions you are using work? Not much point worrying about vertexdata if the rest doesn't work.

I pointed you to working code in an earlier post.
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 01:55
Quote: "There is no command Get VertexData Position X(VertexIndex, Index)."

get vertexdata position x(get indexdata(index))

Quote: "How do I check if it is indexed?"

get vertexdata index count() -> if >0 then object has indices

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Jun 2012 02:16
Basically the modified code would look like this:


Right?

I tested that and it still didn't work.

Thanks,

DigitalFury

Zombie Video Game!
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 02:29
Quote: "Right?"

yes, but only if your object has indices (in a case of dbpro plain it doesn't)

since it doens't work in both cases something else is wrong in your code. I suggest to test you functions, especialy the point in poligon. Think of 3 vertices and a point for which you know that it must be inside the polygon and test your function

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Jun 2012 03:11 Edited at: 30th Jun 2012 03:14
I verified that the functions work correctly:


I would think this might be wrong:


I don't think it is getting the right vertexes together for each and every polygon on the object. I just guess with that part so I don't know if it is right.

Any other ideas?

Zombie Video Game!
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 03:38
Quote: "I don't think it is getting the right vertexes together for each and every polygon on the object. I just guess with that part so I don't know if it is right."

it is correct if object has only vertices

Quote: "Any other ideas?"

it could be that the point you are testing isn't really inside a triangle, it could be very close so you think it is but it isn't.
try introducing some epsilons in you pointInTRI functions so it checks if a point is very near to a triangle.

How do you get those coordinates of a point? You didn't show as that part of the code

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Jun 2012 03:43 Edited at: 30th Jun 2012 03:44
@Brendy boy - I don't even know what an epsilon is. lol Could you use my code to come up with an example? Just enter in the values. I just wrote out the values to figure if it was right.

Quote: "How do you get those coordinates of a point? You didn't show as that part of the code"



Thanks,

Digitalfury

Zombie Video Game!
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 03:48
Quote: " I don't even know what an epsilon is. lol Could you use my code to come up with an example?"

For example:
if A#=0.0 then something

but if a is never exactly 0 but it has values like 0.00001224 you need to introduce epsilons:

if a#<epsilon# and a#>-epsilon# then something
where epsilon# is a value like 0.001

Now, you need to find the good spot in your pointInTRI for introducing epsilons

Quote: ""How do you get those coordinates of a point? You didn't show as that part of the code""

Not that point you used for testing, the point in your code that doesn't work correctly

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Jun 2012 03:51
What you saying is like this?:


DigitalFury

Zombie Video Game!
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 03:57
Quote: "What you saying is like this?:"

no, what should that code be?

Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 03:59
you will need to check somehow if your point lies in the plane of a poligon

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Jun 2012 04:08 Edited at: 30th Jun 2012 04:16
@Brendy boy -

Quote: "no, what should that code be?"


I'm not sure that is why I'm asking you.

Quote: "You will need to check somehow if your point lies in the plane of a polygon"


I realize I need to check if i'm within the bounds of the polygon. Which I am in that instance.

The problem I am having is that it is always polygon 1 for some reason no matter which one I select. I'll have to double check the input but I think that is fine.

I'm having trouble getting it to return different input when i'm within another polygon. I'm not sure why i'm having this problem and I think it must have to do with the input or vertexes i'm using to test.

Edit: Double checked the input it is different each time. I do get an extremely small number for the z. Like 0.00000001. I'll test to see if that would cause issues.

Edit: Extremely small numbers don't make a difference the functions still work fine. Which lead me to believe there is something wrong with the vertexes i'm selecting or the input.

Edit: Found out something really weird. With Get index() command I get the first one wrong. Without it I get the second one wrong. I'd guess that means there is something wrong with:


DigitalFury

Zombie Video Game!
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 04:16
Quote: "I'm not sure that is why I'm asking you."

i said you need epsilons, those are not epsilons

Quote: "I realize I need to check if i'm within the bounds of the polygon. Which I am in that instance."

I think the points you are testing are not inside the triangle and that's probably where your error is. Show as your whole code.
poligon plane and poligons bounds are not the same thing but leave that thing a side for nowm kae sure the points realy are inside the triangle.

before the loop in yout code you need to reset the poly variable back to zero, i don't see that in your code

I can't tell anything more because I see only part of your code and i'm trying to help under the assumption that the code I don't see is correct which may and may not be the case

DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Jun 2012 04:24 Edited at: 30th Jun 2012 04:26
Quote: "before the loop in yout code you need to reset the poly variable back to zero, i don't see that in your code"


It shouldn't matter because it is within a function but I did that anyways.

Quote: "i said you need epsilons, those are not epsilons"


I have no idea how to program with epsilons or how to handle them in the function.

You can compare the poly from: DK Get Pick Poly() with this code now.

Full Code: (Enough to work I think. Untested)


DigitalFury

Zombie Video Game!
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 30th Jun 2012 05:37 Edited at: 30th Jun 2012 05:42
SOLUTION
create your plain like this
Make Object Plain Surface, 100, 100,1

EDIT:
and here's the code



DigitalFury
14
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 30th Jun 2012 05:42
@Brendy boy - No way! That was it. Wow, lol thanks a ton. Why would orientation have anything to do with it? DBP is so confusing sometimes.

DigitalFury

Zombie Video Game!

Login to post a reply

Server time is: 2025-06-19 06:44:06
Your offset time is: 2025-06-19 06:44:06