Jump to content


Photo

3d Collisions Dll


  • Please log in to reply
154 replies to this topic

#1 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 23 September 2007 - 01:59 PM

3D collision DLL
Use precise 3d collisions in your GM game!



Since I have moved on to GMNewton and am no longer supporting this, why not some source?
http://host-a.net/ha...odModSource.zip

God bless,
-hanson



This is a dll I created to add 3d collision checking to GM games. It is based off of http://jgt.akpeters....r97/tritri.html by Tomas Moller. I also want to mention Hach-Que; his TriTriCollisions DLL got me started on this project. This DLL supersedes Hach-Que's TriTriCollisions DLL. It works best with low-poly models, so if you have a mesh with many polygons, create a different one with less polys to use as its collision model. The dll works fast enough if you keep your levels small, or add some optimizations. I have included a basic example to get you started. Please note that the physics are not the main focus of the example. If you use this in your project, please give credit to Samuel Hanson. Please let me know what you think!


Notice: Brett14 has improved on this project a ton! If you are looking for precise 3d collisions, I would recommend you check out his topic at http://gmc.yoyogames...howtopic=449508. It offers better speed and fixed bugs as compared to this.


Last update: March 8, 2008

Complete:
-load model
-check collision
-Rotations
-ray-model intersection detection.
-ray reflection
-example
-Primitives
---*block
---*cylinder
---*wall
---*floor
---*triangle
-Collision model replacing on the fly
-supports loading of 3 formats:
---*GM model format, must be triangulated
---*gml(must be formated correctly). Made to work with export from marzipan.
---*Separated format. Made to work with export from Marzipan
---*I encourage you to create scripts to import from more file formats. Please let me know if you create any that I can include in with the scripts

Planned:
Sorry - there are no planned updates at this time. My efforts are now directed toward GMNewton, which is a wrapper for a 3d physics engine. This is still available free to use though, and I love to see what you use it for.

Items in bold are in progress.

Screenshot:
Posted Image


__________________________________________________
____________________

I will keep this available for download for a time, though I highly recommend using Brett14's dll instead.
__________________________________________________
____________________


<span style='font-size:14pt;line-height:100%'>Download: Download ModMod7.2.zip </span> - updated 03/08/08

<span style='font-size:8pt;line-height:100%'>
OLD ModMod7.1
OLD - ModMod7
OLD - ModMod6</span>


Posted Image


Thanks for looking!
-hanson

Edited by hanson, 15 October 2009 - 11:43 PM.

  • 0

#2 Jesper

Jesper

    GMC Member

  • New Member
  • 1789 posts

Posted 23 September 2007 - 02:06 PM

Link broken. And btw, please use normal ZIP.
  • 0

#3 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 23 September 2007 - 02:11 PM

Sorry. I'm fixing it.

FIXED

Edited by hanson, 23 September 2007 - 02:17 PM.

  • 0

#4 Robot Freak

Robot Freak

    GMC Member

  • New Member
  • 271 posts

Posted 23 September 2007 - 06:59 PM

What about support for the basic gamemaker 3D shapes?

Nice DLL!
  • 0

#5 freko

freko

    The Professional

  • GMC Member
  • 504 posts
  • Version:GM8

Posted 23 September 2007 - 07:42 PM

GR8.This is a close one I was looking for.
Can't wait to see your Planned development :ph34r:
Hmm...If futher features arise, I'll be all set to use it in my project
(in my sig)
Keep up the good.




