Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

An update to Anim8or, v1.00b, is available with a few bug fixes. Get your copy HERE. See the "ReadMe" file for details.

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Thanos

Pages: 1 [2] 3 4 ... 7
16
What do you mean input to test? Like compiled code, like an exe?

No, no... just a test case that produces wrong results, for example something like, triangle points: (0,0,0), (5,0,0), (0,0,5) line: (1,-1,1), (1,1,1). I can put your input in the debugger and see where it stops working correctly.

17
When you say you don't understand half of my code, you mean the first half (finding the collision point) or the second half (checking if it's in the triangle)?

Also, did you try rti v3 and it still doesn't work? Because I think it works ok for me (see the example file in the zip).

I'm checking your code now.

EDIT: See image, red are what I call 'points at corners', blue what I call 'points at midways' (actually called midpoints  ::) )
...and, what I call 'internal product' is uh, the dot product.

EDIT 2: Ok, I think I start to see what is different between the codes. Here:
Code: [Select]
if ( (Dist1 * Dist2) >= 0.0f)
{
// line doesn't cross the triangle.
I thought you meant that the two points define an infinite line. It now seems you meant just the line part between them, right?

EDIT 3: Wait a minute... you don't have to invert x,z, do you? I think it should work without problem anyway.
Can you give me an input to test? (one you know it doesn't work)

18
RTI V3.
I changed the equations. This solves a lot of bugs, and also gives a simpler code.
If it still makes a bug, give me your input and I'll try to reproduce it.


EDIT 27/2/2013: Another bug. DOH
Removed attachment, look for v4.

19
LOL I see what you did there :P

20
EDIT: still stuck on collision though :S

Don't worry, I'm not dead yet... I'm just a little bit stuck.

21
Oh boy... you're right, there's still another bug. Please be patient, I'll track it down.

What coordinate system are you using? x=right, y=up, z=back (standard)? x=right, y=up, z=far (flipped - probably not)? or maybe x=right, y=far, z=up (the best imho but nobody uses it)?

What I'm using. We know that two vertices have the same direction if their inner product is positive, the opposite direction if it's negative, zero if they form a right angle. Ie. if they form a 45 deg angle, x1*x2+y1*y2+z1*z2>=0, whereas for 120 deg it's <0.
So, if we take the vectors starting at the midways and ending at the corners, a point has to be 'in front of them' to be inside the triangle.

See the pic for an example. The dot inside the triangle is in front of all the sides, so the inner product with the red vectors will be positive in all cases. Instead, the blue dot outside is in front of the left and the down sides, but the right side looks the other way, so the inner product with its red vector will be negative.

Of course all vectors have to be relative to the midway before calculation (the second bug I corrected).

22
Ah never mind I just used an if-branch for the division by zero.
I found the second bug too!! And it was SUCH A DUMB BUG :-X

So, cooldude234, here is ray-triangle intersection, version 2, I think it works ok now - I'm sorry I was that slow! I had some exams to sit these days. I hope it serves you well! If you find another bug, just let me know.


EDIT 2, 23/2/2013: Nope, this didn't work too. See version 3 for an update.

23
if there was a division by zero then the code would crash (the program would just stop running and close), and VC++'s debugger would recognize the crash code and tell me it was a division by zero.
Yes, in integers it would crash. In floats however the float variable gets a special value, #inf. Processing this value usually gives #nan (not a number), which makes things stop working well in general. I'm not sure if we are testing the same input though.

Quote from: cooldude234
And I know that you mean your code, but I have no clue what you said by...
Quote
Ok I found 1 bug so far, if the line is vertical, the tangent of angle is infinite,... so it's blown up. I should try to find an alternative way to describe the line.
something about the tan of the angle is infinite, which I don't even know how that's possible and I just don't understand it.
An example in 2D: a 2D line is described by y=ax+b. a is equal to tan(t), where t is the angle of the line. A vertical line is x=c. How much is a here? There is no a here, but vertical means, t=90 deg -> a=tan90 = #inf... unless you use different system to describe the line, without a and b.
Same for 3D.

24
EDIT: Uhh  :-[  :-X it seems it needs just a tad of debugging, I'm sorry cooldude234!!
I meant that my code needs debugging, not yours. :D Yours is probably ok. I have little time this days because of exams, but I'll find some soon to do more tests to find the other bug too.

Quote from: cooldude234
??? :S  ???
Um in other words there is a chance of division by zero in my code. :)

25
Ok I found 1 bug so far, if the line is vertical, the tangent of angle is infinite,... so it's blown up. I should try to find an alternative way to describe the line.

26
I might make a small example application as well, just to make sure it works standalone.

You know, I shouldn't be sure about anything:
Programmer's rule #1: "Thou shalt not expect thy code bug free."

EDIT: Uhh  :-[  :-X it seems it needs just a tad of debugging, I'm sorry cooldude234!!

27
Quote from: cooldude234
Though I must ask what is with the Boolean variable rti? It's defined just to define floating point values. Why not just define the floating point values?

DUH!! It's not a variable! rti() is the complete function ready - made. You don't have to edit it! :P
rti() returns if the point is inside the triangle. I've already made it! see below for an example.

Example of use.
suppose we have, a triangle with points (1,2,3), (2,3,4), (3,4,5).
and a ray line from points (3,2,1), (2,0,1).

Rename rti.cpp to rti.h (should have done this myself - sorry)

And in your main program:
#include "rti.h"
...
float xi, yi, zi;
...
inTri = rti(1,2,3,2,3,4,3,4,5,3,2,1,2,0,1,&xi,&yi,&zi);
if (inTri == true)
{
    // The point is in the triangle.
    // The point is (xi,yi,zi) - do something with it!
}
else
{
    // The point is not in the triangle.
}

28
Here you are.  ;)

I think the code I once sent you for line plane intersection might have a bug. I tried avoiding it this time, do a test if you want.

EDIT: Oh my, where are my manners?
Return values: x, y, z: collision point.
Return value is a boolean indicating whether the point belongs in the triangle or not.

EDIT 2, 16/2/2013: This version had a bug, so I removed the attachment. See version 3 for an update.

29
Sorry for the late reply. I can give some help if I find time.
Tell me what exactly you mean "That page didn't give me any good results and it never worked."? What is the point that stops working correctly?
Also, how is a triangle defined in your code - to allow me write some compatible code? Like, ((x1,y1,z1),(x2,y2,z2),(x3,y3,z3)) (ie. is there a 'point' class? or maybe a 'triangle' class too?) Or raw data, like, (x1,y1,z1,x2,y2,z2,x3,y3,z3)?

EDIT: Oh also, how is the ray line defined? Point-and-direction or two-points-on-line? (Is there a 'ray' class or 'line' class? Show me.)

30
ASL Scripts / Re: ASL Editor [version 3.5 is out!]
« on: January 19, 2013, 10:46:06 pm »
Oh, believe me, this one is gonna be the main reason I'll start making ASL scripts. Thanks Kubajzz!

Pages: 1 [2] 3 4 ... 7