SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 25/11/2015, 03:25 PM   #1
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 248
Reputation: 116
Default cimulator - collision detection and physics simulation

cimulator
collision detection and physics simulation


cimulator is mainly focuses on server side third-party physics simulation. This plugin is purely dependent upon bullet physics library. They key features of this plugin is pretty simple, Simulation can be done with any object of Grand Theft Auto SanAndreas with a proper collision shape. SanAndreas has a world of 44759 map objects and this why the simulation uses more CPU power. Keep a track on latest commits at the github repository of cimulator. The latest version of this plugin supports server-synced simulation to avoid usage of timers, hence reduces the stress on CPU.


Showcasing Simulation

[ame="http://www.youtube.com/watch?v=BYVxElZ-FpA"]cimulator[/ame]

[ame="http://www.youtube.com/watch?v=T0ZoGjewz1w"]Stack Simulation[/ame]


Natives

Code:
native CR_EnableSimulation();
native CR_DisableSimulation();
native CR_Load(Float:worldrest = 0.0);
native CR_RemoveColMap();
native CR_RemoveBuilding(modelid, Float:x, Float:y, Float:z, Float:range);
native CR_SetWorldGravity(Float:x, Float:y, Float:z); 
native CR_GetWorldGravity(&Float:x, &Float:y, &Float:z); 
native CR_RayCastNormal(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, &Float:x3, &Float:y3, &Float:z3);
native CR_RayCast(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, &Float:x3, &Float:y3, &Float:z3);
native CR_RayCastEx(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, &Float:x3, &Float:y3, &Float:z3, &modelid);
native CR_RayCastReflection(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, &Float:rx, &Float:ry, &Float:rz, &Float:angle);
native CR_RayCastObjectInfo(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, &modelid, &Float:boundingRadius, &isStatic);
native CR_RayCastIntData(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, &Float:x3, &Float:y3, &Float:z3, &data);
native CR_RayCastFloatData(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, &Float:x3, &Float:y3, &Float:z3, &Float:data);
native CR_FreeMemory();
native CR_RemoveDynamicCol(index);
native CR_RemoveStaticCol(index);
native CR_CreateDynamicCol(objectid, modelid, Float:mass, Float:x, Float:y, Float:z, Float:yaw, Float:pitch, Float:roll, inertia = 0, tag = ACTIVE_TAG);
native CR_CreateStaticCol(objectid, modelid, Float:x, Float:y, Float:z, Float:yaw, Float:pitch, Float:roll);
native CR_GetDynamicColModel(index);
native CR_GetStaticColModel(index);
native CR_SetMass(index, Float:mass);
native Float:CR_GetMass(index);
native CR_SetDynamicColShape(index, modelid);
native CR_SetStaticColShape(index, modelid);
native CR_GetBoundingSphere(modelid, &Float:x, &Float:y, &Float:z, &Float:radius);
native CR_GetAABB(modelid, Float:x, Float:y, Float:z, Float:yaw, Float:pitch, Float:roll, &Float:minx, &Float:miny, &Float:minz, &Float:maxx, &Float:maxy, &Float:maxz);
native CR_GetTransform(index, &Float:x, &Float:y, &Float:z, &Float:rx, &Float:ry, &Float:rz);
native CR_SetDynamicOrigin(index, Float:x, Float:y, Float:z);
native CR_SetStaticOrigin(index, Float:x, Float:y, Float:z);
native CR_GetDynamicOrigin(index, &Float:x, &Float:y, &Float:z);
native CR_GetStaticOrigin(index, &Float:x, &Float:y, &Float:z);
native CR_SetDynamicRotation(index, Float:yaw, Float:pitch, Float:roll);
native CR_SetStaticRotation(index, Float:yaw, Float:pitch, Float:roll);
native CR_GetDynamicRotation(index, &Float:yaw, &Float:pitch, &Float:roll);
native CR_GetStaticRotation(index, &Float:yaw, &Float:pitch, &Float:roll);
native CR_SetLinearVelocity(index, Float:vx, Float:vy, Float:vz);
native CR_GetLinearVelocity(index, &Float:vx, &Float:vy, &Float:vz);
native CR_SetAngularVelocity(index, Float:vx, Float:vy, Float:vz);
native CR_GetAngularVelocity(index, &Float:vx, &Float:vy, &Float:vz);
native CR_SetTorque(index, Float:tx, Float:ty, Float:tz);
native CR_SetFriction(index, Float:friction);
native Float:CR_GetFriction(index);
native CR_SetRestitution(index, Float:rest);
native Float:CR_GetRestitution(index);
native CR_IsDynamicSlotUsed(index);
native CR_IsStaticSlotUsed(index);
native CR_IsActive(index);
native CR_IsMoving(index);
native CR_Activate(index);
native CR_Simulator(newtime, oldtime);
native CR_GetNumCollisionObject();
native CR_GetNumChildShapes(modelid);
native CR_IsCompound(modelid);
native CR_Wait(ms);
native CR_DynamicContactTest(index);
native CR_ContactTestEx(modelid, Float:x, Float:y, Float:z, Float:yaw, Float:pitch, Float:roll);
native CR_CharacterContactTest(Float:x, Float:y, Float:z, Float:radius, Float:height);
native Float:CR_GetContactPoints(index, &Float:x1, &Float:y1, &Float:z1, &Float:x2, &Float:y2, &Float:z2);
native CR_GetTimeMilliseconds();
native CR_GetDynamicColObject(index);
native CR_GetStaticColObject(index);
native CR_SetDynamicUserData(index, type, {Float,_}:...);
native CR_SetStaticUserData(index, type, {Float,_}:...);
native CR_GetDynamicInt(index, &data);
native CR_GetDynamicFloat(index, &Float:data);
native CR_GetStaticInt(index, &data);
native CR_GetStaticFloat(index, &Float:data);
native CR_GetStaticPool();
native CR_GetDynamicPool();
native Float:CR_PlacementCorrection(modelid, Float:x, Float:y, Float:z, Float:yaw, Float:pitch, Float:roll);
native CR_CreateVehicleCol(vehicleid, modelid, Float:x, Float:y, Float:z, Float:qx, Float:qy, Float:qz, Float:qw);
native CR_RemoveVehicleCol(index);
native CR_SetVehicleOrigin(index, Float:x, Float:y, Float:z);
native CR_GetVehicleOrigin(index, &Float:x, &Float:y, &Float:z);
native CR_SetVehicleRotation(index, Float:qx, Float:qy, Float:qz, Float:qw);
native CR_GetVehicleRotation(index, &Float:qx, &Float:qy, &Float:qz, &Float:qw);
native CR_GetVehicleID(index);
native CR_GetVehicleModel(index);
native CR_IsVehicleSlotUsed(index);
native CR_VehicleContactTest(modelid, Float:x, Float:y, Float:z, Float:yaw, Float:pitch, Float:roll);
native CR_GetVehiclePool();
stock CR_SetTransform(index, Float:x, Float:y, Float:z, Float:rotx, Float:roty, Float:rotz)
stock CR_UpdateTransform(index)
stock CR_DestroyAllColVolumes(vehicle = 0)
stock CR_DestroyDynamicCol(index)
stock CR_DestroyStaticCol(index)
stock CR_FlushMemory()
stock CR_ThrowObject(playerid, index, Float:speed)
stock CR_GetForwardObjectInfo(playerid, Float:distance, &modelid, &Float:boundingRadius, &isStatic)
stock CR_PlaceObjectOnGround(objectid, modelid)
stock CR_FindZ_For2D(Float:x, Float:y, &Float:z)
Documentation on all functions are provided at cimulator.inc. I would suggest you to go through cimulator.pdf in the download file for more detailed information including some FAQs.

