AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Module: BMOD - Extended Physics Module (https://forums.alliedmods.net/showthread.php?t=178066)

Backup 02-10-2012 16:11

Module: BMOD - Extended Physics Module
 
2 Attachment(s)
https://github.com/jonatan1024/bgmod..._logo/bmod.png

What is BMOD?
BMOD allows amxx developers to use physics engine (Bullet) inside their plugin. There are few videos, so you can get the idea, what kind of things can be achieve with this:
http://www.youtube.com/watch?v=WxbXrLsKFGQ
http://www.youtube.com/watch?v=Nn26KkoIGNY
http://www.youtube.com/watch?v=pAocm7bZszs
http://www.youtube.com/watch?v=CUmNRsVro1U
http://www.youtube.com/watch?v=vUCIKGlyDBQ
http://www.youtube.com/watch?v=fAJlHJehlI8

How does it work?
There is an API which gives you the ability to create dynamic, static or kinematic objects inside the "bullet world". After creating an dynamic object, you connect it to some entity and this entity now copies the object's movement. Dynamic objects can be used as anything that moves freely, for example pink rubber balls boucing all across the map. In case of static object, no movement is copied, but you can still work with the object, set its properties, etc. These can be used for building the world, making walls or triggers. Kinematic objects are exact opposite of dynamic objects - they copy their entity's movement. That is useful for player collision box or for moving brush entities like doors, trains, etc.

Documentation?
For documentation just grab latest inc file, everything should be written in there.

Hello world?

Here is a simple example where you can learn how to create static world, dynamic spheres, kinematic player collision box and modify behaviour of some objects (bounciness).

Code:

#include <amxmodx>
#include <amxmisc>
#include <bmod>
#include <engine>

new worldObj

public plugin_init() {
    register_concmd("bmod_test","_bmod_test")
    //create static bmod object from worldspawn
    worldObj = bmod_obj_from_ent(0)
    //set world friction and restitution
    bmod_obj_call(worldObj, "setFriction", 1.0)
    bmod_obj_call(worldObj, "setRestitution", 1.0)
}

public _bmod_test(id){
    //create a new entity
    new entity = create_entity("func_wall")
    entity_set_model(entity,"models/fyzsph.mdl")
    //set entity origin 128 units above player
    new Float:origin[3]
    entity_get_vector(id,EV_VEC_origin,origin)
    origin[2]+=128
    entity_set_origin(entity,origin)
    //set some movetype and nextthink, so entity movement is smoother (because of velocity and avelocity)
    entity_set_float(entity,EV_FL_nextthink,86400.0)
    entity_set_int(entity,EV_INT_movetype,8)
    //create new bmod object
    new object = bmod_obj_new("BMOD/sphere/24", 1.0)
    //hook entity with bmod object
    bmod_obj_assign_ent(object, entity)
    bmod_obj_update_pos(object)
   
    //set object friction and restitution
    bmod_obj_call(object, "setFriction", 2.0)
    bmod_obj_call(object, "setRestitution", 0.88)
}

public client_connect(plr){
    //create collision box for a player
    new obj = bmod_obj_new("BMOD/box/16/16/36")
    bmod_obj_assign_ent(obj, plr)
    bmod_obj_set_kinematic(obj, true)
}

public client_disconnect(plr){
    bmod_obj_delete(bmod_obj_by_ent(plr))
}

public plugin_precache(){
    precache_model("models/fyzsph.mdl")
}



More?
Download bmod_test.zip form the attached files. It contains more complicated example and also that fyzsph.mdl you might be looking for.
You can also check out CrateNade plugin.

Latest binaries/source

Download latest binaries from GitHub (windows,linux).
Download latest amxx include file from Github.
View latest source at GitHub.

Additional info
Your feedback, wishes and english mistakes corrections are appreciated!

Current linux release requires Bullet shared libraries to be put into hlds root directory. If there is anyone who can recompile this module for linux without the need for bullet shared libs, your help is very welcome.

Attached zip file might be several years old and contain some serious bugs.

If you're looking for old-api bmod, see legacy branch. It's full of bugs and has been discontinued.

Thanks joropito for helping me with GitHub and other support.

mabaclu 02-10-2012 16:33

Re: Module: BMOD - Extended Physics Module
 
Finally released! Good job!

.Dare Devil. 02-10-2012 17:07

Re: Module: BMOD - Extended Physics Module
 
I just cant belive it,

this is better than hl2 Physics omg.
Good job!

hleV 02-10-2012 17:14

Re: Module: BMOD - Extended Physics Module
 
Sweet!

zeus 02-10-2012 17:42

Re: Module: BMOD - Extended Physics Module
 
Awsome work dude !!
We apreciate
http://assets.diylol.com/hfs/f07/478...ome-99ecc3.jpg

xPaw 02-11-2012 04:50

Re: Module: BMOD - Extended Physics Module
 
Quote:

Originally Posted by .Dare Devil. (Post 1648059)
this is better than hl2 Physics omg.

Let's get real, it is not better than HL2 physics.

.Dare Devil. 02-11-2012 08:39

Re: Module: BMOD - Extended Physics Module
 
Quote:

Originally Posted by xPaw (Post 1648248)
Let's get real, it is not better than HL2 physics.

I tested it and tested hl2 physics.
And i take back my words :):):):):):)

