Jump to content


Photo

3D Collision Detection DLL


  • Please log in to reply
64 replies to this topic

#1 Venomous

Venomous

    GMC Member

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

Posted 02 August 2014 - 04:25 AM

This is a 3D collision detection DLL for GameMaker: Studio. Written in C++ using the Bullet library's collision detection functions.
 
Features:

  • Shapes: sphere, box, capsule, cone, cylinder, plane
  • Triangle meshes
  • Load trimesh from model file
  • Compound shapes
  • Collision objects
  • World system
  • Masks for filtering collisions
  • Raycast test
  • Overlap test
  • Sweep test
  • Get position, surface normal, and distance of hit from raycasts and sweeps
  • Transformations: translation, rotation, and scaling
  • Very fast.

 

Functions:
Note: All scripts are prefixed with "c_" for "collision".

Spoiler

 
Usage:

  • Create the collision world
  • Create a collision shape
  • Create a collision object, which uses the shape. (reuse the shape as many times as you like)
  • Add the collision object to the world
  • Perform collision checks on the world or on the object

 

Limitations:
Overlap tests do not work between two trimeshes. You can however, check collisions between any other kind of shape and a trimesh.
You cannot perform a sweep test with a trimesh because swept shapes need to be convex. You can do sweep tests against them.
Scaling has limitations. It only works on shapes, not objects, and not all shapes support non-uniform scaling.
Limited testing done so far. May contain bugs.
 
Download: v5


Edited by Venomous, 14 October 2015 - 06:28 PM.

  • 18

#2 Sirosky

Sirosky

    GMC Member

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

Posted 02 August 2014 - 03:29 PM

Dude this is amazing! +1


  • 1

gcjRa8D.png


#3 MishMash

MishMash

    GMC Member

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

Posted 02 August 2014 - 03:43 PM

Might aswell ask, but how does this compare with P3DC? Looks interesting :)!


  • 2

VitalitySig18thMar.png


#4 slojanko

slojanko

    HARD GAMER

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

Posted 02 August 2014 - 03:51 PM

Do you plan to add physics?


  • 0

Games in progress:

The unexpected: [--------------------]

My examples on YYG sandbox

My games on GameJolt

 


#5 Venomous

Venomous

    GMC Member

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

Posted 02 August 2014 - 04:01 PM

Might aswell ask, but how does this compare with P3DC? Looks interesting :)!

Aside from the extra features, this DLL is much faster. I looked through the source code for P3DC and it appears to loop through every triangle in a model during a collision check. That is very inefficient. This DLL uses an internal hierarchy to accelerate collision checks. The primitive shapes are actual mathematical shapes and are not made of triangles, as in P3DC. This also makes it more efficient.

 

 

Do you plan to add physics?

I do not plan on adding physics. There is already a full fledged(although somewhat older) bullet physics wrapper here.


Edited by Venomous, 02 August 2014 - 04:03 PM.

  • 0

#6 MishMash

MishMash

    GMC Member

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

Posted 02 August 2014 - 05:02 PM

 

 

Aside from the extra features, this DLL is much faster. I looked through the source code for P3DC and it appears to loop through every triangle in a model during a collision check. That is very inefficient. This DLL uses an internal hierarchy to accelerate collision checks. The primitive shapes are actual mathematical shapes and are not made of triangles, as in P3DC. This also makes it more efficient.

 

Ah ok then! How exactly is the "trimesh" format constructed? Will I be able to load in GM D3D models, or is this some custom format?


  • 0

VitalitySig18thMar.png


#7 Venomous

Venomous

    GMC Member

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

Posted 02 August 2014 - 05:17 PM

 

 

Ah ok then! How exactly is the "trimesh" format constructed? Will I be able to load in GM D3D models, or is this some custom format?

 

A trimesh is just a model made of triangles. The c_shape_add_triangle() function lets you create a trimesh from any format you like. There's a script included which loads a trimesh from a GM model file. Works with models exported from Model Creator.


  • 0

#8 MishMash

MishMash

    GMC Member

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

