public override void update() { base.update(); if (Parent.tool == this) { RigidBody body; JVector normal; float frac; bool result = Scene.world.CollisionSystem.Raycast(GenericMethods.FromOpenTKVector(Position), GenericMethods.FromOpenTKVector(PointingDirection), raycastCallback, out body, out normal, out frac); Vector3 hitCoords = Position + PointingDirection * frac; if (result && ghost != null) { float smoothness = 0.9f; //Matrix4 newOri = Matrix4.Mult(Matrix4.CreateRotationX((float)Math.PI / 2), Conversion.MatrixFromVector(normal)); Matrix4 newOri = GenericMethods.MatrixFromVector(normal); Vector3 newPos = hitCoords; ghost.Position = smoothness * ghost.Position + (1 - smoothness) * newPos; //ghost.updateModelMatrix(); } ghost.isVisible = true; } else { ghost.isVisible = false; } }
public override void update() { base.update(); if (Parent.tool == this) { arcModel.Position = weaponModel.Position; //arcModel.Position2 = weaponModel.Position; muzzleModel.Position = weaponModel.Position; muzzleModel.Orientation = weaponModel.Orientation; arcModel.Orientation = weaponModel.Orientation; arcModel.Orientation2 = weaponModel.Orientation; // moving model if (selectedMod != null) { JVector anchorCoords = GenericMethods.FromOpenTKVector(Position + PointingDirection * grabDist); if (mConst != null) { mConst.Anchor = anchorCoords; } else if (selectedBody.IsStatic) { selectedBody.Position = anchorCoords + selModRelPos; } selectedMod.updateMatrix(); Matrix4 globalMaker = Matrix4.Mult(selectedMod.Orientation, selectedMod.ModelMatrix); Vector4 gpos = GenericMethods.Mult(modelLocalHitCoords, globalMaker); JVector hitCoords = GenericMethods.FromOpenTKVector(gpos.Xyz); //weaponLocalHitCoords = GenericMethods.Mult(gpos, Matrix4.Invert(Parent.viewInfo.modelviewMatrix)).Xyz; //arcModel.Position2 = GenericMethods.Mult(new Vector4(weaponLocalHitCoords - new Vector3(0, 0, 5), 1f), Matrix4.Invert(Parent.viewInfo.modelviewMatrix)).Xyz; arcModel.Position2 = gpos.Xyz - 5 * Parent.viewInfo.PointingDirection; //arcModel.Orientation2 = Matrix4.CreateTranslation(weaponLocalHitCoords - new Vector3(0, 0, -5)); } } else { arcModel.isVisible = false; muzzleModel.isVisible = false; if (selectedMod != null) { //mConst.Body1.AffectedByGravity = true; if (mConst != null) { Scene.world.RemoveConstraint(mConst); } selectedBody = null; selectedMod.selected = 0; selectedMod.Forceupdate = false; selectedMod = null; mConst = null; } } }
protected override void fireDown() { RigidBody body; JVector normal; float frac; bool result = Scene.world.CollisionSystem.Raycast(GenericMethods.FromOpenTKVector(Position), GenericMethods.FromOpenTKVector(PointingDirection), raycastCallback, out body, out normal, out frac); Vector4 gpos = new Vector4(Position + PointingDirection * frac, 1); JVector hitCoords = GenericMethods.FromOpenTKVector(gpos.Xyz); weaponLocalHitCoords = GenericMethods.Mult(gpos, Matrix4.Invert(weaponModel.ModelMatrix)).Xyz; arcModel.Orientation2 = Matrix4.CreateTranslation(weaponLocalHitCoords - new Vector3(0, 0, -5)); muzzleModel.isVisible = true; if (result && body.Tag != null) { PhysModel curMod = (PhysModel)body.Tag; if (curMod.grabable) { arcModel.isVisible = true; grabDist = frac; selectedBody = body; selectedMod = (PhysModel)body.Tag; selectedMod.selected = 1; selectedMod.Forceupdate = true; Matrix4 localMaker = Matrix4.Invert(Matrix4.Mult(selectedMod.Orientation, selectedMod.ModelMatrix)); modelLocalHitCoords = GenericMethods.Mult(gpos, localMaker); if (body.IsStatic) { selModRelPos = body.Position - hitCoords; } else { JVector lanchor = hitCoords - body.Position; lanchor = JVector.Transform(lanchor, JMatrix.Transpose(body.Orientation)); body.IsActive = true; //body.SetMassProperties(JMatrix.Identity, 0.1f, false); //body.AffectedByGravity = false; mConst = new Jitter.Dynamics.Constraints.SingleBody.PointOnPoint(body, lanchor); mConst.Softness = 0.02f; mConst.BiasFactor = 0.1f; Scene.world.AddConstraint(mConst); } } } }
public void setPhysMesh(Shape newShape) { RigidBody newBody = new RigidBody(newShape); newBody.Position = GenericMethods.FromOpenTKVector(Position); newBody.Mass = 20f; newBody.Tag = this; newBody.Orientation = GenericMethods.FromOpenTKMatrix(Orientation); Body = newBody; Scene.world.AddBody(newBody); }
protected override void fireDown() { RigidBody body; JVector normal; float frac; bool result = Scene.world.CollisionSystem.Raycast(GenericMethods.FromOpenTKVector(Position), GenericMethods.FromOpenTKVector(PointingDirection), raycastCallback, out body, out normal, out frac); muzzleModel.Color = new Vector4(0.8f, 0.3f, 0.8f, 1.0f) * 2; if (body != null) { PhysModel selectedMod = (PhysModel)body.Tag; if (selectedMod != null) { selectedMod.dissolve(); } } }
protected override void interactDown() { if (selectedMod == null) { RigidBody body; JVector normal; float frac; bool result = Scene.world.CollisionSystem.Raycast(GenericMethods.FromOpenTKVector(Position), GenericMethods.FromOpenTKVector(PointingDirection), raycastCallback, out body, out normal, out frac); if (result && body.Tag != null) { PhysModel curMod = (PhysModel)body.Tag; if (curMod.grabable) { curMod.IsStatic = !curMod.IsStatic; curMod.selectedSmooth = 1; } } } }
public void movePlayer(Vector3 move) { RigidBody hitbody; JVector normal; float frac; bool result = Scene.world.CollisionSystem.Raycast(GenericMethods.FromOpenTKVector(Position), new JVector(0, -1f, 0), mRaycastCallback, out hitbody, out normal, out frac); //Console.WriteLine(frac); if (result && frac < 2.2f) { parent.Body.AddForce(GenericMethods.FromOpenTKVector(move.X * parent.fwdVec + parent.rightVec * move.Z)); if (move.Y > 0) { parent.Body.LinearVelocity = new JVector(parent.Body.LinearVelocity.X, 5, parent.Body.LinearVelocity.Z); } } else { parent.Body.AddForce(GenericMethods.FromOpenTKVector(move.X * parent.fwdVec + parent.rightVec * move.Z)); } }