But this module here, is so fucking awsome.
That bounce balls and spike physics is so nice.

I think it is impossible on hl2 physics :)
that way i said that is better than hl2 physics.

HL2 physics are too real :)
but better player touch...

Steelec 02-11-2012 09:25

Re: Module: BMOD - Extended Physics Module
 
Awesome! Wery NICE! GJ ;)

Kiske 02-12-2012 07:05

Re: Module: BMOD - Extended Physics Module
 
EXCELENT!

You upload the plugin that samples in the video: http://www.youtube.com/watch?v=Nn26KkoIGNY ?
You upload the models/fyzsph.mdl ?

Backup 02-12-2012 08:37

Re: Module: BMOD - Extended Physics Module
 
1 Attachment(s)
Quote:

Originally Posted by Kiske (Post 1648872)
EXCELENT!

You upload the plugin that samples in the video: http://www.youtube.com/watch?v=Nn26KkoIGNY ?
You upload the models/fyzsph.mdl ?

Code:

#include <amxmodx>
#include <engine>
#include <bmod>

public plugin_init() {
    register_plugin("bmod_test","0","asdf")
    register_concmd("bmod_test","_bmod_test")
}

new i=0

public _bmod_test(id){
    new entity = create_entity("func_wall")
    switch(i%5){
        case 0:{
            entity_set_model(entity,"models/fyzsph.mdl")
        }
        case 1:{
            entity_set_model(entity,"models/fyzbox.mdl")
        }
        case 2:{
            entity_set_model(entity,"models/fyzcyl.mdl")
        }
        case 3:{
            entity_set_model(entity,"models/fyzcap.mdl")
        }
        case 4:{
            entity_set_model(entity,"models/fyzcon.mdl")
        }
    }
    new Float:origin[3]
    entity_get_vector(id,EV_VEC_origin,origin)
    origin[2]+=128
    entity_set_origin(entity,origin)
    entity_set_float(entity,EV_FL_nextthink,86400.0)
    entity_set_int(entity,EV_INT_movetype,8)
    bmod_object_add(entity,i%5,1.0,24.0,24.0,24.0)
    i++
}

public plugin_precache(){
    precache_model("models/fyzsph.mdl")
    precache_model("models/fyzbox.mdl")
    precache_model("models/fyzcyl.mdl")
    precache_model("models/fyzcap.mdl")
    precache_model("models/fyzcon.mdl")
}


xakintosh 02-12-2012 14:31

Re: Module: BMOD - Extended Physics Module
 
Wicked Work.
You are insane dude good job.

Kiske 02-13-2012 02:05

Re: Module: BMOD - Extended Physics Module
 
Quote:

Originally Posted by Backup (Post 1648908)
Code:

#include <amxmodx>
#include <engine>
#include <bmod>

public plugin_init() {
    register_plugin("bmod_test","0","asdf")
    register_concmd("bmod_test","_bmod_test")
}

new i=0

public _bmod_test(id){
    new entity = create_entity("func_wall")
    switch(i%5){
        case 0:{
            entity_set_model(entity,"models/fyzsph.mdl")
        }
        case 1:{
            entity_set_model(entity,"models/fyzbox.mdl")
        }
        case 2:{
            entity_set_model(entity,"models/fyzcyl.mdl")
        }
        case 3:{
            entity_set_model(entity,"models/fyzcap.mdl")
        }
        case 4:{
            entity_set_model(entity,"models/fyzcon.mdl")
        }
    }
    new Float:origin[3]
    entity_get_vector(id,EV_VEC_origin,origin)
    origin[2]+=128
    entity_set_origin(entity,origin)
    entity_set_float(entity,EV_FL_nextthink,86400.0)
    entity_set_int(entity,EV_INT_movetype,8)
    bmod_object_add(entity,i%5,1.0,24.0,24.0,24.0)
    i++
}