Posted 02 August 2014 - 05:21 PM

 

A trimesh is just a model made of triangles. The c_shape_add_triangle() function lets you create a trimesh from any format you like. There's a script included which loads a trimesh from a GM model file. Works with models exported from Model Creator.

Alrighty then! Nice :)


  • 0

VitalitySig18thMar.png


#9 Venomous

Venomous

    GMC Member

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

Posted 07 August 2014 - 02:10 AM

Update. A few new functions were added, most notably two functions to get and set a user id. Take a look at c_object_set_userid() and c_object_get_userid(). It can be any unsigned integer, but it is useful in particular to link a collision object with a GM instance. After performing a raycast, for example, you can then easily find which instance was hit. Also did some small optimizations and improved the example. New download link in first post.


  • 2

#10 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 15 August 2014 - 08:06 AM

Does this work  when using deactivation in big rooms with a incredible amount of objects?

Btw the bullet system seems to be working perfect. Really great for adding decals/bullet holes.


Edited by Alvare, 15 August 2014 - 08:07 AM.

  • 0

#11 Venomous

Venomous

    GMC Member

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

Posted 15 August 2014 - 06:06 PM

Does this work  when using deactivation in big rooms with a incredible amount of objects?

It should handle lots of collision objects at once with decent speed. If you want collision objects to be deactivated along with your GameMaker instances, you can remove them from the world with c_world_remove_object(), then when you want to reactivate, call c_world_add_object().


  • 1

#12 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 15 August 2014 - 07:43 PM

 

Does this work  when using deactivation in big rooms with a incredible amount of objects?

It should handle lots of collision objects at once with decent speed. If you want collision objects to be deactivated along with your GameMaker instances, you can remove them from the world with c_world_remove_object(), then when you want to reactivate, call c_world_add_object().

 

Decent speed is not enough because there are over 2000 3D instances in the room. So I'd rather have them activate/deactivate at some distance.

Should I do this in a step event?


Edited by Alvare, 15 August 2014 - 08:03 PM.

  • 0

#13 Venomous

Venomous

    GMC Member

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

Posted 15 August 2014 - 09:36 PM

 

 

Does this work  when using deactivation in big rooms with a incredible amount of objects?

It should handle lots of collision objects at once with decent speed. If you want collision objects to be deactivated along with your GameMaker instances, you can remove them from the world with c_world_remove_object(), then when you want to reactivate, call c_world_add_object().

 

Decent speed is not enough because there are over 2000 3D instances in the room. So I'd rather have them activate/deactivate at some distance.

Should I do this in a step event?

 

I suggest trying it without deactivation first and see how fast it runs. I did a quick test with 5000 cubes. I got around 600 FPS with over 50 bullets all raycasting at once. I think that's fast enough.


  • 0

#14 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 16 August 2014 - 09:36 AM

Cool. I'm using sprites for collision right now and most of them are set to non-precise anyway. I'll try tomorrow or tonight.  :thumbsup:


Edited by Alvare, 16 August 2014 - 09:36 AM.

  • 0

#15 -RepublicCommando-

-RepublicCommando-

    GMC Member

  • New Member
  • 13 posts
  • Version:GM8

Posted 23 August 2014 - 02:17 AM

This DLL surpasses the P3DC DLL very well.. You have done a brilliant job with this (I'm just learning C++, so it's actually very inspiring), and I'm going to make an attempt at using it in GM8.0.

If I end up getting it to work in that version, I'll go ahead and post my work so other non-GMS users can take a peak.

 

I've made a simple script to kind of macro a few of yours (to simplify object creation in coding terms), that returns the handle of the finished object when executed.

I must get my game fully set up to test it of course, but that will be in the example I post when/if I get it working.

 

Again, brilliant job.


  • 0

"Foul language is the attempt of an feeble mind trying to express itself."


#16 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 06 September 2014 - 09:18 AM

I really don't know how to attach a collision to the camera. Didn't work when doing the same thing as the bullet.

Might need use the same code as the boxes, perhaps?

 