Download

cimulator-1.09

Last edited by codectile; 17/04/2016 at 02:18 PM.
codectile is offline   Reply With Quote
Old 25/11/2015, 03:29 PM   #2
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,892
Reputation: 1321
Default Re: cimulator - collision detection and physics simulation

What happened to the original thread?
Pottus is offline   Reply With Quote
Old 25/11/2015, 03:44 PM   #3
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 248
Reputation: 116
Default Re: cimulator - collision detection and physics simulation

The previous thread was messed up plus the previous version had some issues and I wanted to start fresh. The latest version supports new things, one of the main feature is server-synced simulation. This major update needed a fresh start because I kinda re-developed the core of the project.

EDIT: I'd even hooked objects to collision volumes for ease of use.
codectile is offline   Reply With Quote
Old 03/12/2015, 03:34 PM   #4
Stanford
Gangsta
 
Stanford's Avatar
 
Join Date: Feb 2012
Posts: 984
Reputation: 84
Default Re: cimulator - collision detection and physics simulation

How much memory does this plugin uses? let's say we have about 100k of dynamic objects.
__________________
******: "That code compiles perfectly, but I can tell you now it won't make me a cup of tea."

******: "I've said this before. People think that MySQL is some simple plug-and-play magic bullet that you can use to just make your mode instantly better. They don't realise that the "L" in "SQL" means "language". So instead of programming PAWN, and using a bit of this mystery thing, you are now programming in two languages at once. If you spend months learning PAWN, you should spend the same time learning SQL, if not more - it is probably the more complex of the two languages, and not something that just gets bolted on to the side."
Stanford is offline   Reply With Quote
Old 03/12/2015, 03:37 PM   #5
SkittlesAreFalling
Big Clucker
 
