File size: 1,460 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#ifdef GAME_TEMPLATE
[EditorAttribute("box", "GameLib/Scripted", "Script model", "-0.25 -0.25 -0.25", "0.25 0.25 0.25", "255 0 0 255", "0 0 0 0", true, true, true)]
class ScriptModelClass
{
}
ScriptModelClass ScriptModelSource;
class ScriptModel: GenericEntity
{
[Attribute("", "resourceNamePicker", "Model", "xob")]
string Model;
[Attribute("1", "combobox", "Physics", "", { ParamEnum("None", "2"), ParamEnum("Static", "1"), ParamEnum("Dynamic", "0") } )]
int Type;
void ScriptModel(IEntitySource src, IEntity parent)
{
if (Model== "")
return;
SetFlags(EntityFlags.ACTIVE | EntityFlags.SOLID | EntityFlags.VISIBLE, false);
vobject vobj = GetObject(Model);
SetObject(vobj, "");
ReleaseObject(vobj, false);
if (Type == 1)
{
dBodyCreateStatic(this, 0xffffffff); // todo - defines for layer mask
}
else if (Type == 0)
{
if(!dBodyCreateDynamic(this, 1.0, 0xffffffff))
{
//create implicit box
vector mins, maxs;
GetBounds(mins, maxs);
vector center = (mins + maxs) * 0.5;
vector size = maxs - mins;
PhysicsGeomDef geoms[] = {PhysicsGeomDef("", dGeomCreateBox(size), "material/default", 0xffffffff)};
dBodyCreateDynamicEx(this, center, 1, geoms);
}
if(dBodyIsSet(this))
{
dBodySetMass(this, 1.0);
dBodyActive(this, ActiveState.ACTIVE);
dBodyDynamic(this, true);
}
}
}
void ~ScriptModel()
{
if(dBodyIsSet(this))
dBodyDestroy(this);
}
}
#endif |