if(c_overlap_world(object))
{
    var u = keyboard_check(ord("W"))-keyboard_check(ord("S"));
    var r = keyboard_check(ord("D"))-keyboard_check(ord("A"));
    var dir = point_direction(0, 0, u, r)+aim_dir;
    
    var spd = 1;
    x -= lengthdir_x(1, dir)*lengthdir_x(1, aim_zdir*u)*spd;
    y -= lengthdir_y(1, dir)*lengthdir_x(1, aim_zdir*u)*spd;
    z -= lengthdir_y(1, aim_zdir*u)*spd; 
}

When adding the box collision to the camera, this'll stop the camera from going through static collision but it's stuck unless you go the opposite way. It also bugs out on floors and ceilings.

Could you please show me the better way?  :)

 

This DLL does not include any form of collision response. It is for collision detection only.

So it's not made to do this?  :sweat:


Edited by Alvare, 06 September 2014 - 09:33 AM.

  • 0

#17 Venomous

Venomous

    GMC Member

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

Posted 08 September 2014 - 04:37 PM

I really don't know how to attach a collision to the camera. Didn't work when doing the same thing as the bullet.
Might need use the same code as the boxes, perhaps?
 
When adding the box collision to the camera, this'll stop the camera from going through static collision but it's stuck unless you go the opposite way. It also bugs out on floors and ceilings.
Could you please show me the better way?  :)

It's better to use a sweep test for that, so you can move to the exact point of the collision and use surface normal of the collision for sliding. I'll try to make an example of this, if I can find the time.

This DLL does not include any form of collision response. It is for collision detection only.

So it's not made to do this?  :sweat:

That just means you have to code the collision response yourself, just like you are doing. Now that you mention it, it does sound a little misleading.

Edit: Done. I updated the example with some basic collision response code, as well as some other minor changes. Link is updated in first post.

Edited by Venomous, 08 September 2014 - 09:18 PM.

  • 1

#18 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 09 September 2014 - 10:00 PM

Awesome. Gonna check it out right now!

 

Another question.. if a 3D path is set up with gm's pr_trianglestrip, would it be possible to use that as a trimesh?

It's for checking if the character is walking on the grass or the path.  :biggrin:

 

EDIT -

Collision is indeed far from perfect. Got stuck or hangs and random fps drops when testing and wildly flying against every geometry. xD

Maybe I should only use this to check collision for now.


Edited by Alvare, 09 September 2014 - 10:07 PM.

  • 0

#19 Venomous

Venomous

    GMC Member

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

Posted 10 September 2014 - 02:24 AM



Awesome. Gonna check it out right now!

 

Another question.. if a 3D path is set up with gm's pr_trianglestrip, would it be possible to use that as a trimesh?

It's for checking if the character is walking on the grass or the path.  :biggrin:

 

EDIT -

Collision is indeed far from perfect. Got stuck or hangs and random fps drops when testing and wildly flying against every geometry. xD

Maybe I should only use this to check collision for now.

Strange, it seemed to be working fine when I was testing it. Obviously I didn't test it enough :P

 

Yes, you can set up a trimesh for your path but you'll have to split your trianglestrip into individual triangles. Add the triangles to your trimesh with c_shape_add_triangle().

 

Edit: I thought I should mention this. If your levels only consist of axis-aligned geometry, then it is really easy to get smooth collisions. You just cancel movement on the axis that is blocked. Like this:

if(c_sweep_world(shape, x, y, z, x+xmove, y, z, mask)) xmove = 0;
if(c_sweep_world(shape, x, y, z, x, y+ymove, z, mask)) ymove = 0;
if(c_sweep_world(shape, x, y, z, x, y, z+zmove, mask)) zmove = 0;
x += xmove;
y += ymove;
z += zmove;

Your shape needs to be a box for this to work properly.


Edited by Venomous, 10 September 2014 - 03:08 AM.

  • 0

#20 Alvare

Alvare

    Not an administrator

  • GMC Member
  • 1812 posts
  • Version:None

