public CCPhysicsBody(float mass, float moment, CCPoint offset) { var offsetcp = new cpVect(offset.X, offset.Y);; _positionOffset = offsetcp != null ? offsetcp : cpVect.Zero; _node = null; _world = null; _info = null; _dynamic = true; _enabled = true; _rotationEnabled = true; _gravityEnabled = true; _massDefault = mass == MASS_DEFAULT; _momentDefault = moment == MOMENT_DEFAULT; _mass = mass; _area = 0.0f; _density = 0.0f; _moment = moment; _isDamping = false; _linearDamping = 0.0f; _angularDamping = 0.0f; _tag = 0; _categoryBitmask = int.MaxValue; //(UINT_MAX) _collisionBitmask = 0; _contactTestBitmask = int.MaxValue; _group = 0; _positionResetTag = false; _rotationResetTag = false; _rotationOffset = 0; _info = new CCPhysicsBodyInfo(); _info.Body = new cpBody(_mass, _moment); }
public CCRayCastCallbackInfo(CCPhysicsWorld world, Func <CCPhysicsWorld, CCPhysicsRayCastInfo, object, bool> func, CCPoint p1, CCPoint p2, object data) { this.world = world; this.func = func; this.p1 = p1; this.p2 = p2; this.data = data; }
public CCRayCastCallbackInfo(CCPhysicsWorld world, Func <CCPhysicsWorld, CCPhysicsRayCastInfo, object, bool> func, CCPoint p1, CCPoint p2, object data) : this() { this.World = world; this.Function = func; this.Pont1 = p1; this.Point2 = p2; this.Data = data; }
public CCRayCastCallbackInfo(CCPhysicsWorld world, Func<CCPhysicsWorld, CCPhysicsRayCastInfo, object, bool> func, CCPoint p1, CCPoint p2, object data) { this.world = world; this.func = func; this.p1 = p1; this.p2 = p2; this.data = data; }
public CCRayCastCallbackInfo(CCPhysicsWorld world, Func<CCPhysicsWorld, CCPhysicsRayCastInfo, object, bool> func, CCPoint p1, CCPoint p2, object data) : this() { this.World = world; this.Function = func; this.Pont1 = p1; this.Point2 = p2; this.Data = data; }
public CCPhysicsJoint() { _bodyA = null; _bodyB = null; _world = null; _info = null; _enable = false; _collisionEnable = true; _destoryMark = false; _tag = 0; }
public CCPhysicsContact() : base(PHYSICSCONTACT_EVENT_NAME) { _world = null; _shapeA = null; _shapeB = null; _eventCode = EventCode.NONE; _info = null; _notificationEnable = true; _result = true; _data = null; _contactInfo = null; _contactData = null; _preContactData = null; }
public CCScene(CCWindow window, CCViewport viewport, CCDirector director = null) #endif { IgnoreAnchorPointForPosition = true; AnchorPoint = new CCPoint(0.5f, 0.5f); Viewport = viewport; Window = window; Director = (director == null) ? window.DefaultDirector : director; if (window != null && director != null) { window.AddSceneDirector(director); } #if USE_PHYSICS _physicsWorld = physics ? new CCPhysicsWorld(this) : null; #endif SceneResolutionPolicy = window.DesignResolutionPolicy; }
public static bool CollisionBeginCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world) { cpShape a, b; arb.GetShapes(out a, out b); CCPhysicsShapeInfo ita = null, itb = null; cp.AssertWarn(CCPhysicsShapeInfo.Map.TryGetValue(a, out ita) && CCPhysicsShapeInfo.Map.TryGetValue(b, out itb)); if (a != null || b != null) { return(false); } CCPhysicsContact contact = new CCPhysicsContact(ita.getShape(), itb.getShape()); arb.data = contact; contact._contactInfo = arb; return(world.CollisionBeginCallback(contact)); }
public CCPointQueryCallbackInfo(CCPhysicsWorld w, Func<CCPhysicsWorld, CCPhysicsShape, object, bool> f, object d) { world = w; func = f; data = d; }
public static void CollisionSeparateCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world) { CCPhysicsContact contact = (CCPhysicsContact)(arb.data); if (contact != null) world.CollisionSeparateCallback(contact); //delete contact; }
public CCScene(CCWindow window, CCViewport viewport, CCDirector director = null) #endif { IgnoreAnchorPointForPosition = true; AnchorPoint = new CCPoint(0.5f, 0.5f); Viewport = viewport; Window = window; Director = (director == null) ? window.DefaultDirector : director; if (window != null && director != null) window.AddSceneDirector(director); #if USE_PHYSICS _physicsWorld = physics ? new CCPhysicsWorld(this) : null; #endif SceneResolutionPolicy = window.DesignResolutionPolicy; }
public static bool CollisionPreSolveCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world) { return world.CollisionPreSolveCallback((CCPhysicsContact)(arb.data)); }
public static void CollisionPostSolveCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world) { world.CollisionPostSolveCallback((CCPhysicsContact)(arb.data)); }
public static bool CollisionBeginCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world) { cpShape a, b; arb.GetShapes(out a, out b); CCPhysicsShapeInfo ita = null, itb = null; cp.AssertWarn(CCPhysicsShapeInfo.Map.TryGetValue(a, out ita) && CCPhysicsShapeInfo.Map.TryGetValue(b, out itb)); if (a != null || b != null) return false; CCPhysicsContact contact = new CCPhysicsContact(ita.getShape(), itb.getShape()); arb.data = contact; contact._contactInfo = arb; return world.CollisionBeginCallback(contact); }
/// ////////////////////////////////////////////////////////////////// public bool WriteToFile(CCPhysicsWorld world, String filename, int indentFactor, StringBuilder errorMsg) { if (null == world || null == filename) return false; using (System.IO.TextWriter writeFile = new StreamWriter(filename)) { try { writeFile.WriteLine((world).ToString()); } catch (Exception e) { errorMsg.Append("Error writing JSON to file: " + filename + " " + e.Message); return false; } } return true; }
// SIN REVISAR CCPhysicsJoint j2CCPhysicsJoint(CCPhysicsWorld space, JObject jointValue) { CCPhysicsJoint joint = null; int bodyIndexA = (int)jointValue["bodyA"]; int bodyIndexB = (int)jointValue["bodyB"]; if (bodyIndexA >= m_bodies.Count || bodyIndexB >= m_bodies.Count) return null; // set features common to all joints //var bodyA = m_bodies[bodyIndexA]; //var bodyB = m_bodies[bodyIndexB]; //var collideConnected = jointValue["collideConnected"] == null ? false : (bool)jointValue["collideConnected"]; // keep these in scope after the if/else below //b2RevoluteJointDef revoluteDef; //b2PrismaticJointDef prismaticDef; //b2DistanceJointDef distanceDef; //b2PulleyJointDef pulleyDef; //b2MouseJointDef mouseDef; //b2GearJointDef gearDef; //b2WheelJoint wheelDef; //b2WeldJointDef weldDef; //b2FrictionJointDef frictionDef; //b2RopeJointDef ropeDef; //MotorJoint motorDef; cpVect mouseJointTarget = new cpVect(0, 0); string type = jointValue["type"].ToString() == null ? "" : jointValue["type"].ToString(); if (type == "revolute") { CCPoint localAnchorA = jsonToPoint("anchorA", jointValue); CCPoint localAnchorB = jsonToPoint("anchorB", jointValue); // joint = new cpPivotJoint(m_bodies[bodyIndexA], m_bodies[bodyIndexB], localAnchorA, localAnchorB); // joint = CCPhysicsJointPin.Construct(m_bodies[bodyIndexA],m_bodies[bodyIndexB],localAnchorA); space.AddJoint(joint); //jointDef = revoluteDef = new b2RevoluteJointDef(); // JointFactory.CreateRevoluteJoint(world, bodyA, bodyB, jsonToVec("anchorB", jointValue)); //revoluteDef.localAnchorA = jsonToVec("anchorA", jointValue); //revoluteDef.localAnchorB = jsonToVec("anchorB", jointValue); //revoluteDef.referenceAngle = jsonToFloat("refAngle", jointValue); //revoluteDef.enableLimit = jointValue["enableLimit"] == null ? false : (bool)jointValue["enableLimit"]; //revoluteDef.lowerAngle = jsonToFloat("lowerLimit", jointValue); //revoluteDef.upperAngle = jsonToFloat("upperLimit", jointValue); //revoluteDef.enableMotor = jointValue["enableMotor"] == null ? false : (bool)jointValue["enableMotor"]; //revoluteDef.motorSpeed = jsonToFloat("motorSpeed", jointValue); //revoluteDef.maxMotorTorque = jsonToFloat("maxMotorTorque", jointValue); } //else if (type == "prismatic") //{ //jointDef = prismaticDef = new b2PrismaticJointDef(); //JointFactory.CreatePrismaticJoint(world, bodyA, bodyB, localAnchorB, localAxis); //prismaticDef.localAnchorA = jsonToVec("anchorA", jointValue); //prismaticDef.localAnchorB = jsonToVec("anchorB", jointValue); //if (jointValue["localAxisA"] != null) // prismaticDef.localAxisA = jsonToVec("localAxisA", jointValue); //else // prismaticDef.localAxisA = jsonToVec("localAxis1", jointValue); //prismaticDef.referenceAngle = jsonToFloat("refAngle", jointValue); //prismaticDef.enableLimit = jointValue["enableLimit"] == null ? false : (bool)jointValue["enableLimit"]; //prismaticDef.lowerTranslation = jsonToFloat("lowerLimit", jointValue); //prismaticDef.upperTranslation = jsonToFloat("upperLimit", jointValue); //prismaticDef.enableMotor = jointValue["enableMotor"] == null ? false : (bool)jointValue["enableMotor"]; //prismaticDef.motorSpeed = jsonToFloat("motorSpeed", jointValue); //prismaticDef.maxMotorForce = jsonToFloat("maxMotorForce", jointValue); //} else if (type == "distance") { CCPoint localAnchorA = jsonToPoint("anchorA", jointValue); CCPoint localAnchorB = jsonToPoint("anchorB", jointValue); float length = jsonToFloat("length", jointValue); float stiffness = jsonToFloat("frequency", jointValue); float damping = jsonToFloat("dampingRatio", jointValue); joint = CCPhysicsJointSpring.Construct(m_bodies[bodyIndexA], m_bodies[bodyIndexB], localAnchorA, localAnchorB, stiffness, damping); // joint =new cpDampedSpring(m_bodies[bodyIndexA], m_bodies[bodyIndexB], localAnchorA, localAnchorB, length, stiffness, damping); space.AddJoint(joint); //jointDef = distanceDef = new b2DistanceJointDef(); //distanceDef.localAnchorA = jsonToVec("anchorA", jointValue); //distanceDef.localAnchorB = jsonToVec("anchorB", jointValue); //distanceDef.length = jsonToFloat("length", jointValue); //distanceDef.frequencyHz = jsonToFloat("frequency", jointValue); //distanceDef.dampingRatio = jsonToFloat("dampingRatio", jointValue); } //else if (type == "pulley") //{ // jointDef = pulleyDef = new b2PulleyJointDef(); // pulleyDef.groundAnchorA = jsonToVec("groundAnchorA", jointValue); // pulleyDef.groundAnchorB = jsonToVec("groundAnchorB", jointValue); // pulleyDef.localAnchorA = jsonToVec("anchorA", jointValue); // pulleyDef.localAnchorB = jsonToVec("anchorB", jointValue); // pulleyDef.lengthA = jsonToFloat("lengthA", jointValue); // pulleyDef.lengthB = jsonToFloat("lengthB", jointValue); // pulleyDef.ratio = jsonToFloat("ratio", jointValue); //} //else if (type == "mouse") //{ // jointDef = mouseDef = new b2MouseJointDef(); // mouseJointTarget = jsonToVec("target", jointValue); // mouseDef.target = jsonToVec("anchorB", jointValue);// alter after creating joint // mouseDef.maxForce = jsonToFloat("maxForce", jointValue); // mouseDef.frequencyHz = jsonToFloat("frequency", jointValue); // mouseDef.dampingRatio = jsonToFloat("dampingRatio", jointValue); //} // Gear joints are apparently not implemented in JBox2D yet, but // when they are, commenting out the following section should work. //else if (type == "gear") //{ // jointDef = gearDef = new b2GearJointDef(); //JointFactory.CreateGearJoint(world, joint1, joint2, ratio); // int jointIndex1 = (int)jointValue["joint1"]; // int jointIndex2 = (int)jointValue["joint2"]; // var joint1 = m_joints[jointIndex1]; // var joint2 = m_joints[jointIndex2]; // var ratio = jsonToFloat("ratio", jointValue); // //joint = gearDef = JointFactory.CreateGearJoint(world, joint1, joint2, ratio); //} // Wheel joints are apparently not implemented in JBox2D yet, but // when they are, commenting out the following section should work. else if (type == "wheel") { CCPoint localAnchorA = jsonToPoint("anchorA", jointValue); CCPoint localAnchorB = jsonToPoint("anchorB", jointValue); CCPoint localAxisA = jsonToPoint("localAxisA", jointValue); //joint =new cpGrooveJoint(m_bodies[bodyIndexA], m_bodies[bodyIndexB], localAnchorA, cpVect.cpvadd(localAnchorA, localAxisA), localAnchorB); joint =CCPhysicsJointGroove.Construct(m_bodies[bodyIndexA], m_bodies[bodyIndexB], localAnchorA, localAnchorA+localAxisA, localAnchorB); space.AddJoint(joint); //also add a distance joint //Chipmunk groove joints have limits whereas b2WheelJoints do not, and chipmunk damped springs //seem to be only one way (ie. only preventing compression) whereas b2WheelJoints are two-way, //for lack of a better description. This can be accounted for in a rather messy way by using //the length of the axis to adjust the target position of the spring so that it is not right //on top of the limit of the groove joint. float length = localAxisA.Length * 0.5f; float stiffness = jsonToFloat("springFrequency", jointValue); float damping = jsonToFloat("springDampingRatio", jointValue); joint =CCPhysicsJointSpring.Construct(m_bodies[bodyIndexA], m_bodies[bodyIndexB], localAnchorA, localAnchorB, stiffness, damping); space.AddJoint( joint); //jointDef = revoluteDef = new b2RevoluteJointDef(); //revoluteDef.localAnchorA = jsonToVec("anchorA", jointValue); //revoluteDef.localAnchorB = jsonToVec("anchorB", jointValue); //revoluteDef.enableMotor = jointValue["enableMotor"] == null ? false : (bool)jointValue["enableMotor"]; //revoluteDef.motorSpeed = jsonToFloat("motorSpeed", jointValue); //revoluteDef.maxMotorTorque = jsonToFloat("maxMotorTorque", jointValue); //jointDef = wheelDef = new b2WheelJointDef(); //JointFactory.CreateWheelJoint(world, bodyA, bodyB, localAnchorB, localAxisA); //var localAnchorA = jsonToVec("anchorA", jointValue); //var localAnchorB = (jsonToVec("anchorB", jointValue)); //var localAxisA = (jsonToVec("localAxisA", jointValue)); //var enableMotor = jointValue["enableMotor"] == null ? false : (bool)jointValue["enableMotor"]; //var motorSpeed = jsonToFloat("motorSpeed", jointValue); //var maxMotorTorque = jsonToFloat("maxMotorTorque", jointValue); //var frequencyHz = jsonToFloat("springFrequency", jointValue); //var dampingRatio = jsonToFloat("springDampingRatio", jointValue); //wheelDef.LocalAnchorA = localAnchorA; //wheelDef.LocalAnchorB = localAnchorB; //wheelDef.MotorEnabled = enableMotor; //wheelDef.MotorSpeed = motorSpeed; //wheelDef.SpringFrequencyHz = frequencyHz; //wheelDef.MaxMotorTorque = maxMotorTorque; //wheelDef.SpringDampingRatio = dampingRatio; } //else if (type == "weld") //{ // jointDef = weldDef = new b2WeldJointDef(); // weldDef.localAnchorA = jsonToVec("anchorA", jointValue); // weldDef.localAnchorB = jsonToVec("anchorB", jointValue); // weldDef.referenceAngle = 0; //} //else if (type == "friction") //{ // jointDef = frictionDef = new b2FrictionJointDef(); // frictionDef.localAnchorA = jsonToVec("anchorA", jointValue); // frictionDef.localAnchorB = jsonToVec("anchorB", jointValue); // frictionDef.maxForce = jsonToFloat("maxForce", jointValue); // frictionDef.maxTorque = jsonToFloat("maxTorque", jointValue); //} //else if (type == "rope") //{ // jointDef = ropeDef = new b2RopeJointDef(); // ropeDef.localAnchorA = jsonToVec("anchorA", jointValue); // ropeDef.localAnchorB = jsonToVec("anchorB", jointValue); // ropeDef.maxLength = jsonToFloat("maxLength", jointValue); //} //else if (type == "motor") //{ // var maxForce = jsonToFloat("maxForce", jointValue); // var maxMotorTorque = jsonToFloat("maxTorque", jointValue); // var angularOffset = jsonToFloat("refAngle", jointValue); // joint = motorDef = new MotorJoint(bodyA, bodyB); // world.AddJoint(joint); // motorDef.LinearOffset = jsonToVec("anchorA", jointValue); // motorDef.MaxForce = maxForce; // motorDef.MaxTorque = maxMotorTorque; // motorDef.AngularOffset = angularOffset; //} //if (null != jointDef) //{ // // set features common to all joints // jointDef.BodyA = m_bodies[bodyIndexA]; // jointDef.BodyB = m_bodies[bodyIndexB]; // jointDef.CollideConnected = jointValue["collideConnected"] == null ? false : (bool)jointValue["collideConnected"]; // joint = space.CreateJoint(jointDef); // if (type.Equals("mouse")) // ((b2MouseJoint)joint).SetTarget(mouseJointTarget); // String jointName = jointValue["name"] == null ? "" : (string)jointValue["name"]; // if (!jointName.Equals("")) // { // SetJointName(joint, jointName); // } //} return joint; }
public static bool CollisionPreSolveCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world) { return(world.CollisionPreSolveCallback((CCPhysicsContact)(arb.data))); }
public CCPhysicsBody(float mass, float moment, CCPoint offset) { var offsetcp = new cpVect(offset.X, offset.Y); ; _positionOffset = offsetcp != null ? offsetcp : cpVect.Zero; _node = null; _world = null; _info = null; _dynamic = true; _enabled = true; _rotationEnabled = true; _gravityEnabled = true; _massDefault = mass == MASS_DEFAULT; _momentDefault = moment == MOMENT_DEFAULT; _mass = mass; _area = 0.0f; _density = 0.0f; _moment = moment; _isDamping = false; _linearDamping = 0.0f; _angularDamping = 0.0f; _tag = 0; _categoryBitmask = int.MaxValue;//(UINT_MAX) _collisionBitmask = 0; _contactTestBitmask = int.MaxValue; _group = 0; _positionResetTag = false; _rotationResetTag = false; _rotationOffset = 0; _info = new CCPhysicsBodyInfo(); _info.Body = new cpBody(_mass, _moment); }
public CCPointQueryCallbackInfo(CCPhysicsWorld w, Func <CCPhysicsWorld, CCPhysicsShape, object, bool> f, object d) { world = w; func = f; data = d; }
public void SetWorld(CCPhysicsWorld world) { _world = world; }
protected void readCustomPropertiesFromJson(CCPhysicsWorld item, JObject value) { if (null == item) return; if (value["customProperties"] != null) return; int i = 0; JArray propValues = (JArray)value["customProperties"]; if (null != propValues) { int numPropValues = propValues.Count; for (i = 0; i < numPropValues; i++) { JObject propValue = (JObject)propValues[i]; String propertyName = propValue["name"].ToString(); if (propValue["int"] != null) SetCustomInt(item, propertyName, (int)propValue["int"]); if (propValue["float"] != null) SetCustomFloat(item, propertyName, (float)propValue["float"]); if (propValue["string"] != null) SetCustomString(item, propertyName, propValue["string"].ToString()); if (propValue["vec2"] != null) SetCustomVector(item, propertyName, this.jsonToVec("vec2", propValue)); if (propValue["bool"] != null) SetCustomBool(item, propertyName, (bool)propValue["bool"]); } } }
public CCPointQueryCallbackInfo(CCPhysicsWorld w, Func<CCPhysicsWorld, CCPhysicsShape, object, bool> f, object d) { World = w; Function = f; Data = d; }
public CCPhysicsBody j2CCPhysicsBody(CCPhysicsWorld world, JObject bodyValue) { CCPhysicsBody body = null; int i = 0; JArray fixtureValues = (JArray)bodyValue["fixture"]; if (null != fixtureValues) { int numFixtureValues = fixtureValues.Count; for (i = 0; i < numFixtureValues; i++) { JObject fixtureValue = (JObject)fixtureValues[i]; body = j2CCPhysicsShape(fixtureValue, (int)bodyValue.GetValue("type")); readCustomPropertiesFromJson(body, fixtureValue); } } body.Position = jsonToPoint("position", bodyValue); body.SetAngle(jsonToFloat("angle", bodyValue)); body.SetVelocity(jsonToPoint("linearVelocity", bodyValue)); body.SetAngularVelocity( jsonToFloat("angularVelocity", bodyValue)); //body. linearDamping = jsonToFloat("linearDamping", bodyValue, -1, 0); //body.set angularDamping = jsonToFloat("angularDamping", bodyValue, -1, 0); //body.gravityScale = jsonToFloat("gravityScale", bodyValue, -1, 1); //body.allowSleep = bodyValue["allowSleep"] == null ? false : (bool)bodyValue["allowSleep"]; //body.awake =; var awake = bodyValue["awake"] == null ? false : (bool)bodyValue["awake"]; if (!awake) body.Body.Sleep(); var fixedRotation = bodyValue["fixedRotation"] == null ? false : (bool)bodyValue["fixedRotation"]; if (fixedRotation) body.Moment = cp.Infinity; //body.bullet = bodyValue["bullet"] == null ? false : (bool)bodyValue["bullet"]; //bodyDef.active = bodyValue["active"] == null ? false : (bool)bodyValue["active"]; //body.active = true; String bodyName = bodyValue["name"] == null ? "" : (string)bodyValue["active"]; if (!string.IsNullOrEmpty(bodyName)) SetBodyName(body, bodyName); // may be necessary if user has overridden mass characteristics //b2MassData massData = new b2MassData(); body.Body.SetMass(jsonToFloat("massData-mass", bodyValue)); //massData.mass = ; body.Body.SetCenterOfGravity(jsonToVec("massData-center", bodyValue)); //massData.center =; //massData.I = jsonToFloat("massData-I", bodyValue); //body.SetMassData(massData); world.AddBody(body); return body; }
public static void CollisionSeparateCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world) { CCPhysicsContact contact = (CCPhysicsContact)(arb.data); if (contact != null) { world.CollisionSeparateCallback(contact); } //delete contact; }
//bool ignoreBodyRotation = false; #if USE_PHYSICS public PhysicsDebugDraw(CCPhysicsWorld world) { _world = world; _space = world.Info.Space; SelectFont("weblysleeku", 22); _world.Scene.AddChild(this); // getScene().addChild(_drawNode); }
public CCPointQueryCallbackInfo(CCPhysicsWorld w, Func <CCPhysicsWorld, CCPhysicsShape, object, bool> f, object d) { World = w; Function = f; Data = d; }