[Plugin] cimulator - collision detection and physics simulation
#1

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

Код:
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
Reply
#2

What happened to the original thread?
Reply
#3

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.
Reply
#4

How much memory does this plugin uses? let's say we have about 100k of dynamic objects.
Reply
#5

I thought I was tripping balls right now. haha
Reply
#6

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.
Reply
#7

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
Reply
#8

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.
Reply
#9

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.
Reply
#10

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.
Reply
#11

Not all of them are added to the ColAndreas world, but a lot of them are.

Just a random model test (ALL added to the ColAndreas world) -
Initial memory: 186mb
1.2 million objects and initial memory: 943mb.

I'll post my map's usage when I get the chance.
Reply
#12

943mb is a lot. By the way, I am trying to implement a feature which will reduce memory usage of object. Basically, I am dividing cimulator in two sections; static and dynamic. Static objects will use less memory compared to dynamic objects.
Reply
#13

Quote:
Originally Posted by codectile
View Post
943mb is a lot. By the way, I am trying to implement a feature which will reduce memory usage of object. Basically, I am dividing cimulator in two sections; static and dynamic. Static objects will use less memory compared to dynamic objects.
Yes do that, it would be great to detect Z for mapped objects (static) without using much memory.
Reply
#14

Is it possible to register a specific movement? Like throwing a knife and it could get stickied to the wall. Or at least hit the wall and fall down.
Reply
#15

Quote:
Originally Posted by Cypress
View Post
Is it possible to register a specific movement? Like throwing a knife and it could get stickied to the wall. Or at least hit the wall and fall down.
Yes you can detect if it hits any object on the map, but keep in mind that Vehicles and Peds/Players are not supported, you will need some workaround for these...
Reply
#16

Quote:
Originally Posted by Cypress
View Post
Is it possible to register a specific movement? Like throwing a knife and it could get stickied to the wall. Or at least hit the wall and fall down.
Here the problem is, weapons don't have a collision shape except for projectiles.

Quote:
Originally Posted by DRIFT_HUNTER
View Post
Yes you can detect if it hits any object on the map, but keep in mind that Vehicles and Peds/Players are not supported, you will need some workaround for these...
Players are supported but for specific purposes, one of them is detecting player-world and player-object collision. CR_CharacterContactTest.
Reply
#17

Quote:

Here the problem is, weapons don't have a collision shape except for projectiles.

Which is why you would use the weapon model for the streamed object and a collision model (like object 3065, a small sphere) for the cimulated one. You wouldn't be able to see the collision model, so it would look normal.
Reply
#18

A sphere without inertia would be just fine. Okay so, I have implemented a base technique to create static objects which is expected to use less memory than dynamic objects. Crayder, can you do a test with ColAndreas by creating 10000 static objects(modelid: 1221, if possible) and tell me the memory consumption?
Reply
#19

Quote:
Originally Posted by codectile
View Post
A sphere without inertia would be just fine. Okay so, I have implemented a base technique to create static objects which is expected to use less memory than dynamic objects. Crayder, can you do a test with ColAndreas by creating 10000 static objects(modelid: 1221, if possible) and tell me the memory consumption?
Total - 445mb
Without those 10000 objects (model 1221) - 432mb

So approx 13 mb.
Reply
#20

I think the new object creation(static) works quite well. I did the the test with cimulator using the same modelid for 10000 objects and the memory consumption was only 7mb.
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)