Posted 10 September 2014 - 10:49 AM

Edit: I thought I should mention this. If your levels only consist of axis-aligned geometry, then it is really easy to get smooth collisions. You just cancel movement on the axis that is blocked. Like this:

<Snip>

Your shape needs to be a box for this to work properly.

 

No, the geometry is sometimes angled.

 

Yes, you can set up a trimesh for your path but you'll have to split your trianglestrip into individual triangles. Add the triangles to your trimesh with c_shape_add_triangle().

By hand? Or is there a way to use the existing model? 0_o


Edited by Alvare, 10 September 2014 - 11:00 AM.

  • 0

#21 UKDutyPaid

UKDutyPaid

    GMC Member

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

Posted 23 September 2014 - 05:13 PM

Thanks for this.  Only just started playing with it, but it's working great so far, about as simple as it can get wrt integration, kudos.  It's a great little demo project too, the bullet physics is a very handy example!  I've been using PC3D before now, but I think you might have a convert.  With this, shaders and the ability to get mipmapping through windows_device dll I'm considering actually pursuing one of my many previously abandoned 3d projects.  GM is finally getting the toolbox it needs! cheers.


  • 0

#22 qualityproduckshunz

qualityproduckshunz

    Female member

  • Banned Users
  • 109 posts
  • Version:GM:Studio

Posted 21 December 2014 - 08:17 PM

I tried to load this in studio and it gave me an exception related to some sort of config file. I haven't updated to the latest version of Studio.

 

I browsed through the scripts and they seem like they are enough to make a game. Question is, are they to be trusted?


It's time to be vegan.


#23 Venomous

Venomous

    GMC Member

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

Posted 21 December 2014 - 11:21 PM

It should work with the latest version of Studio. I don't know of any games that use this, so it hasn't been tested much. If you find a bug let me know and I'll look into it.
  • 1

#24 chreechokash007

chreechokash007

    GMC Member

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

Posted 04 February 2015 - 02:10 PM

How to actually make collision with complicated d3d models like helicopter,car etc..? All i can see in this are some basic shapes like cube,cylinder etc. Please help.


  • 0

#25 chreechokash007

chreechokash007

    GMC Member

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

Posted 04 February 2015 - 03:59 PM

It's just alright. I figured that out already.


  • 0

#26 slayer 64

slayer 64

    Slayer of gingers

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

Posted 05 February 2015 - 02:48 AM

how's the collision response part coming? if you could just get a shape to slide against something and get pushed out of that way that would be really valuable. never mind the full-on physics and rotations. i would even throw money at that.
  • 0

5y5rs3d.pngfg0UQNL.png


#27 chreechokash007

chreechokash007

    GMC Member

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

Posted 05 February 2015 - 04:08 AM

Everything seems to be working like a charm except that when i scale a 3d model the c_transform_scaling don't seems to be forming any synch with that. Means when i scale a 3d model and also scale collision object using c_transform_scaling in the same way but the collision positions get disturbed. Please help me on that.


  • 0

#28 chreechokash007

chreechokash007

    GMC Member

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

Posted 05 February 2015 - 01:44 PM

Please fix the scaling for trimesh.


  • 0

#29 Venomous

Venomous

    GMC Member

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

Posted 13 February 2015 - 04:14 PM

how's the collision response part coming? if you could just get a shape to slide against something and get pushed out of that way that would be really valuable. never mind the full-on physics and rotations. i would even throw money at that.

I've been working on collision response for collisions against non axis-aligned geometry, but so far I don't have a good solution.

 

 

Everything seems to be working like a charm except that when i scale a 3d model the c_transform_scaling don't seems to be forming any synch with that. Means when i scale a 3d model and also scale collision object using c_transform_scaling in the same way but the collision positions get disturbed. Please help me on that.

Keep in mind that not all shapes support non-uniform scaling. Only boxes and trimeshes support non-uniform scaling on each axis. You can't scale a sphere on only the X axis, for example. If you have a trimesh that isn't scaling properly then that could be a bug.


  • 0