public plugin_precache(){
    precache_model("models/fyzsph.mdl")
    precache_model("models/fyzbox.mdl")
    precache_model("models/fyzcyl.mdl")
    precache_model("models/fyzcap.mdl")
    precache_model("models/fyzcon.mdl")
}


Very very thanks!

iBuX 02-13-2012 16:45

Re: Module: BMOD - Extended Physics Module
 
Very nice!

Good job.

Backup 02-13-2012 17:15

Re: Module: BMOD - Extended Physics Module
 
I'm very glad you like it, but i would also appreciate some feedback like: Is it working? Are there any functions you miss (like applying forces, setting gravity, callbacks)? Or should i work on entity handling (proper collision with walls, doors, breakables)? Or should i try to implement player collision?

Emp` 02-13-2012 19:33

Re: Module: BMOD - Extended Physics Module
 
Quote:

Originally Posted by Backup (Post 1649972)
Or should i try to implement player collision?

I think that would be one of the best goals you could accomplish with this, along with the entity handling.

One thing that I saw immediately that I would prefer you do is convert the following into an enumeration.
Code:

0 - sphere (x is radius)
1 - box (x, y and z are half of box dimensions)
2 - cylinder (same as box, x is radius; cylinder is situated along Z axis)
3 - capsule (x is radius, y is distance between half spheres; capsule is situated along Z axis)
4 - cone (x is radius, y is height; cone is situated along Z axis)

Using an enumeration would be easier to distinguish what is being created, instead of trying to remember the numeric values.

Also, I have not had any time to actually test anything with this, but could you answer these questions (they all have to do with how much entity data is used between "worlds"):
  1. Are entities' and objects' velocities tied both ways? Meaning if I set an entity's velocity, will it correctly alter the object's velocity?
  2. Does an entity's movetype also affect its movement? I.e. would an entity with MOVETYPE_FLY float in the air?
  3. Does the entity's gravity affect anything?

A feature that I think would be interesting, would be able to do something like Weapon Physics for the entities.

Backup 02-14-2012 10:09

Re: Module: BMOD - Extended Physics Module
 
Quote:

Originally Posted by Emp` (Post 1650061)
One thing that I saw immediately that I would prefer you do is convert the following into an enumeration.
Code:

...
Using an enumeration would be easier to distinguish what is being created, instead of trying to remember the numeric values.

Whatever, that was the most easy thing to do.
Quote:

Originally Posted by Emp` (Post 1650061)
Are entities' and objects' velocities tied both ways? Meaning if I set an entity's velocity, will it correctly alter the object's velocity?

Nope, bmod ingores and overwrites all your changes of velocity. I would have to store last frame velocity and that is wasting of memory, because i am able (*will be able in next version) to set velocity and forces directly using internal bullet functions.
Quote:

Originally Posted by Emp` (Post 1650061)
Does an entity's movetype also affect its movement? I.e. would an entity with MOVETYPE_FLY float in the air?

Nope, why would you hook an entity you want to be floating to an physics engine anyway?
Quote:

Originally Posted by Emp` (Post 1650061)
Does the entity's gravity affect anything?

Nope. I'm going to use origin, angles, velocity, avelocity and gravity to create bullet objects. (In current version only origin of entity is used)
Quote:

Originally Posted by Emp` (Post 1650061)
A feature that I think would be interesting, would be able to do something like Weapon Physics for the entities.

I don't get it, could you be more specific? What feature would be interesting?

joropito 02-14-2012 10:32

Re: Module: BMOD - Extended Physics Module
 
Player push will be great when collision occurs. It should be done taking into consideration the objects and players weight.

Exolent[jNr] 02-14-2012 10:49

Re: Module: BMOD - Extended Physics Module
 
Quote:

Originally Posted by Backup (Post 1650335)
Nope, why would you hook an entity you want to be floating to an physics engine anyway?

So, you're saying that if an entity doesn't have gravity, it shouldn't need better physics?
What about something like ricochet where discs fly around and push players? I think that would be a good purpose for such feature.

Quote:

Originally Posted by Backup (Post 1650335)
I don't get it, could you be more specific? What feature would be interesting?

Grenade explosions and bullets pushing entities, since it seems you have the bounce feature already made.

TheSpectator 02-15-2012 02:14

Re: Module: BMOD - Extended Physics Module
 
Just awesome!

mabaclu 02-15-2012 17:48

Re: Module: BMOD - Extended Physics Module
 
Quote:

Originally Posted by joropito (Post 1650342)
Player push will be great when collision occurs. It should be done taking into consideration the objects and players weight.

