# 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.

### Dark GDK / Line intersect face || face intersect face w/out collisioning

Message
Posted: 3rd Mar 2012 02:48 Edited at: 3rd Mar 2012 08:14
Anybody know how to check if a line intersects a face with out a collisioning system?

WLGfx didn't you post how in my last post? Can you explain your code?

At least can some one verify this.

Posted: 3rd Mar 2012 16:24
That looks right. You can run some simulations to test it.

I'm not sure why you would need this..... Are you trying to make a collision engine? I tried this before, but found it was already done with DX's intersect mesh function (can't remember what it's called exactly). If you're doing this for a game, you may run into some speed issues. The math involved is complicated and you would have to do this with EVERY face of your mesh (to be accurate). DX has very optimized code to accomplish this task already.

I'm not trying to discourage you, I just don't want you to waste time if you don't have to.

The fastest code is the code never written.
Posted: 3rd Mar 2012 19:04
No worries I am not discouraged. Thanks for enlightening me about the speed issues. I will have to check it against every face but I don't think I can use DX ( not sure though ) because the triangles are just in a struct and not really triangles yet.
Posted: 3rd Mar 2012 19:14
Help me understand your final goal. What do you want to accomplish with the code?

The fastest code is the code never written.
Posted: 3rd Mar 2012 21:26
Ok Im connecting objects in order to generate levels, but ok im trying to recreate the code I posted with GDK's vector3 cammands and I not understanding the dbMultiplyVector3() cammand.

In other words how do I recreate this line of code?

IntersectPos = LP1 + (LP2-LP1) * ( -Dist1/(Dist2-Dist1) );
Posted: 3rd Mar 2012 22:36
I don't understand that command either. If it works like DX's:
Quote: "D3DXVECTOR3* D3DXVec3Scale( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, FLOAT s)"

This basically multiplies the "s" value into the x,y,z values of the "pV" vector and places that value in the "pOut" vector and returns that value from the function as well. Are you looking for some other kind of math? From what I understand, you are looking for something like that.
I am unfamiliar with the library you are using, but perhapse the command exists:

The fastest code is the code never written.
Posted: 4th Mar 2012 00:21 Edited at: 4th Mar 2012 01:01
Sorry for the late reply. I am around now and then...

Are you checking whether a 3d line v1(XYZ) to v2(XYZ) crosses a face? If so then that would be a ray check...

In my code I was originally working with a 2D floor map before creating the final 3D mesh out of the data so I was just checking whether a new edge that was being added was intersecting any other edges already in the floor map. I had to shift v1 a tad as it would intersect anyway. (just digging out some code to help explain it better)

This first bit is the main setup, your's will be completely different but it's easy enough to follow:

This checks the 2D edge intersection of the main edges list:

These next two functions will actually try to attempt to add a corridor segment. If a piece of the newly added segment crosses the main map then it will fail, but only if it hasn't added the minimum amount of segment pieces. The second function is where I have had to nudge one of the vertices so that it will work when checking the intersection:

If you want me to I can send you this project in an email so you can study it better...

EDIT: I've also found some of these which I've bookmarked for my own refernce:

http://softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm
http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
http://www.cs.princeton.edu/courses/archive/fall00/cs426/lectures/raycast/sld016.htm

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Posted: 11th Mar 2012 02:11 Edited at: 11th Mar 2012 02:41
So I got this. I havn't double checked to see if it works but Im pretty sure it does. Umm also it seems very slow like you were saying hawkblood. I'm wondering is if I cant limit how much its used more.
right now Im only checking triangles within a certain range and Im not checking triangles that are attached to the current one.
I can prolly limit my range more.

 It sounded bad to me that I didnt double check it so I did, not exactly very thoroughly but o'well. If you happen to know if it works or not, please post.
Posted: 11th Mar 2012 03:02
Each time you call this function you do 19-44 additional calls to other functions. Each one of those calls clears the instruction pointer's read-ahead buffer. This will result in a very slow overall function. You are also making and deleting 12 vectors. You could do the same thing with directx math. Each of the math functions you are doing are simply calling DXmath functions to do the job, so that makes each call double the speed drop (not really, but close).

D3DXVECTOR3 v1,v2,v3..... and so on.... as declarative instead of dbMakeVector3(..)
D3DXVec3Subtract(..) == dbSubtractVector3(..)
D3DXVec3Cross(..) == dbCrossProductVector3(..)

and so on.... If you declare the 12 vectors at the beginning of your function (don't delete them) and replace the db functions with DX, you would save some clock cycles.
Here is a website of the math functions:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb172972(v=vs.85).aspx

The fastest code is the code never written.
Posted: 11th Mar 2012 03:25
the built in vector thingy for c++, does it work like

//declare

vector a;
vector b;
vector c=a*b;

or something like that?
Posted: 11th Mar 2012 14:46
Yes. I am not sure about c=a*b, but there is a DX vector multiply function. I would try both to see which one works faster. I think they may even be "inline" functions, so that would make them faster to call than other functions. "inline" functions simply tells the compiler to put the actual code there instead of calling the function. This is faster but makes your program larger.

The fastest code is the code never written.