#30 chreechokash007

chreechokash007

    GMC Member

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

Posted 14 February 2015 - 02:43 PM

I was scaling a bus object all the 3 axis x,y,z equally from scale of 1 to 2 and it looks like collision positions remained the same just the model got doubled.


  • 0

#31 Venomous

Venomous

    GMC Member

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

Posted 14 February 2015 - 07:01 PM

Only shapes can be scaled. Are you sure that you're scaling the shape and not the object?


Edited by Venomous, 14 February 2015 - 07:04 PM.

  • 0

#32 chreechokash007

chreechokash007

    GMC Member

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

Posted 15 February 2015 - 03:49 AM

lol that was an object. So is there any possibility for objects to support scaling in future?


  • 0

#33 Venomous

Venomous

    GMC Member

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

Posted 15 February 2015 - 10:04 PM

This is actually a limitation of the Bullet library itself and not something I can change. You could always create a shape for each object and scale that.


  • 0

#34 chreechokash007

chreechokash007

    GMC Member

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

Posted 16 February 2015 - 03:16 PM

Ok in my game there are 600 walls and for each of them a separate collision is created using c_shape_add_box which makes the frame rate come down. So i decided to create a single scene of 600 walls and loaded it in a global variable. Now the problem is that how can i also make a single collision shape for the scene because creating 600 different collision objects is bringing down the frame rate? Do i need to load the scene with c_shape_load_trimesh() somehow or need to construct a trimesh using c_shape_begin_trimesh and then adding triangles manually to fit the scene? Please help me.


  • 0

#35 Venomous

Venomous

    GMC Member

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

Posted 16 February 2015 - 04:11 PM

The game should not slow down with only 600 boxes. I did a test a while ago where I created with several thousand boxes and the frame rate was still high. Can you give me some more specifics on your setup? Show me your code?


  • 0

#36 chreechokash007

chreechokash007

    GMC Member

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

Posted 16 February 2015 - 04:21 PM

sorry with 5000 walls not 600. Basically i wanted to know if there is a way to create a single shape from all the walls so that there remains only one collision object for the whole walls scene.


Edited by chreechokash007, 16 February 2015 - 04:22 PM.

  • 0

#37 Venomous

Venomous

    GMC Member

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

Posted 16 February 2015 - 04:36 PM

I doubt that combining all the walls into one shape will help with performance. Collision objects do not slow down the game much unless they are involved in a collision check. Do you have a GameMaker instance for each collision object? That is unnecessary and could be the source of the slowdown. To answer your question though, yes, that should be possible. You could set the transform position before each c_shape_add_box() call, to give each box its own position within the shape.


  • 0

#38 chreechokash007

chreechokash007

    GMC Member

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

Posted 16 February 2015 - 04:44 PM

Please tell me in code step wise. You mean like this-

shape=c_shape_create()
with(obj_wall)
{
c_transform_position(x,y,z)
c_shape_add_box(shape,16,0,32)
}
object=c_object_create(shape,MASK_SOLID,MASK_PLAYER)
c_world_add_object(object)
c_object_apply_transform(object)
c_transform_identity()

Edited by chreechokash007, 16 February 2015 - 04:49 PM.

  • 0

#39 Venomous

Venomous

    GMC Member

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

Posted 16 February 2015 - 04:54 PM

If you want all the boxes in one shape, then yes, that would be the way to do it.


  • 0

#40 chreechokash007

chreechokash007

    GMC Member

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

Posted 16 February 2015 - 05:00 PM

The above code is giving error. Maybe i am doing something wrong. Please rectify the error in my above code.


  • 0

#41 chreechokash007

chreechokash007

    GMC Member

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

Posted 16 February 2015 - 05:10 PM

Ok that worked.Thanks man.


  • 0

#42 chreechokash007

chreechokash007

    GMC Member

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

Posted 17 February 2015 - 06:05 AM

Is it supported with android?


  • 0

#43 Venomous

Venomous

    GMC Member

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

Posted 17 February 2015 - 06:15 PM

