private void objectFromTemplate() { PhysModel curModel; switch (template.useType) { case Template.UseType.Animated: curModel = new AnimatedModel(Scene); break; default: curModel = new PhysModel(Scene); break; } curModel.Materials = template.materials; curModel.Meshes = template.meshes; curModel.Position = ghost.Position; curModel.PhysBoxes = template.pmeshes; curModel.IsStatic = template.isStatic; curModel.Name = Scene.getUniqueName(); curModel.Orientation = ghost.Orientation; if (template.hasLight && Scene.lightCount < ShaderLoader.maxNoLights) { Light mLight = new LightSpot(curModel); mLight.Color = new Vector4(template.lightColor, 1); } }
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 fireUp() { 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); } } } }
protected void genericLoad(ref XmlTextReader reader, string type) { if (reader.Name == PhysModel.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") childname = reader.Value; } GameObject child = new PhysModel(this); child.Name = childname; child.load(ref reader, "pmodel"); } if (reader.Name == AnimatedModel.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") childname = reader.Value; } GameObject child = new AnimatedModel(this); child.Name = childname; child.load(ref reader, "animodel"); } if (reader.Name == MetaModel.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") childname = reader.Value; } GameObject child = new MetaModel(this); child.Name = childname; child.load(ref reader, "metamodel"); } if (reader.Name == LightSpot.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") childname = reader.Value; } GameObject child = new LightSpot(this); child.Name = childname; child.load(ref reader, "lamp"); } if (reader.Name == "position" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); Position = GenericMethods.VectorFromString(reader.Value); } if (reader.Name == "direction" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); PointingDirection = GenericMethods.VectorFromString(reader.Value); } if (reader.Name == "color" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); Color = new Vector4(GenericMethods.VectorFromString(reader.Value),1); } if (reader.Name == "rotation" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); Orientation = GenericMethods.ToOpenTKMatrix(GenericMethods.JMatrixFromString(reader.Value)); } }
private void objectFromTemplate() { PhysModel curModel = new PhysModel(Scene); curModel.Materials = template.materials; curModel.Meshes = template.meshes; curModel.Position = ghost.Position; curModel.PhysBoxes = template.pmeshes; curModel.IsStatic = template.isStatic; curModel.setName(Scene.getUniqueName()); curModel.Orientation = ghost.Orientation; if (template.hasLight && Scene.lightCount < ShaderLoader.maxNoLights) { Light mLight = new LightSpot(curModel); mLight.Color = new Vector4(template.lightColor, 1); } }