View Full Version : Colision Detect Code

Hi guy's !

I'm Computer Ciency Student, in UNIVAP University in Brazil. I need Colisions Detect Codes for my graduation work.

Could anyone help me ?

I'm working on some collision code at the moment for a game but haven't found anything on the net that's much help. I have come up with some crude formulars which work for basic shapes but it involves working on 2 dimensions at a time which can limit what sort of objects you can create. If anyone has some well explained formulars (maths for idiots stuff) then please post it I would be interested in it too.

i recently written some code to do line-sphere collision detection.

here it is:

//-----------------------------------------------------------------------------

// a,b two points on the line

// p point to be checked

float point_line_distance_squared( Tdmyvert3f p, Tdmyvert3f a, Tdmyvert3f b ) {

//

// how it works:

// the area of the triangle is A=b*h/2

// we need to find the h value, so:

// h=2A/b

// the triangle base b can be found easily with euclidean distance from a to b (two points on a line)

// the area of triangle is a bit tough: i remember i read that the normal modulo is also called

// the "signed area" of the triangle... so i gave it a try.

// calculate the normal the standard way, then find the lenght of the normal segment.

// actually, i don't know why there's no need to double the area returned.

// probably the signed area is not of the triangle, but of the parallelogram.

// ehm... well...

// yes, i found it is for that reason.

//

Tdmyvert3f u,v,n;

// u=ab

VECTOR_SUB_3(u,b,a);

// v=bp

VECTOR_SUB_3(v,p,b);

// calc cross product to eval parallelogram area

n.x = u.y*v.z - u.z*v.y;

n.y = u.z*v.x - u.x*v.z;

n.z = u.x*v.y - u.y*v.x;

return SQUARED_LEN_3(n)/SQUARED_LEN_3(u);

}

//-----------------------------------------------------------------------------

float point_line_distance( Tdmyvert3f p, Tdmyvert3f a, Tdmyvert3f b ) {

return sqrt(point_line_distance_squared(p,a,b));

}

//-----------------------------------------------------------------------------

BOOL sphere_line_collision( Tdmyvert3f center, float radius, Tdmyvert3f a, Tdmyvert3f b ) {

return point_line_distance_squared(center,a,b) < radius*radius;

}

i think data types and macros are self explanatory.

this is really simple and unoptimized, and maybe there are some errors with square roots... but indeed it works.

for better collision code, look up the book "realtime rendering": it is a very good source.

[This message has been edited by dmy (edited 08-27-2000).]

I would like to know what sort of collision do you need for ur graduation??

Is it a line-sphere collision? a line-plane one?

I ask that because there are many algorithms to make a collision detection but they are more or less complex....

JC

CyBBe

08-29-2000, 09:23 AM

I also need collision detection, I've searched quite a while now and I can't find any useful information.

I need something that works with my heightmap engine...

Anyone, plz

This may be rather technical, but you might want to take a look: http://www.cs.unc.edu/~dm/collide.html

They describe several collision detection algorithms and have a few packages available for download.

[This message has been edited by Rob (edited 08-29-2000).]

Chapter 4.5 Game Programing Gems

CyBBe

08-30-2000, 07:18 AM

Rob: thanx for the link, I'll check it out

Amp: Game Programming Gems???

masterpoi

08-30-2000, 09:03 AM

Take a look at flipcode's tutorials, http://www.flipcode.com

Also, just last night I was flipping through Real-time Rendering (great book!) and it had a pretty good section on collision detection.

Gelero

08-31-2000, 02:26 AM

Aê Mirfy !!!

Até que enfim um brazuca nesse forum de "mothafu**ers" !!!

Ja venho penando em Opengl, há algum tempo...

e tenho alguns codigo que podem ser uteis..

Prefiro delphi, mas tambem programo em C, ok ???

qualquer coisa, meu mail é guivieira@brfree.com.br

Abracos !

[This message has been edited by Gelero (edited 08-31-2000).]

[This message has been edited by Gelero (edited 08-31-2000).]

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.