edit:-
But does it support other types of models like obj & 3ds.
And I hav found a minor bug:-
When the ball touched the sides of the floating blue plate, it gets stuck.. :(

Edited by freko, 23 September 2007 - 07:49 PM.

  • 0

#6 xygthop3

xygthop3

    The one who knocks

  • GMC Member
  • 3041 posts
  • Version:GM:Studio

Posted 25 September 2007 - 12:11 AM

Nice DLL, please add .obj or .3ds support because .mod format is a pain in the neck.

Thanks
  • 0

#7 freko

freko

    The Professional

  • GMC Member
  • 504 posts
  • Version:GM8

Posted 25 September 2007 - 01:08 AM

Yea Please..
  • 0

#8 Ivo Georgiev

Ivo Georgiev

    GMC Member

  • New Member
  • 274 posts

Posted 25 September 2007 - 08:55 AM

Nice DLL, please add .obj or .3ds support because .mod format is a pain in the neck.

Thanks

<{POST_SNAPBACK}>

D3D can draw ONLY GM model arrays!
All the scripts which load obj files are converting the file to GM model array.
And this DLL uses this model array.
Great DLL.Just awsome!

AND: OBJ file is a pain in the neck...You can only load it with script.Its biger that the mod format.The script for loading models is very slow because the slow file functions :D .There is a program for converting OBJ to MOD.

Edited by Ivo Georgiev, 25 September 2007 - 09:02 AM.

  • 0

#9 xygthop3

xygthop3

    The one who knocks

  • GMC Member
  • 3041 posts
  • Version:GM:Studio

Posted 25 September 2007 - 10:35 PM

I also found the bug that freko found, and it freezes the game and has to be closed via task manager.

Also, the collisions with a ramp with even a small incline on 10deg's could use some work.

Edited by xygthop3, 26 September 2007 - 12:13 AM.

  • 0

#10 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 26 September 2007 - 12:31 AM

I also found the bug that freko found, and it freezes the game and has to be closed via task manager.

Also, the collisions with a ramp with even a small incline on 10deg's could use some work.

<{POST_SNAPBACK}>


The ball getting stuck might be a while loop not ending for some reason. I'll look in to it.

And about the ramp collision, you want it to climb slopes right? If that's not what you meant pleas explain farther.

obj and 3ds formats are not supported(yet). I might add these if I read about the file formats a bit. If anyone is willing to help me and make a few scripts, here are the steps you need to take:

1. Create a new script
2. set a temporary variable to begin_define_model()//(i.e. var modelid;modelid=begin_define_model(); )
3. Write some code to extract triangles from file. Refer to file format documentations to know how to parse it.
3. use model_add_point and model_add_triangle to add triangles read from file to the dlls model.
4. call end_define_model()
5. return modelid

Thanks for the comments,
-hanson

Edited by hanson, 25 March 2008 - 02:24 PM.

  • 0

#11 xygthop3

xygthop3

    The one who knocks

  • GMC Member
  • 3041 posts
  • Version:GM:Studio

Posted 26 September 2007 - 12:35 AM

And about the ramp collision, you want it to climb slopes right?  If that's not what you meant pleas explain farther.

<{POST_SNAPBACK}>


Yep, climb slopes, ramps, terrain.....etc,etc
  • 0

#12 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 26 September 2007 - 12:39 AM

And about the ramp collision, you want it to climb slopes right?  If that's not what you meant pleas explain farther.

<{POST_SNAPBACK}>


Yep, climb slopes, ramps, terrain.....etc,etc

<{POST_SNAPBACK}>

I'll see if I can add that to the example when I release an update to the dll.
  • 0

#13 xygthop3

xygthop3

    The one who knocks

  • GMC Member
  • 3041 posts
  • Version:GM:Studio

Posted 26 September 2007 - 12:41 AM

And about the ramp collision, you want it to climb slopes right?  If that's not what you meant pleas explain farther.

<{POST_SNAPBACK}>


Yep, climb slopes, ramps, terrain.....etc,etc

<{POST_SNAPBACK}>

I'll see if I can add that to the example when I release an update to the dll.

<{POST_SNAPBACK}>


I'll try my hand at it and see if I can convert the Mosaic Lite .obj script to work with this as well, shouldn't be to hard.

Edited by xygthop3, 26 September 2007 - 12:42 AM.

  • 0

#14 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 26 September 2007 - 12:50 AM

Okay, Thanks! You can look at the scripts in the example under the 'plugins' sub-folder if you want to see the completed import code.
-hanson
  • 0

#15 xygthop3

xygthop3

    The one who knocks

  • GMC Member
  • 3041 posts
  • Version:GM:Studio

Posted 26 September 2007 - 02:12 AM

Just a little thing. I noticed you didn't use file_text_close(), this is quite important.
  • 0

#16 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 26 September 2007 - 02:16 AM

I fixed that and updated the download. Thanks for noticing.
-hanson

Edited by hanson, 26 September 2007 - 02:26 AM.

  • 0

#17 xygthop3

xygthop3

    The one who knocks

  • GMC Member
  • 3041 posts
  • Version:GM:Studio

Posted 26 September 2007 - 08:14 AM

Great, here is the script to load collisions for .obj models, use the same as you would with load_model_mod();

You will need to use Mosaic Lite Script to load the .obj and draw it however.

I will add an example later.

//obj_loader for MODMODCollision DLL by xygthop3 will load collisions for .obj models. ENJOY!//Use create_from_obj by Zoltan Percsich to draw the obj model.data=ds_list_create();if(!file_exists(argument0)) return(-1);//return -1 if file not foundfile=file_text_open_read(argument0);modelid=begin_define_model();//show_message("start load model:"+argument0+"  id:"+string(modelid))for (i=0;file_text_eof(fp)==false;i+=1) {    filetext=file_text_read_string(fp);//row=string_replace_all(row,"  "," ");        if (string_char_at(filetext,1)=="v" && string_char_at(filetext,2)==" ") {//  start=string_pos_ext(" " , filetext , 1)//  count=string_pos_ext(" " , filetext , 2);    filetext=string_copy(filetext,3,28);    ds_list_clear(data);    string_to_list_ext(filetext," ",data);    model_add_point_fromlist(data);//    show_list(data)    ds_list_clear(data)    }       file_text_readln(fp);          }end_define_model();file_text_close(fp);ds_list_destroy(data);return(modelid);

Posted Image

Edited by xygthop3, 26 September 2007 - 08:23 AM.

  • 0

#18 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 26 September 2007 - 12:32 PM

I am having a bit of trouble with your script. It seems as if the points are sometimes reused in the obj file format. We will have to also parse the faces. That should be easy though...
Good job so far.
Thanks,

-hanson
  • 0

#19 xygthop3

xygthop3

    The one who knocks

  • GMC Member
  • 3041 posts
  • Version:GM:Studio

Posted 26 September 2007 - 08:57 PM

Help?

I did notice that .obj's exported from Marzipan the faces are ordered 1-2-3-4 etc,etc

.obj's exported from Anim8or the faces seem to be ordered in order they were created in anim8or (eg: 13-14-15). I could add parsing with a little help from Mosaic Lite, but for now, just run the models through Marzipan for a shot term fix. :D

Edited by xygthop3, 26 September 2007 - 10:00 PM.

  • 0

#20 Slick

Slick

    The Wheelman

  • GMC Member
  • 268 posts

Posted 27 September 2007 - 08:03 AM

hanson, I'd just like to say great work on this. This is indeed something many people including myself have been either trying to create ourselves or find. You have delivered the gold :D

I see a lot of potential in this if used correctly, can't wait to see what future updates will offer.

Edited by Slick, 27 September 2007 - 08:25 AM.

  • 0

#21 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 29 September 2007 - 11:21 AM

Help?

I did notice that .obj's exported from Marzipan the faces are ordered 1-2-3-4 etc,etc

.obj's exported from Anim8or the faces seem to be ordered in order they were created in anim8or (eg: 13-14-15). I could add parsing with a little help from Mosaic Lite, but for now, just run the models through Marzipan for a shot term fix.  :unsure:

<{POST_SNAPBACK}>


Good work! I'll give that a try.

@Slick: Thanks!

-hanson
  • 0

#22 eat268

eat268

    Videogame Programmer

  • New Member
  • 335 posts

Posted 01 October 2007 - 12:33 AM

Are the collisions perfect?
  • 0

#23 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 01 October 2007 - 02:41 AM

Are the collisions perfect?

<{POST_SNAPBACK}>


Yes, the collisions are perfect. Every triangle in first model is collision checked with every triangle in second model.

-hanson
  • 0

#24 freko

freko

    The Professional

  • GMC Member
  • 504 posts
  • Version:GM8

Posted 01 October 2007 - 06:40 PM

Howz work on the rotations going on.

Will you be adding forces too..?
  • 0

#25 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 02 October 2007 - 12:52 PM

Howz work on the rotations going on.

Will you be adding forces too..?

<{POST_SNAPBACK}>


The rotations are going slow. I'm not an expert on 3d math. I have been reading on how to do them though. About forces... if you mean physics, I am not planning on it.

-hanson
  • 0

#26 xygthop3

xygthop3

    The one who knocks

  • GMC Member
  • 3041 posts
  • Version:GM:Studio

Posted 10 October 2007 - 09:58 PM

A bump on the house.
  • 0

#27 dmitko

dmitko

    GMC Member

  • GMC Member
  • 1011 posts
  • Version:Unknown

Posted 20 October 2007 - 07:51 AM

This is what GM needs. Well done!
  • 0

#28 Proffessor_gad

Proffessor_gad

    GMC Member

  • New Member
  • 757 posts

Posted 13 November 2007 - 10:25 PM

I've been working on a 3d engine of my own with physics, real gravity, parenting, spheroids, fast rotate, fast resize, .obj import and stuff. But it doesn't have model -> model collissions. Maybe if we work together we can cook up something good. ;)



