All right. Glad to see you are still here
I'm having a hard time validating if the shapes and the meshes are the same in my game, so I made this shape/mesh viewer.
Thanks to that, I discovered that a Cone Shape with a height of 1 is in fact a Cone Mesh with a height of 0.5 !? Maybe that's supposed to be like that, I don't know.
What I would like to know is if collision shapes can be scaled using zbtSetShapeLocalScaling?
Press left/right to change shape/model and move the mouse around to see if everything's ok. You'll see my problem with the ArrowShape example (it's a squished cone).
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" MouseVisible="255" FileVersion="2">
<OnLoaded>
<ZExternalLibrary Comment="Bullet 3D physics" ModuleName="ZgeBullet" CallingConvention="1" BeforeInitExp="if(ANDROID) this.ModuleName = "./libZgeBullet.so";">
<Source>
<![CDATA[/*
ZgeBullet Library, a wrapper for the Bullet Physics Library.
http://bulletphysics.org
Project home
https://github.com/Rado-1/ZgeBullet
Download Windows DLL and Android shared library from
https://github.com/Rado-1/ZgeBullet/releases
Copyright (c) 2012-2015 Radovan Cervenka
Version: 2.1 (2015-06-27)
*/
// Constants
// Triangle mesh types
const int ZBT_TRIANGLE_CONVEX_HULL_MESH = 1;
const int ZBT_TRIANGLE_CONCAVE_STATIC_MESH = 2;
const int ZBT_TRIANGLE_CONCAVE_DEFORMABLE_MESH = 3;
// Activation states
const int ZBT_ACTIVE_TAG = 1;
const int ZBT_ISLAND_SLEEPING = 2;
const int ZBT_WANTS_DEACTIVATION = 3;
const int ZBT_DISABLE_DEACTIVATION = 4;
const int ZBT_DISABLE_SIMULATION = 5;
// Default values of constraint limits
const float ZBT_DEFAULT_HINGE_SOFTNESS = 0.9;
const float ZBT_DEFAULT_HINGE_BIAS_FACTOR = 0.3;
const float ZBT_DEFAULT_HINGE_RELAXATION_FACTOR = 1.0;
const float ZBT_DEFAULT_CONE_TWIST_SOFTNESS = 1.0;
const float ZBT_DEFAULT_CONE_TWIST_BIAS_FACTOR = 0.3;
const float ZBT_DEFAULT_CONE_TWIST_RELAXATION_FACTOR = 1.0;
// Vehicle tunning defaults
const float ZBT_DEFAULT_VEHICLE_SUSP_STIFFNESS = 5.88;
const float ZBT_DEFAULT_VEHICLE_SUSP_COMPRESSION = 0.83;
const float ZBT_DEFAULT_VEHICLE_SUSP_DAMPING = 0.88;
const float ZBT_DEFAULT_VEHICLE_SUSP_MAX_SUSP_TRAVEL_CM = 500.0;
const float ZBT_DEFAULT_VEHICLE_SUSP_FORCE = 6000.0;
const float ZBT_DEFAULT_VEHICLE_FRICTION_SLIP = 10.5;
// Axes
const int ZBT_AXIS_X_LINEAR = 0;
const int ZBT_AXIS_Y_LINEAR = 1;
const int ZBT_AXIS_Z_LINEAR = 2;
const int ZBT_AXIS_X_ANGULAR = 3;
const int ZBT_AXIS_Y_ANGULAR = 4;
const int ZBT_AXIS_Z_ANGULAR = 5;
// Collision flags
const int ZBT_CF_STATIC_OBJECT= 1;
const int ZBT_CF_KINEMATIC_OBJECT= 2;
const int ZBT_CF_NO_CONTACT_RESPONSE = 4;
const int ZBT_CF_CUSTOM_MATERIAL_CALLBACK = 8;
const int ZBT_CF_CHARACTER_OBJECT = 16;
const int ZBT_CF_DISABLE_SPU_COLLISION_PROCESSING = 64;
// Functions
// World
xptr zbtCreateWorld() {}
void zbtDestroyWorld(xptr world) {}
void zbtSetCurrentWorld(xptr world) {}
void zbtSetWorldGravity(float x, float y, float z) {}
void zbtStepSimulation(float timeStep, int maxSubSteps, float fixedTimeStep) {}
// Collision shapes
xptr zbtCreateStaticPlaneShape(
float normalX, float normalY, float normalZ, float planeConstant) {}
xptr zbtCreateBoxShape(float x, float y, float z) {}
xptr zbtCreateSphereShape(float radius) {}
xptr zbtCreateScalableSphereShape(float radius) {}
xptr zbtCreateConeShape(float radius, float height) {}
xptr zbtCreateCylinderShape(float radius, float height) {}
xptr zbtCreateCapsuleShape(float radius, float height) {}
xptr zbtCreateCompoundShape() {}
xptr zbtAddChildShape(xptr compoundShape, xptr childShape,
float x, float y, float z, float rx, float ry, float rz) {}
xptr zbtRemoveChildShape(xptr compoundShape, xptr childShape) {}
xptr zbtCreateHeightfieldTerrainShape(xptr heightfieldData,
int width, int length, float minHeight, float maxHeight, int upAxis,
int bFlipQuadEdges, int bDiamondSubdivision) {}
xptr zbtCreateConvexHullShape(xptr points, int numPoints) {}
xptr zbtCreateMultiSphereShape(xptr positions, xptr radii, int numSpheres) {}
xptr zbtCreateTriangleMeshShape(xptr triangles, int numTriangles, int meshType) {}
void zbtUpdateDeformableTriangleMesh(xptr triangleMeshShape) {}
void zbtSetShapeLocalScaling(xptr shape, float x, float y, float z) {}
void zbtSetShapeMargin(xptr shape, float margin) {}
void zbtDeleteShape(xptr shape) {}
void zbtDeleteAllShapes() {}
// Rigid bodies
xptr zbtCreateRigidBodyXYZ(float mass, xptr shape,
float x, float y, float z, float rx, float ry, float rz) {}
xptr zbtCreateRigidBody(float mass, xptr shape, xptr position, xptr rotation) {}
void zbtDeleteRigidBody(xptr rigidBody) {}
void zbtSetMass(xptr rigidBody, float mass) {}
void zbtSetDamping(xptr rigidBody, float linearDamping, float angularDamping) {}
void zbtSetLinearFactor(xptr rigidBody, float x, float y, float z) {}
void zbtSetAngularFactor(xptr rigidBody, float x, float y, float z) {}
void zbtSetGravity(xptr rigidBody, float x, float y, float z) {}
void zbtSetLinearVelocity(xptr rigidBody, float x, float y, float z) {}
void zbtGetLinearVelocity(xptr rigidBody,
ref float outX, ref float outY, ref float outZ) {}
void zbtSetAngularVelocity(xptr rigidBody, float x, float y, float z) {}
void zbtGetAngularVelocity(xptr rigidBody,
ref float outX, ref float outY, ref float outZ) {}
void zbtApplyCentralImpulse(xptr rigidBody, float x, float y, float z) {}
void zbtApplyTorqueImpulse(xptr rigidBody, float x, float y, float z) {}
void zbtApplyImpulse(xptr rigidBody, float x, float y, float z,
float relX, float relY, float relZ) {}
void zbtSetSleepingThresholds(xptr rigidBody, float linear, float angular) {}
// Constraints and limits
int zbtAreConnected(xptr rigidBodyA, xptr rigidBodyB) {}
xptr zbtAddFixedConstraint(xptr rigidBodyA, xptr rigidBodyB,
float pivotAx, float pivotAy, float pivotAz,
float pivotBx, float pivotBy, float pivotBz,
float rotAx, float rotAy, float rotAz,
float rotBx, float rotBy, float rotBz, int bDisableCollision) {}
xptr zbtAddPoint2PointConstraint1(xptr rigidBody,
float pivotX, float pivotY, float pivotZ) {}
xptr zbtAddPoint2PointConstraint(xptr rigidBodyA, xptr rigidBodyB,
float pivotAx, float pivotAy, float pivotAz,
float pivotBx, float pivotBy, float pivotBz, int bDisableCollision) {}
xptr zbtAddHingeConstraint1(xptr rigidBody,
float pivotX, float pivotY, float pivotZ,
float axisX, float axisY, float axisZ) {}
xptr zbtAddHingeConstraint(xptr rigidBodyA, xptr rigidBodyB,
float pivotAx, float pivotAy, float pivotAz,
float pivotBx, float pivotBy, float pivotBz,
float axisAx, float axisAy, float axisAz,
float axisBx, float axisBy, float axisBz, int bDisableCollision) {}
void zbtSetHingeLimits(xptr hinge, float low, float high,
float softness, float biasFactor, float relaxationFactor) {}
void zbtEnableHingeAngularMotor(xptr hinge, int bEnableMotor,
float targetVelocity, float maxMotorImpulse) {}
xptr zbtAddConeTwistConstraint1(xptr rigidBody,
float pivotX, float pivotY, float pivotZ,
float rotX, float rotY, float rotZ) {}
xptr zbtAddConeTwistConstraint(xptr rigidBodyA, xptr rigidBodyB,
float pivotAx, float pivotAy, float pivotAz,
float pivotBx, float pivotBy, float pivotBz,
float rotAx, float rotAy, float rotAz,
float rotBx, float rotBy, float rotBz, int bDisableCollision) {}
void zbtSetConeTwistLimits(xptr twist, float swingSpanA, float swingSpanB,
float twistSpan, float damping, float softness, float biasFactor,
float relaxationFactor) {}
void zbtEnableConeTwistMotor(xptr twist,
int bEnableMotor, float maxMotorImpulse,
float targetX, float targetY, float targetZ) {}
xptr zbtAddSliderConstraint1(xptr rigidBody,
float pivotX, float pivotY, float pivotZ,
float rotX, float rotY, float rotZ,
int bUseLinearReferenceWorldFrame) {}
xptr zbtAddSliderConstraint(xptr rigidBodyA, xptr rigidBodyB,
float pivotAx, float pivotAy, float pivotAz,
float pivotBx, float pivotBy, float pivotBz,
float rotAx, float rotAy, float rotAz,
float rotBx, float rotBy, float rotBz,
int bUseLinearReferenceFrameA, int bDisableCollision) {}
void zbtSetSliderLimits(xptr slider,
float linLower, float linUpper, float angLower, float angUpper) {}
void zbtSetSliderSoftness(xptr slider,
float dirLin, float dirAng, float limLin, float limAng,
float orthoLin, float orthoAng) {}
void zbtSetSliderRestitution(xptr slider,
float dirLin, float dirAng, float limLin, float limAng,
float orthoLin, float orthoAng) {}
void zbtSetSliderDamping(xptr slider,
float dirLin, float dirAng, float limLin, float limAng,
float orthoLin, float orthoAng) {}
void zbtEnableSliderLinearMotor(xptr slider, int bEnableMotor,
float targetVelocity, float maxForce) {}
void zbtEnableSliderAngularMotor(xptr slider, int bEnableMotor,
float targetVelocity, float maxForce) {}
xptr zbtAddGearConstraint(xptr rigidBodyA, xptr rigidBodyB,
float axisAx, float axisAy, float axisAz,
float axisBx, float axisBy, float axisBz,
float ratio) {}
void zbtSetGearConstraint(xptr gear,
float axisAx, float axisAy, float axisAz,
float axisBx, float axisBy, float axisBz,
float ratio) {}
xptr zbtAddGeneric6DofConstraint1(xptr rigidBody,
float pivotX, float pivotY, float pivotZ,
float rotX, float rotY, float rotZ,
int bUseLinearReferenceWorldFrame) {}
xptr zbtAddGeneric6DofConstraint(xptr rigidBodyA, xptr rigidBodyB,
float pivotAx, float pivotAy, float pivotAz,
float pivotBx, float pivotBy, float pivotBz,
float rotAx, float rotAy, float rotAz,
float rotBx, float rotBy, float rotBz,
int bUseLinearReferenceFrameA, int bDisableCollision) {}
void zbtSetGeneric6DofLimits(xptr dof, int axis, float lower, float upper) {}
void zbtSetGeneric6DofLinearLimits(xptr dof,
float lowerX, float lowerY, float lowerZ,
float upperX, float upperY, float upperZ) {}
void zbtSetGeneric6DofAngularLimits(xptr dof,
float lowerX, float lowerY, float lowerZ,
float upperX, float upperY, float upperZ) {}
xptr zbtAddGeneric6DofSpringConstraint1(xptr rigidBody,
float pivotX, float pivotY, float pivotZ,
float rotX, float rotY, float rotZ,
int bUseLinearReferenceWorldFrame) {}
xptr zbtAddGeneric6DofSpringConstraint(xptr rigidBodyA, xptr rigidBodyB,
float pivotAx, float pivotAy, float pivotAz,
float pivotBx, float pivotBy, float pivotBz,
float rotAx, float rotAy, float rotAz,
float rotBx, float rotBy, float rotBz,
int bUseLinearReferenceFrameA, int bDisableCollision) {}
void zbtSetGeneric6DofSpring(xptr spring,
int axis, int bEnableSpring, float stiffness, float damping,
float equilibriumPoint) {}
void zbtSetEnabled(xptr constraint, int bEnabled) {}
void zbtDeleteConstraint(xptr constraint) {}
// Raycast vehicle
void zbtSetVehicleTunning(float suspStiffness, float suspCompression,
float suspDamping, float maxSuspTravelCm, float maxSuspForce,
float frictionSlip) {}
xptr zbtCreateRaycastVehicle(xptr carChassis,
int rightAxis, int upAxis, int forwardAxis) {}
int zbtAddWheel(xptr vehicle,
float connectionPointX, float connectionPointY, float connectionPointZ,
float directionX, float directionY, float directionZ,
float wheelAxleX, float wheelAxleY, float wheelAxleZ,
float wheelRadius, float suspRestLength, int bIsFrontWheel) {}
void zbtSetWheelIsFront(xptr vehicle, int wheelId, int bIsFront) {}
void zbtSetWheelRadius(xptr vehicle, int wheelId, float radius) {}
void zbtSetWheelRollInfluence(xptr vehicle, int wheelId, float rollInfluence) {}
void zbtSetWheelFrictionSlip(xptr vehicle, int wheelId, float frictionSlip) {}
void zbtSetWheelSuspRestLength(xptr vehicle, int wheelId, float suspRestLength) {}
void zbtSetWheelMaxSuspTravel(xptr vehicle, int wheelId, float maxSuspTravel) {}
void zbtSetWheelSuspStiffness(xptr vehicle, int wheelId, float suspStiffness) {}
void zbtSetWheelDampingCompression(xptr vehicle, int wheelId,
float dampingCompression) {}
void zbtSetWheelDampingRelaxation(xptr vehicle, int wheelId,
float dampingRelaxation) {}
void zbtSetWheelSteering(xptr vehicle, int wheelId, float steering) {}
void zbtSetWheelEngineForce(xptr vehicle, int wheelId, float force) {}
void zbtSetWheelBrake(xptr vehicle, int wheelId, float brake) {}
void zbtResetVehicleSusp(xptr vehicle) {}
float zbtGetVehicleCurrentSpeed(xptr vehicle) {}
void zbtGetWheelPositionXYZ(xptr vehicle, int wheelId,
ref float outX, ref float outY, ref float outZ) {}
void zbtGetWheelPosition(xptr vehicle, int wheelId, xptr outPosition) {}
void zbtGetWheelRotationXYZ(xptr vehicle, int wheelId,
ref float outRx, ref float outRy, ref float outRz) {}
void zbtGetWheelRotation(xptr vehicle, int wheelId, xptr outRotation) {}
void zbtGetWheelPosRotXYZ(xptr vehicle, int wheelId,
ref float outX, ref float outY, ref float outZ,
ref float outRx, ref float outRy, ref float outRz) {}
void zbtGetWheelPosRot(xptr vehicle, int wheelId,
xptr outPosition, xptr outRotation) {}
void zbtDeleteRaycastVehicle(xptr vehicle) {}
// Ghost object
xptr zbtCreateGhostObject(xptr shape,
float x, float y, float z, float rx, float ry, float rz) {}
void zbtDeleteGhostObject(xptr ghostObject) {}
int zbtGetNumOverlappingObjects(xptr ghostObject) {}
xptr zbtGetOverlappingObject(xptr ghostObject, int index) {}
// Kinematic character controller
xptr zbtCreateKinematicCharacterController(
xptr ghostObject, float stepHeight) {}
void zbtDeleteKinematicCharacterController(xptr controller) {}
void zbtSetCharacterUpAxis(xptr controller, int axis) {}
void zbtSetCharacterWalkDirection(xptr controller,
float x, float y, float z) {}
void zbtSetCharacterVelocityForTimeInterval(xptr controller,
float x, float y, float z, float timeInterval) {}
void zbtCharacterWarp(xptr controller, float x, float y, float z) {}
void zbtSetCharacterFallSpeed(xptr controller, float fallSpeed) {}
void zbtSetCharacterJumpSpeed(xptr controller, float jumpSpeed) {}
void zbtSetCharacterMaxJumpHeight(xptr controller, float maxJumpHeight) {}
int zbtCharacterCanJump(xptr controller) {}
void zbtCharacterJump(xptr controller) {}
void zbtSetCharacterGravity(xptr controller, float gravity) {}
void zbtSetCharacterMaxSlope(xptr controller, float slope) {}
void zbtSetCharacterUseGhostSweepTest(xptr controller,
int bUseGhostObjectSweepTest) {}
int zbtCharacterOnGround(xptr controller) {}
void zbtCharacterReset(xptr controller) {}
void zbtSetCharacterUpInterpolate(xptr controller, int bInterpolate) {}
// Collision objects (in general)
void zbtSetFriction(xptr obj, float friction) {}
void zbtSetRestitution(xptr obj, float restitution) {}
void zbtSetHitFraction(xptr obj, float hitFraction) {}
void zbtGetPositionXYZ(xptr obj,
ref float outX, ref float outY, ref float outZ) {}
void zbtGetPosition(xptr obj, xptr outPosition) {}
void zbtSetPositionXYZ(xptr obj, float x, float y, float z) {}
void zbtSetPosition(xptr obj, xptr position) {}
void zbtGetRotationXYZ(xptr obj,
ref float outRx, ref float outRy, ref float outRz) {}
void zbtGetRotation(xptr obj, xptr outRotation) {}
void zbtSetRotationXYZ(xptr obj, float rx, float ry, float rz) {}
void zbtSetRotation(xptr obj, xptr rotation) {}
void zbtGetPosRotXYZ(xptr obj,
ref float outX, ref float outY, ref float outZ,
ref float outRx, ref float outRy, ref float outRz) {}
void zbtGetPosRot(xptr obj, xptr outPosition, xptr outRotation) {}
void zbtSetPosRotXYZ(xptr obj,
float x, float y, float z,
float rx, float ry, float rz) {}
void zbtSetPosRot(xptr obj, xptr position, xptr rotation) {}
void zbtSetCollisionFlags(xptr obj, int flags) {}
int zbtIsActive(xptr obj) {}
void zbtActivate(xptr obj, int bForceActivation) {}
void zbtSetActivationState(xptr obj, int newState) {}
void zbtForceActivationState(xptr obj, int newState) {}
void zbtSetDeactivationTime(xptr obj, float time) {}
void zbtSetUserIndex(xptr obj, int index) {}
int zbtGetUserIndex(xptr obj) {}
void zbtSetUserModel(xptr obj, model userModel) {}
model zbtGetUserModel(xptr obj) {}
// Collision detection
void zbtSetIgnoreCollisionCheck(xptr objA, xptr objB,
int bIgnoreCollisionCheck) {}
int zbtStartCollisionDetection() {}
int zbtGetNextContact(xptr outObjA, xptr outObjB,
xptr outPosA, xptr outPosB, xptr outNormal) {}
void zbtGetCollidedObjects(int contactIndex, xptr outObjA, xptr outObjB) {}
int zbtIsColliding(xptr obj) {}
int zbtGetNumberOfCollisions(xptr obj) {}
int zbtIsCollidedWith(xptr objA, xptr objB) {}
// Raycasting
xptr zbtRayTest(float fromX, float fromY, float fromZ, float toX, float toY, float toZ) {}
void zbtGetRayTestHitPointXYZ(ref float outX, ref float outY, ref float outZ) {}
void zbtGetRayTestHitPoint(xptr outPosition) {}
void zbtGetRayTestHitNormalXYZ(ref float outX, ref float outY, ref float outZ) {}
void zbtGetRayTestHitNormal(xptr outNormal) {}]]>
</Source>
</ZExternalLibrary>
<ZLibrary>
<Source>
<![CDATA[const int
CUBE=0,
SPHERE=1,
CONE=2,
CYLINDER=3,
CAPSULE=4,
ARROW=5,
STONE=6,
PLANE=7,
IDMAX=7;
xptr
World,
CubeShape,SphereShape,ConeShape,CylinderShape,CapsuleShape,
ArrowShape,StoneShape,
PlaneShape;]]>
</Source>
</ZLibrary>
<ZExpression>
<Expression>
<![CDATA[// Init physical world
World = zbtCreateWorld();
zbtSetCurrentWorld(World);
zbtSetWorldGravity(0, 0, 0);
// Basic collision shapes
SphereShape = zbtCreateSphereShape(1);
CubeShape = zbtCreateBoxShape(1,1,1);
ConeShape = zbtCreateConeShape(1,1);
CapsuleShape = zbtCreateCapsuleShape(1,1);
CylinderShape = zbtCreateCylinderShape(1,1);
// Squished shapes
ArrowShape = zbtCreateConeShape(1, 1);
zbtSetShapeLocalScaling(ArrowShape, 1.2, 1.5, 0.4);
StoneShape = zbtCreateScalableSphereShape(1.0);
zbtSetShapeLocalScaling(StoneShape, 1.4, 0.4, 1.4);
// Compound shapes
PlaneShape = zbtCreateCompoundShape();
zbtAddChildShape(PlaneShape, zbtCreateBoxShape(0.5, 0.2, 2.6), 0,0,-0.8, 0,0,0); // Hull
zbtAddChildShape(PlaneShape, zbtCreateBoxShape(0.9, 0.1, 0.3), 1.4,-0.1,1.05, -0.1,0.6,-0.53); // Wing right
zbtAddChildShape(PlaneShape, zbtCreateBoxShape(0.9, 0.1, 0.3), -1.4,-0.1,1.05, 0.1,0.6,0.03); // Wing left
createModel(TestModel);]]>
</Expression>
</ZExpression>
</OnLoaded>
<OnUpdate>
<ZExpression Comment="Update ZgeBullet">
<Expression>
<![CDATA[Timer += App.DeltaTime;
zbtStepSimulation(App.DeltaTime, 0, 0);]]>
</Expression>
</ZExpression>
</OnUpdate>
<OnClose>
<ZExpression Comment="Destroy physics">
<Expression>
<![CDATA[// ZgeBullet Destroy physical world
zbtDestroyWorld(World);
zbtDeleteAllShapes();]]>
</Expression>
</ZExpression>
</OnClose>
<Content>
<Group Comment="Meshes">
<Children>
<Mesh Name="CubeMesh">
<Producers>
<MeshBox/>
</Producers>
</Mesh>
<Mesh Name="SphereMesh">
<Producers>
<MeshBox Scale="1 0.5 1" XCount="18" YCount="12" Grid2DOnly="255"/>
<MeshExpression AutoNormals="0">
<Expression>
<![CDATA[//
float E, A, K, X, Y, Z;
// Convert range to radians
E = v.Y*PI; // Elevation
A = v.X*PI; // Azimuth
// Convert spherical coordinates into cartesian
K = cos(E);
X = sin(A)*K;
Y = sin(E);
Z = cos(A)*K;
// Assign coordinates
v.X = X;
v.Y = Y;
v.Z = Z;
n.X = X;
n.Y = Y;
n.Z = Z;]]>
</Expression>
</MeshExpression>
</Producers>
</Mesh>
<Mesh Name="ConeMesh">
<Producers>
<MeshSphere ZSamples="3" RadialSamples="18"/>
<MeshTransform Rotation="0.25 0 0"/>
<MeshExpression Expression="v.Y = v.Y < 0.25 ? -0.5 : 0.5;"/>
</Producers>
</Mesh>
<Mesh Name="CylinderMesh">
<Producers>
<MeshBox Scale="1 0.5 1" XCount="18" YCount="2" Grid2DOnly="255"/>
<MeshExpression AutoNormals="0">
<Expression>
<![CDATA[float k;
if(abs(v.Y) < 0.5){
k = v.X * PI;
v.X = sin(k);
v.Z = cos(k);
} else {
v.X = 0;
v.Z = 0;
}
v.Y = v.Y < 0 ? -1 : 1;
n.X = v.X;
n.Y = v.Y;
n.Z = v.Z;]]>
</Expression>
</MeshExpression>
</Producers>
</Mesh>
<Mesh Name="CapsuleMesh">
<Producers>
<MeshBox Scale="0.5 0.5 1" XCount="18" Grid2DOnly="255"/>
<MeshExpression AutoNormals="0">
<Expression>
<![CDATA[float RX, SX, CX;
RX = v.X*PI*2;
SX = sin(RX); CX = cos(RX);
v.X = SX;
v.Z = CX;;
n.X = v.X;
n.Y = 0;
n.Z = v.Z;]]>
</Expression>
</MeshExpression>
<MeshBox Comment="bottom cap" Scale="0.5 0.5 1" XCount="18" YCount="6" Grid2DOnly="255"/>
<MeshExpression AutoNormals="0">
<Expression>
<![CDATA[float RX, SX, CX,
RY, SY, CY;
RX = v.X*PI*2;
RY = v.Y*PI/2-PI/4;
SX = sin(RX); CX = cos(RX);
SY = sin(RY); CY = cos(RY);
v.X = SX*CY;///2;
v.Y = SY;///2;
v.Z = CX*CY;///2;
n.X = v.X;
n.Y = v.Y;
n.Z = v.Z;
v.Y -= 0.5;]]>
</Expression>
</MeshExpression>
<MeshCombine/>
<MeshBox Comment="top cap" Scale="0.5 0.5 1" XCount="18" YCount="6" Grid2DOnly="255"/>
<MeshExpression AutoNormals="0">
<Expression>
<![CDATA[float RX, SX, CX,
RY, SY, CY;
RX = v.X*PI*2;
RY = v.Y*PI/2+PI/4;
SX = sin(RX); CX = cos(RX);
SY = sin(RY); CY = cos(RY);
v.X = SX*CY;///2;
v.Y = SY;///2;
v.Z = CX*CY;///2;
n.X = v.X;
n.Y = v.Y;
n.Z = v.Z;
v.Y += 0.5;]]>
</Expression>
</MeshExpression>
<MeshCombine/>
</Producers>
</Mesh>
<Mesh Name="PlaneMesh">
<Producers>
<MeshBox Scale="0.5 0.2 2.6"/>
<MeshTransform Position="0 0 -0.8"/>
<MeshBox Comment="right" Scale="0.9 0.1 0.3"/>
<MeshTransform Position="1.4 -0.1 1.05" Rotation="-0.1 0.6 -0.53"/>
<MeshCombine/>
<MeshBox Comment="left" Scale="0.9 0.1 0.3"/>
<MeshTransform Position="-1.4 -0.1 1.05" Rotation="0.1 0.6 0.03"/>
<MeshCombine/>
</Producers>
</Mesh>
</Children>
</Group>
<Model Name="TestModel">
<Definitions>
<Variable Name="ModelID" Type="1"/>
<Variable Name="ModelBody" Type="9"/>
<ZLibrary>
<Source>
<![CDATA[void CreateObjectBody()
{
if (ModelBody != null) zbtDeleteRigidBody(ModelBody);
TransformCollision.Scale = vector3(1,1,1);
TransformCollision.Translate = vector3(0,0,0);
TransformCollision.Rotate = vector3(0,0,0);
switch (ModelID)
{
case CUBE:
CollisionMesh.Mesh = CubeMesh;
CurrentModel.ModelBody = zbtCreateRigidBodyXYZ(0, CubeShape, CurrentModel.Position.X, CurrentModel.Position.Y, CurrentModel.Position.Z, CurrentModel.Rotation.X, CurrentModel.Rotation.Y, CurrentModel.Rotation.Z);
break;
case SPHERE:
CollisionMesh.Mesh = SphereMesh;
CurrentModel.ModelBody = zbtCreateRigidBodyXYZ(0, SphereShape, CurrentModel.Position.X, CurrentModel.Position.Y, CurrentModel.Position.Z, 0, 0, 0);
break;
case CONE:
CollisionMesh.Mesh = ConeMesh;
CurrentModel.ModelBody = zbtCreateRigidBodyXYZ(0, ConeShape, CurrentModel.Position.X, CurrentModel.Position.Y, CurrentModel.Position.Z, CurrentModel.Rotation.X, CurrentModel.Rotation.Y, CurrentModel.Rotation.Z);
break;
case CYLINDER:
CollisionMesh.Mesh = CylinderMesh;
CurrentModel.ModelBody = zbtCreateRigidBodyXYZ(0, CylinderShape, CurrentModel.Position.X, CurrentModel.Position.Y, CurrentModel.Position.Z, CurrentModel.Rotation.X, CurrentModel.Rotation.Y, CurrentModel.Rotation.Z);
break;
case CAPSULE:
CollisionMesh.Mesh = CapsuleMesh;
CurrentModel.ModelBody = zbtCreateRigidBodyXYZ(0, CapsuleShape, CurrentModel.Position.X, CurrentModel.Position.Y, CurrentModel.Position.Z, CurrentModel.Rotation.X, CurrentModel.Rotation.Y, CurrentModel.Rotation.Z);
break;
case ARROW:
CollisionMesh.Mesh = ConeMesh;
TransformCollision.Scale = vector3(1.2,1.5,0.4);
CurrentModel.ModelBody = zbtCreateRigidBodyXYZ(0, ArrowShape, CurrentModel.Position.X, CurrentModel.Position.Y, CurrentModel.Position.Z, CurrentModel.Rotation.X, CurrentModel.Rotation.Y, CurrentModel.Rotation.Z);
break;
case STONE:
CollisionMesh.Mesh = SphereMesh;
TransformCollision.Scale = vector3(1.4, 0.4, 1.4);
/*
xptr sh = zbtCreateScalableSphereShape(1.0);
zbtSetShapeLocalScaling(sh, 2, 0.4, 2);
CurrentModel.ModelBody = zbtCreateRigidBodyXYZ(1, sh, CurrentModel.Position.X, CurrentModel.Position.Y, CurrentModel.Position.Z, CurrentModel.Rotation.X, CurrentModel.Rotation.Y, CurrentModel.Rotation.Z);
*/
CurrentModel.ModelBody = zbtCreateRigidBodyXYZ(1, StoneShape, CurrentModel.Position.X, CurrentModel.Position.Y, CurrentModel.Position.Z, CurrentModel.Rotation.X, CurrentModel.Rotation.Y, CurrentModel.Rotation.Z);
break;
case PLANE:
CollisionMesh.Mesh = PlaneMesh;
CurrentModel.ModelBody = zbtCreateRigidBodyXYZ(0, PlaneShape, CurrentModel.Position.X, CurrentModel.Position.Y, CurrentModel.Position.Z, CurrentModel.Rotation.X, CurrentModel.Rotation.Y, CurrentModel.Rotation.Z);
break;
}
}]]>
</Source>
</ZLibrary>
</Definitions>
<OnSpawn>
<ZExpression>
<Expression>
<![CDATA[Timer = 0;
CurrentModel.RotationVelocity = rnd()*0.1;
CreateObjectBody();]]>
</Expression>
</ZExpression>
</OnSpawn>
<OnUpdate>
<ZExpression>
<Expression>
<![CDATA[CurrentModel.Position.X += cos(Timer)/80;
CurrentModel.Position.Y += sin(Timer)/80;
zbtSetPosRot(ModelBody, CurrentModel.Position, CurrentModel.Rotation);
float r,x,y,z;
r = tan(App.FOV/360*PI);
//r = 0.4142; // If you're using a constant FOV, you can swap out this calculation with the resulting value.
z = App.CameraPosition.Z - CurrentModel.Position.Z;
x = z * App.MousePosition.X * r * App.ViewportWidth/App.ViewportHeight; // If you're using a constant aspectRatio, you can swap out "App.ViewportWidth/App.ViewportHeight" with a specific value.
y = z * App.MousePosition.Y * r;
if (zbtRayTest(x, y, 100, x, y, -100) != null)
BoxColor.Color = vector3(1,0,0);
else
BoxColor.Color = vector3(1,1,1);]]>
</Expression>
</ZExpression>
<KeyPress Comment="LEFT" Keys="<" RepeatDelay="0.1">
<OnPressed>
<ZExpression>
<Expression>
<![CDATA[if (--ModelID<0) ModelID = IDMAX;
CreateObjectBody();]]>
</Expression>
</ZExpression>
</OnPressed>
</KeyPress>
<KeyPress Comment="RIGHT" Keys=">" RepeatDelay="0.1">
<OnPressed>
<ZExpression>
<Expression>
<![CDATA[if (++ModelID>IDMAX) ModelID = 0;
CreateObjectBody();]]>
</Expression>
</ZExpression>
</OnPressed>
</KeyPress>
</OnUpdate>
<OnRender>
<RenderTransformGroup Name="TransformCollision">
<Children>
<UseMaterial Material="ObjectMaterial"/>
<RenderSetColor Name="BoxColor" Color="1 1 1 1"/>
<RenderMesh Name="CollisionMesh" Mesh="CubeMesh"/>
</Children>
</RenderTransformGroup>
</OnRender>
<OnRemove>
<ZExpression Comment="Delete rigid body and shape" Expression="zbtDeleteRigidBody(ModelBody);"/>
</OnRemove>
</Model>
<Material Name="ObjectMaterial" WireframeWidth="0" SpecularColor="0 0 0 1" EmissionColor="0 0 0 1"/>
<Variable Name="Timer"/>
</Content>
</ZApplication>
I've edited my example by adding a skipping stone after the arrow shape. Collisions works on the stone but not on the arrow, so it seems that we can only use zbtSetShapeLocalScaling on zbtCreateScalableSphereShape. Hence the name?
Anyway, I'm going to avoid pixel perfect collision shapes in Omeganaut, because it is nearly impossible to hit them and it's not funny to play. I'll stay with simple boxes and spheres!
BTW, is it better to use boxes or scalable spheres in term of speed performance?