Join Date: Oct 2013
Posts: 155
Reputation: 14
Default Re: cimulator - collision detection and physics simulation

I thought I was tripping balls right now. haha
SkittlesAreFalling is offline   Reply With Quote
Old 03/12/2015, 06:08 PM   #6
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 248
Reputation: 116
Default Re: cimulator - collision detection and physics simulation

Firstly, no one will ever create that amount of objects. Secondly, cimulator has a limit on objects, look at cimulator.inc. Thirdly, that amount of objects will consume less than 130mb in theory.
codectile is offline   Reply With Quote
Old 03/12/2015, 07:01 PM   #7
TwinkiDaBoss
Gangsta
 
Join Date: Jul 2014
Posts: 799
Reputation: 51
Default Re: cimulator - collision detection and physics simulation

Hmmm really nice. Does it detect player-object interaction?
Ie: from the 2nd video you made, if I was to walk thru those crates, would physics apply to them
TwinkiDaBoss is offline   Reply With Quote
Old 04/12/2015, 01:54 AM   #8
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 248
Reputation: 116
Default Re: cimulator - collision detection and physics simulation

Certainly, objects will not repel from the players now because I removed that function as it was quite CPU intensive. The good thing is that you can still detect player-object collisions using CR_CharacterContactTest, where xyz is the player's position and radius and height are data to generate a capsule bounding them. Even GTA SA uses capsule shapes for players as ragdolls were not present back then. The function mentioned above detects player-world collisions as well.
codectile is offline   Reply With Quote
Old 04/12/2015, 03:03 AM   #9
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,329
Reputation: 652
Default Re: cimulator - collision detection and physics simulation

Quote:
Firstly, no one will ever create that amount of objects
I use 12 times that and more... Yes, that's 1.2 million. Yes that's a lot of objects and of course they are not simulated.
Crayder is offline   Reply With Quote
Old 04/12/2015, 03:45 AM   #10
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 248
Reputation: 116
Default Re: cimulator - collision detection and physics simulation

TwinkiDaBoss said "dynamic objects" so my answer was according to that. Here in this topic dynamic means physics enabled. By the way, how much memory did it take? I assume that you are using ColAndreas.
codectile is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collision Detection (Plugin) Deduction Scripting Help 0 27/12/2013 04:24 AM
Collision Detection? NumbSkull Scripting Help 4 13/11/2012 03:27 AM


All times are GMT. The time now is 09:03 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.