DLL's are Windows only, so no.


  • 0

#44 johnboy

johnboy

    GMC Member

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

Posted 31 May 2015 - 09:50 AM

Hi. I'm looking for a raycaster for use in a 2d game - will this help with collision's, and what does it require (if anything) to use in 2d? I'm assuming that Studio still benefits from this for the performance boost? (Don't mean to be rude to YoYo - but I've never understood why people are able to do all the things GMS doesn't seem very good for - like if I tried collision_line it would be slow, yet a raycast is fast -? why don't they do it?). Will download this if it's still available, and hopefully you won't mind a few pointers for using it?

 

Thanks!


  • 0

#45 joshuaallen64

joshuaallen64

    GMC Member

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

Posted 31 May 2015 - 12:18 PM

Can you take a look at c_raycast_object, you overlooked something there. 

The script definition asks for 8 arguments but only uses 7.


  • 0

#46 CaptainLepidus

CaptainLepidus

    GMC Member

  • GMC Member
  • 852 posts
  • Version:GM:HTML5

Posted 11 August 2015 - 04:55 AM

Hey, this looks like just what I was looking for for my project, but unfortunately calling c_world_add_object is crashing my game. full code:

 

c_init();
c_world_create();
    
shape = c_shape_create();
shape = c_shape_add_box( shape ,1500,1500,0);
object = c_object_create(shape,MASK_SOLID,MASK_NONE);
c_world_add_object( object );

Is there something else I need to do before adding my object to the world? 


  • 0

"The reason programming is addictive is the same reason a good game is addictive: it constantly feeds you with a sense of minor accomplishment on your way to [achieving] the greater goal."

Yal

Planning to build a network of like-minded, innovative GameMaker developers, connected by a set of tools for building awesome games. Interested? PM me.


#47 hippyman

hippyman

    Dirty Stinky Hippy

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

Posted 11 August 2015 - 10:32 PM

 

Hey, this looks like just what I was looking for for my project, but unfortunately calling c_world_add_object is crashing my game. full code:

 

c_init();
c_world_create();
    
shape = c_shape_create();
shape = c_shape_add_box( shape ,1500,1500,0);
object = c_object_create(shape,MASK_SOLID,MASK_NONE);
c_world_add_object( object );

Is there something else I need to do before adding my object to the world? 

 

You don't need the "shape = " part before c_shape_add_box. That's more than likely the issue 


  • 1

 badge.png?dl=0

HM Audio Soundcloud: https://soundcloud.com/hm-audio


#48 -Oakleaf-

-Oakleaf-

    Whipslash

  • GMC Member
  • 1420 posts

Posted 11 October 2015 - 10:25 AM

Impressive. And easy to use.

 

I have just one problem: transformations. Seems to me, you can only use one c_transform_rotation and c_transform_position before applying the transformation to the object. That is, I can't stack transformations like with the d3d_transform functions. Am I correct?

 

So for example, I can't do this:

//Turret
c_transform_rotation(0,0,turr_dir-hull_rot_z);
c_transform_position(0,0,hull_h+turr_h/2);
c_transform_rotation(hull_rot_x,hull_rot_y,hull_rot_z);
c_transform_position(x,y,z);
c_object_apply_transform(object_turr);
c_transform_identity();

Because it'll ignore the first 2 transformations. Or am I just misunderstandig something?


  • 0

#49 Venomous

Venomous

    GMC Member

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

Posted 12 October 2015 - 02:04 AM

Yeah, it won't stack. The simplest way for me to fix this would be to add a function to pass in your own matrix. That way you could use the d3d_transform functions if you want and then pass in the result via matrix_get(). I haven't touched the source in quite a while, so I'm not sure how much work it'd be. Let me know if you need this.


  • 1

#50 TheSnidr

TheSnidr

    Heavy metal viking dentist

  • GMC Elder
  • 3345 posts
  • Version:GM:Studio

Posted 12 October 2015 - 07:00 AM

Wouldn't it just require multiplying the rotation matrix with the transformation matrix?
  • 1