The main problem for both of us is that GM IS SLOW... So whoever uses this engine definately needs to simplify their models.

Edited by Proffessor_gad, 14 November 2007 - 04:12 AM.

  • 0

#29 hanson

hanson

    GMC Member

  • GMC Member
  • 444 posts
  • Version:GM8

Posted 14 November 2007 - 01:28 PM

I've been working on a 3d engine of my own with physics, real gravity, parenting, spheroids, fast rotate, fast resize, .obj import and stuff. But it doesn't have model -> model collissions. Maybe if we work together we can cook up something good.  ^_^



The main problem for both of us is that GM IS SLOW... So whoever uses this engine definately needs to simplify their models.

<{POST_SNAPBACK}>


Sure, we coult try :) . I am slowly getting through the model rotations code. Currently I am able to rotate one point with any xrot,yrot,and zrot. There shouldn't be too much work to do from here. I haven't had a lot of time to work on it lately though. I think adding the rotations is going to slow it down a bit. I might try wrapping ColDet , a Free 3D Collision Detection Library for C++. It would probably be much faster than my code.
If you would be willing, might I take a look at your progress on your 3d engine so far? It sound interesting.

-hanson
  • 0

#30 gamescoper

gamescoper

    GMC Member

  • New Member
  • 21 posts

Posted 14 November 2007 - 07:51 PM

superb hanson you siad you would make this and you delivered this is great no more 2d:3d ratios yesssssssssssssss!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users