There could be a function called set_object_weight that would change the weight of an object. Then Bmod would calculate the acceleration using the formula: Force = mass x acceleration

ot_207 02-16-2012 05:08

Re: Module: BMOD - Extended Physics Module
 
The only thing that I would suggest with this module is to make it an interface to all the possible functions of the Bullet physics.

Also it would be a good idea to add get natives.
For example: bmod_get_friction and is_bmod_registered.

And forwards if the bmod library can offer.

Also request for the mods of the forums.
Sticky PLEASEEE!!!

Backup 02-17-2012 11:39

Re: Module: BMOD - Extended Physics Module
 
Ok, added more natives, look at the include file for complete list.
In this video i'm using last bullet hit for traceline end point because i'm too lazy to get it from player angles. I set gravity (or apply force at hit point) of traced object by console bind.
http://www.youtube.com/watch?v=fAJlHJehlI8

So if you want objects reacting to bullets or explosions, use bmod_traceline and bmod_object_apply_force_at (this takes relative position, so substract it from entity origin).

mabaclu 02-17-2012 17:22

Re: Module: BMOD - Extended Physics Module
 
What about joining objects? It would allow coders to make more complex objects by joining cylinders, cones, boxes, etc.

ot_207 02-18-2012 02:27

Re: Module: BMOD - Extended Physics Module
 
Quote:

Originally Posted by Backup (Post 1652261)
Ok, added more natives, look at the include file for complete list.
In this video i'm using last bullet hit for traceline end point because i'm too lazy to get it from player angles. I set gravity (or apply force at hit point) of traced object by console bind.
http://www.youtube.com/watch?v=fAJlHJehlI8

So if you want objects reacting to bullets or explosions, use bmod_traceline and bmod_object_apply_force_at (this takes relative position, so substract it from entity origin).

Beautiful. I will make a physics plugin soon :mrgreen:.

Things that I like to request:
1. Module autoloading
2. Some forwards, don't know if the bmod library has something like that.
3. Also I think that it would be a good idea to make the object properties set function just like engine this is good when this module will provide more and more functions that we can play with. bmod_set_float(ent, BM_gravity/BM_restitution, gravity).

Quote:

Originally Posted by mabaclu (Post 1652447)
What about joining objects? It would allow coders to make more complex objects by joining cylinders, cones, boxes, etc.

Another alternative to your suggestion would be to make the bullet engine support custom models. Like the player models for instance, though I don't know if this bullet physics will be able to support this.

Backup 02-18-2012 14:56

Re: Module: BMOD - Extended Physics Module
 
Quote:

Originally Posted by ot_207 (Post 1652599)
1. Module autoloading

Sorry, i don't get it, what is it?
Anyway i've done everything else: engine-like variables handling and one simple callback called when body contact is made. You can use it for sound effects, as i tried to in this video:
http://www.youtube.com/watch?v=0tpyPSHG96s
Quote:

Originally Posted by ot_207 (Post 1652599)
Another alternative to your suggestion would be to make the bullet engine support custom models. Like the player models for instance, though I don't know if this bullet physics will be able to support this.

Player models are too complex for physics simulation. I'm going to add support for model trimesh (including both map brush model (beginning with *) and studio model (.mdl files)).

zeus 02-18-2012 15:03

Re: Module: BMOD - Extended Physics Module
 
Module autoloading means when a plugin is using the module it will autoload even if it is not enabled from modules.ini ( i guess ) :D

mabaclu 02-18-2012 18:10

Re: Module: BMOD - Extended Physics Module
 
The "callback when body contact is made" is not working, can you give me an example script please?

Backup 02-18-2012 18:28

Re: Module: BMOD - Extended Physics Module
 
You have to call bmod_object_set_callback(entity,1) on objects you want to get callback from.
Code:

public whatever(){
    ...
    new Float:size[3] = {24.0,24.0,24.0}
    bmod_object_add(entity,BMOD_sphere,1.0,size)
    bmod_object_set_callback(entity,1)
}
public bmod_forward_contact(ent1,ent2,Float:distance){
    ...
}

If you don't want to get callback anymore, call bmod_object_set_callback(entity,0).

Is this bad 'feature'? Should every object call this callback automaticly?

mabaclu 02-18-2012 18:34

Re: Module: BMOD - Extended Physics Module
 
Look at my code, it's not working. Nothing happens when 2 balls collide:
Code:

#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <bmod>

public plugin_init() {
        register_plugin("bmod_test","0","asdf")
        register_concmd("bmod_test","_bmod_test")
}

public _bmod_test(id){
        new entity = create_entity("func_wall")
        entity_set_model(entity,"models/fyzsph.mdl")
        new Float:origin[3]
        entity_get_vector(id,EV_VEC_origin,origin)
        origin[2]+=128
        entity_set_origin(entity,origin)
        entity_set_float(entity,EV_FL_nextthink,86400.0)
        entity_set_int(entity,EV_INT_movetype,8)
        new Float:size[3] = {24.0,24.0,24.0}
        bmod_object_add(entity,BMOD_sphere,1.0,size)
        new Float:gravity[3] = {0.0,0.0,-2.0}
        bmod_object_set_vector(entity, BMOD_VEC_gravity, gravity)
        bmod_object_set_callback(entity,1)
}
public plugin_precache(){
        precache_model("models/fyzsph.mdl")
}

public bmod_forward_contact(ent1,ent2,Float:distance){
        client_print(0, print_chat, "ent1: %i; ent2: %i; distance: %f", ent1, ent2, distance)
}

Quote:

Originally Posted by Backup (Post 1653004)
Is this bad 'feature'? Should every object call this callback automaticly?

Detecting collisions is a great feature but _set_callback may be an useless native.

I've looked at the source code and i don't see bmod_forward_contact. Did you forget it?

GordonFreeman (RU) 02-18-2012 23:30

Re: Module: BMOD - Extended Physics Module
 
Can i add bmod physics for other in game ents? Not creating new ent.
(example. granades with bmod physics)

Backup 02-19-2012 05:04

Re: Module: BMOD - Extended Physics Module
 
@mabaclu: Works for me.
[IMG]http://img403.**************/img403/7026/bmodmabaclu.png[/IMG]
Have you re-downloaded binaries and include file? I always re-upload them when i release a new version.

Quote:

Originally Posted by GordonFreeman (RU) (Post 1653112)
Can i add bmod physics for other in game ents? Not creating new ent.
(example. granades with bmod physics)

Sure, you just have to hook the right events to get entity id of that granade, and you're good to go.

bogdyuttzu 02-19-2012 09:08

Re: Module: BMOD - Extended Physics Module
 
Can you show an example with bmod_traceline

Backup 02-19-2012 09:42

Re: Module: BMOD - Extended Physics Module
 
Quote:

Originally Posted by bogdyuttzu (Post 1653263)
Can you show an example with bmod_traceline

This is that piece of code which was used as the second example in my video.
Code:

public _bmod_test2(id){
    new Float:start[3]
    entity_get_vector(id,EV_VEC_origin,start)
    new lhit[3]
    get_user_origin(id,lhit,4)
    new Float:end[3]
    end[0]=float(lhit[0])
    end[1]=float(lhit[1])
    end[2]=float(lhit[2])
    new Float:point[3]
    new Float:normal[3]
    new entity = bmod_traceline(start,end,point,normal)
    if(entity){
        new Float:origin[3]
        entity_get_vector(entity,EV_VEC_origin,origin)
        point[0]-=origin[0]
        point[1]-=origin[1]
        point[2]-=origin[2]
        new Float:v_angle[3]
        entity_get_vector(id,EV_VEC_v_angle,v_angle)
        new Float:v_angle2[3]
        angle_vector(v_angle,1,v_angle2)
        new force=5000
        v_angle2[0]*=force
        v_angle2[1]*=force
        v_angle2[2]*=force
        bmod_object_apply_force_at(entity,v_angle2,point)
    }
}


bogdyuttzu 02-19-2012 09:47

Re: Module: BMOD - Extended Physics Module
 
Thanks :D

mabaclu 02-19-2012 12:25

Re: Module: BMOD - Extended Physics Module
 
My binaries and include file are updated but nothing appears in the chat when two balls collide. Here's my test server: 188.93.232.121:37841

Backup 02-19-2012 14:45

Re: Module: BMOD - Extended Physics Module
 
@mabaclu: Please re-download the linux binary once again (from git or from first post). I've made a stupid mistake, i've compiled it with old moduleconfig.h instead of the freshly updated one. I work mainly on windows, so i don't check if there are any bugs in linux release, i just check if it compiles fine and if it loads fine.

Destro- 02-19-2012 15:48

Re: Module: BMOD - Extended Physics Module
 
very good :D

mabaclu 02-20-2012 09:07

Re: Module: BMOD - Extended Physics Module
 
It's working now.
Is it possible to make players act like boxes?

GHW_Chronic 02-22-2012 18:30

Re: Module: BMOD - Extended Physics Module
 
Nice

bibu 02-23-2012 00:58

Re: Module: BMOD - Extended Physics Module
 
GHW is back!


All times are GMT -4. The time now is 03:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.