private GeometryNode ShootBullet; //Geometry for Bullet #endregion Fields #region Constructors public Bullet(Vector3 InitPos, PrimitiveModel BulletModel, Material Material, Vector3 DirBullet, MarkerNode grdMarkerNode) { //Create Bullet ShootBullet = new GeometryNode(); ShootBullet.Name = "ShootBullet" + ShootBullet.ID; ShootBullet.Model = BulletModel; ShootBullet.Material = Material; ShootBullet.Physics.Interactable = true; ShootBullet.Physics.Collidable = true; ShootBullet.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; ShootBullet.Physics.Mass = 60f; ShootBullet.Physics.MaterialName = "Bullet"; ShootBullet.AddToPhysicsEngine = true; // Assign the initial velocity to this shooting box ShootBullet.Physics.InitialLinearVelocity = new Vector3(DirBullet.X * 80, DirBullet.Y * 80, DirBullet.Z * 50); BulletTrans = new TransformNode(); BulletTrans.Translation = InitPos; grdMarkerNode.AddChild(BulletTrans); BulletTrans.AddChild(ShootBullet); //Normal asignament isvisible = true; //Agrego Segundo desde que se creo livetime = Convert.ToInt32(DateTime.Now.TimeOfDay.TotalSeconds) + BULLET_TIMELIVE; }
public List<TransformNode> getListTransformNodes(Object PtID, Object EqID) { //create Box GeometryNode boxNode = new GeometryNode("Box"); boxNode.Model = new Box(6); boxNode.Model.CastShadows = true; boxNode.Model.ReceiveShadows = true; Material boxMat = new Material(); boxMat.Diffuse = Color.Blue.ToVector4(); boxMat.Specular = Color.White.ToVector4(); boxMat.SpecularPower = 20; boxNode.Material = boxMat; TransformNode boxTrans = new TransformNode(); boxTrans.Translation = new Vector3(-35, -18, 8); boxTrans.AddChild(boxNode); //Create cylinder GeometryNode cylinderNode = new GeometryNode("Cylinder"); cylinderNode.Model = new Cylinder(3.5f, 3.5f, 10, 20); cylinderNode.Model.CastShadows = true; cylinderNode.Model.ReceiveShadows = true; Material cylinderMat = new Material(); cylinderMat.Diffuse = Color.Green.ToVector4(); cylinderMat.Specular = Color.White.ToVector4(); cylinderMat.SpecularPower = 20; cylinderNode.Material = cylinderMat; TransformNode cylinderTrans = new TransformNode(); cylinderTrans.Translation = new Vector3(35, -18, 8); cylinderTrans.AddChild(cylinderNode); List<TransformNode> nodes = new List<TransformNode>(); nodes.Add(boxTrans); nodes.Add(cylinderTrans); return nodes; }
public Item(string[] tokens) { Model m = (Model)loader.Load("", tokens[NAME]); m.CastShadows = true; Material defaultMaterial = new Material(); defaultMaterial.Diffuse = Color.White.ToVector4(); //new Vector4(0, 0.5f, 0, 1); defaultMaterial.Specular = Color.White.ToVector4(); defaultMaterial.SpecularPower = 10; build(m, tokens[NAME], defaultMaterial); this.Scale = new Vector3(float.Parse(tokens[Item.SCALE])); this.savedTokens = tokens; }
public static RaceCar AddRaceCar(Scene scene, TransformNode parentTrans) { TransformNode transNode = new TransformNode(); transNode.Translation = new Vector3(0, 10, 10); Material carMat = new Material(); carMat.Diffuse = Color.Pink.ToVector4(); carMat.Specular = Color.White.ToVector4(); carMat.SpecularPower = 10; GeometryNode carNode = new GeometryNode("Race Car"); carNode.Model = new Box(3, 1.0f, 2); carNode.Material = carMat; carNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; NewtonPhysics physicsEngine = (NewtonPhysics)scene.PhysicsEngine; RaceCar car = new RaceCar(carNode, physicsEngine); for (int i = 0; i < 4; i++) car.Tires[i] = CreateTire((TireID)Enum.ToObject(typeof(TireID), i), car.TireTransformNode[i], carNode, scene.PhysicsEngine.Gravity); car.Collidable = true; car.Interactable = true; carNode.Physics = car; carNode.Physics.NeverDeactivate = true; carNode.AddToPhysicsEngine = true; parentTrans.AddChild(transNode); transNode.AddChild(carNode); Newton.NewtonSetBodyLeaveWorldEvent(physicsEngine.NewtonWorld, car.LeaveWorldCallback); return car; }
public TransformNode getPatientNameNode(Object markerID) { if (markerID.Equals("PatientMarkerConfig.txt")) { GeometryNode sphereNode = new GeometryNode("Sphere"); sphereNode.Model = new Sphere(3.5f, 20, 20); sphereNode.Model.CastShadows = true; sphereNode.Model.ReceiveShadows = true; Material sphereMat = new Material(); sphereMat.Diffuse = Color.Red.ToVector4(); sphereMat.Specular = Color.White.ToVector4(); sphereMat.SpecularPower = 20; sphereNode.Material = sphereMat; //sphereNode.Physics.Interactable = false; TransformNode sphereTrans = new TransformNode(); sphereTrans.Translation = new Vector3(0, 0, 5); sphereTrans.AddChild(sphereNode); return sphereTrans; } return null; }
public Item(IModel model, string name, Material material) { build(model, name, material); }
private void createCorderBackground() { cornerPanelTransformNode = new TransformNode("Corner Panel Trans"); scene.RootNode.AddChild(cornerPanelTransformNode); cornerPanelNode = new GeometryNode("Corner Panel"); cornerPanelNode.Model = new TexturedLayer(new Vector2(250, 250));//new Box(300, 250, 1); cornerPanelTransformNode.AddChild(cornerPanelNode); cornerPanelTransformNode.Translation = new Vector3(2.3f, -1.58f, -5); cornerPanelTransformNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(90)); //cornerPanelTransformNode.Translation = new Vector3(0, .06f, -1); cornerPanelTransformNode.Scale = new Vector3(0.005f, 0.005f, 0.005f); Material pointerLabelMaterial = new Material(); pointerLabelMaterial.Diffuse = Color.White.ToVector4(); ;// new Vector4(0, 0.5f, 0, 1); // pointerLabelMaterial.Specular = Color.White.ToVector4(); // pointerLabelMaterial.SpecularPower = 50; pointerLabelMaterial.Texture = Content.Load<Texture2D>("hud/cornerPanel"); cornerPanelNode.Material = pointerLabelMaterial; //cornerPanelTransformNode.SetAlpha(0.55f); Vector4 tempColor = cornerPanelNode.Material.Diffuse; Vector3 tempVec = new Vector3(tempColor.X, tempColor.Y, tempColor.Z); cornerPanelNode.Material.Diffuse = new Vector4(tempVec, 0.7f); }
private void CreateObject() { // Loads a textured model of a ship ModelLoader loader = new ModelLoader(); Model shipModel = (Model)loader.Load("", "p1_wedge"); // Create a geometry node of a loaded ship model GeometryNode shipNode = new GeometryNode("Ship"); shipNode.Model = shipModel; ((Model)shipNode.Model).UseInternalMaterials = true; // Create a transform node to define the transformation for the ship TransformNode shipTransNode = new TransformNode(); shipTransNode.Translation = new Vector3(0, 0, -50); shipTransNode.Scale = new Vector3(0.01f, 0.01f, 0.01f); // It's huge! shipTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), MathHelper.ToRadians(90)); shipTransParentNode = new TransformNode(); shipTransParentNode.Translation = Vector3.Zero; // Create a geometry node with model of a torus GeometryNode torusNode = new GeometryNode("Torus"); torusNode.Model = new Torus(12f, 15.5f, 20, 20); TransformNode torusTransNode = new TransformNode(); torusTransNode.Translation = new Vector3(-50, 0, 0); torusTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(90)); // Create a material node for this torus model Material torusMaterial = new Material(); torusMaterial.Diffuse = Color.DarkGoldenrod.ToVector4(); torusMaterial.Specular = Color.White.ToVector4(); torusMaterial.SpecularPower = 5; torusNode.Material = torusMaterial; // Now add the above nodes to the scene graph in appropriate order scene.RootNode.AddChild(shipTransParentNode); shipTransParentNode.AddChild(shipTransNode); shipTransNode.AddChild(shipNode); scene.RootNode.AddChild(torusTransNode); torusTransNode.AddChild(torusNode); // Now create couple of particle effects to attach to the models // Create a smoke particle effect and fire particle effect to simulate a // ring of fire around the torus model #if WINDOWS_PHONE SmokePlumeParticleEffect smokeParticles = new SmokePlumeParticleEffect(20, spriteBatch); FireParticleEffect fireParticles = new FireParticleEffect(40, spriteBatch); #else SmokePlumeParticleEffect smokeParticles = new SmokePlumeParticleEffect(); FireParticleEffect fireParticles = new FireParticleEffect(); // The order defines which particle effect to render first. Since we want // to show the fire particles in front of the smoke particles, we make // the smoke particles to be rendered first, and then fire particles smokeParticles.DrawOrder = 200; fireParticles.DrawOrder = 300; #endif // Create a particle node to hold these two particle effects ParticleNode fireRingEffectNode = new ParticleNode(); fireRingEffectNode.ParticleEffects.Add(smokeParticles); fireRingEffectNode.ParticleEffects.Add(fireParticles); // Implement an update handler for each of the particle effects which will be called // every "Update" call fireRingEffectNode.UpdateHandler += new ParticleUpdateHandler(UpdateRingOfFire); torusNode.AddChild(fireRingEffectNode); // Create another set of fire and smoke particle effects to simulate the fire // the ship catches when the ship passes the ring of fire #if WINDOWS_PHONE FireParticleEffect shipFireEffect = new FireParticleEffect(150, spriteBatch); SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect(80, spriteBatch); shipFireEffect.MinScale *= 1.5f; shipFireEffect.MaxScale *= 1.5f; #else FireParticleEffect shipFireEffect = new FireParticleEffect(); SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect(); shipSmokeEffect.DrawOrder = 400; shipFireEffect.DrawOrder = 500; #endif ParticleNode shipFireNode = new ParticleNode(); shipFireNode.ParticleEffects.Add(shipFireEffect); shipFireNode.ParticleEffects.Add(shipSmokeEffect); shipFireNode.UpdateHandler += new ParticleUpdateHandler(UpdateShipFire); shipNode.AddChild(shipFireNode); }
private void build(IModel model, string name, Material material) { build(model, name); //geo.Material = material; ((Model)geo.Model).UseInternalMaterials = true; }
TransformNode parentTNodeGrd; //Parent for all Scene Objects #endregion Fields #region Constructors public Graphics3D(MarkerNode MarkerNode, IShadowMap ShadowMap) { //Asignation Ground Node this.groundMarkerNode = MarkerNode; //Asignation Shadow Map this.GShadowMap = ShadowMap; //Add Big Parent for All Scenary Elements parentTNodeGrd = new TransformNode(); parentTNodeGrd.Name = "Level"; groundMarkerNode.AddChild(parentTNodeGrd); // Create a material for the model BulletrMat = new Material(); BulletrMat.Diffuse = Color.Blue.ToVector4(); BulletrMat.Specular = Color.White.ToVector4(); BulletrMat.SpecularPower = 10; //create Bullet Model BulletModel = new TexturedBox(2.0f); LoadLevel = false; LoadCars = false; }
/// <summary> /// Renders the model itself as well as the minimum bounding box if showBoundingBox /// is true. By default, SimpleEffectShader is used to render the model. /// </summary> /// <remarks> /// This function is called automatically to render the model, so do not call this method /// </remarks> /// <param name="material">Material properties of this model</param> /// <param name="renderMatrix">Transform of this model</param> public virtual void Render(ref Matrix renderMatrix, Material material) { if (!UseInternalMaterials) { material.InternalEffect = null; if ((shader.CurrentMaterial != material) || material.HasChanged) { shader.SetParameters(material); foreach (IShader afterEffect in afterEffectShaders) afterEffect.SetParameters(material); material.HasChanged = false; } } BlendState origState = null; if (ContainsTransparency) { origState = State.Device.BlendState; State.AlphaBlendingEnabled = true; } // Render the actual model foreach (ModelMesh modelMesh in this.mesh) { Matrix.Multiply(ref transforms[modelMesh.ParentBone.Index], ref renderMatrix, out tmpMat1); if (animationTransforms.Count > 0 && animationTransforms.ContainsKey(modelMesh.Name)) tmpMat1 = animationTransforms[modelMesh.Name] * tmpMat1; foreach (ModelMeshPart part in modelMesh.MeshParts) { if (UseInternalMaterials) { material.InternalEffect = part.Effect; shader.SetParameters(material); } String techniqueName = technique; if (String.IsNullOrEmpty(techniqueName)) techniqueName = part.Effect.CurrentTechnique.Name; curPart = part; shader.Render( ref tmpMat1, techniqueName, SubmitGeometry); foreach (IShader afterEffect in afterEffectShaders) { if (UseInternalMaterials) afterEffect.SetParameters(material); afterEffect.Render( ref tmpMat1, "", ResubmitGeometry); } } } shader.RenderEnd(); foreach (IShader afterEffect in afterEffectShaders) afterEffect.RenderEnd(); if (ContainsTransparency) State.Device.BlendState = origState; if (showBoundingBox) RenderBoundingBox(ref renderMatrix); }
public static void AddRollingBeats(Scene scene, TransformNode parentTrans) { Vector3 size = new Vector3(10.0f, 0.25f, 0.25f); Vector3 location = new Vector3(0, 3, 3); GeometryNode bar; // ////////////////////////////////////////////////////////////////// // // Create a bar and attach it to the world with a hinge with limits // // ////////////////////////////////////////////////////////////////// { TransformNode pileTrans = new TransformNode(); pileTrans.Translation = location; pileTrans.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.PiOver2); Material barMat = new Material(); barMat.Diffuse = Color.Purple.ToVector4(); barMat.Specular = Color.White.ToVector4(); barMat.SpecularPower = 10; bar = new GeometryNode("Bar"); bar.Model = new Cylinder(size.Y, size.Y, size.X, 20); bar.Material = barMat; bar.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; bar.AddToPhysicsEngine = true; bar.Physics.Interactable = true; bar.Physics.Collidable = true; bar.Physics.Shape = ShapeType.Cylinder; bar.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(bar); Vector3 pivot = location + parentTrans.Translation; Vector3 pin = Vector3.UnitY; pivot.X -= size.X * 0.5f; HingeJoint joint = new HingeJoint(pivot, pin); joint.NewtonHingeCallback = doubleDoor; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(bar.Physics, null, joint); } // ///////////////////////////////////////////////////////////////// // // Add a sliding visualObject with limits // //////////////////////////////////////////////////////////////////// { Vector3 beatLocation = location; Vector3 beatSize = new Vector3(0.5f, 2.0f, 2.0f); beatLocation.X += size.X * 0.25f; TransformNode pileTrans = new TransformNode(); pileTrans.Translation = beatLocation; Material beatMat = new Material(); beatMat.Diffuse = Color.Red.ToVector4(); beatMat.Specular = Color.White.ToVector4(); beatMat.SpecularPower = 10; GeometryNode beat = new GeometryNode("Beat Slider"); beat.Model = new Box(beatSize); beat.Material = beatMat; beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; beat.AddToPhysicsEngine = true; beat.Physics.Interactable = true; beat.Physics.Collidable = true; beat.Physics.Shape = ShapeType.Box; beat.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(beat); Vector3 pivot = beatLocation + parentTrans.Translation; Vector3 pin = Vector3.UnitX; sliderLimit.X = ((location.X - beatLocation.X) - size.X * 0.5f); sliderLimit.Y = ((location.X - beatLocation.X) + size.X * 0.5f); SliderJoint joint = new SliderJoint(pivot, pin); sliderUpdate = delegate(IntPtr slider, ref Newton.NewtonHingeSliderUpdateDesc desc) { float distance = Newton.NewtonSliderGetJointPosit(slider); if (distance < sliderLimit.X) { // if the distance is smaller than the predefine interval, stop the slider desc.m_Accel = Newton.NewtonSliderCalculateStopAccel(slider, ref desc, sliderLimit.X); return 1; } else if (distance > sliderLimit.Y) { // if the distance is larger than the predefine interval, stop the slider desc.m_Accel = Newton.NewtonSliderCalculateStopAccel(slider, ref desc, sliderLimit.Y); return 1; } // no action need it if the joint angle is with the limits return 0; }; joint.NewtonSliderCallback = sliderUpdate; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint); } // ///////////////////////////////////////////////////////////////// // // Add a corkscrew visualObject with limits // // ///////////////////////////////////////////////////////////////// { Vector3 beatLocation = location; Vector3 beatSize = new Vector3(0.5f, 2.0f, 2.0f); beatLocation.X -= size.X * 0.25f; TransformNode pileTrans = new TransformNode(); pileTrans.Translation = beatLocation; Material beatMat = new Material(); beatMat.Diffuse = Color.YellowGreen.ToVector4(); beatMat.Specular = Color.White.ToVector4(); beatMat.SpecularPower = 10; GeometryNode beat = new GeometryNode("Beat Corkscrew"); beat.Model = new Box(beatSize); beat.Material = beatMat; beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; beat.AddToPhysicsEngine = true; beat.Physics.Interactable = true; beat.Physics.Collidable = true; beat.Physics.Shape = ShapeType.Box; beat.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(beat); Vector3 pivot = beatLocation + parentTrans.Translation; Vector3 pin = Vector3.UnitX; corkscrewLimit.X = ((location.X - beatLocation.X) - size.X * 0.5f); corkscrewLimit.Y = ((location.X - beatLocation.X) + size.X * 0.5f); CorkscrewJoint joint = new CorkscrewJoint(pivot, pin); corkscrewUpdate = delegate(IntPtr corkscrew, Newton.NewtonHingeSliderUpdateDesc[] desc) { // no action need it if the joint angle is with the limits uint retCode = 0; float distance = Newton.NewtonCorkscrewGetJointPosit(corkscrew); // The first entry in NewtonHingeSliderUpdateDesc control the screw linear acceleration if (distance < corkscrewLimit.X) { // if the distance is smaller than the predefine interval, stop the slider desc[0].m_Accel = Newton.NewtonCorkscrewCalculateStopAccel(corkscrew, ref desc[0], corkscrewLimit.X); retCode |= 1; } else if (distance > corkscrewLimit.Y) { // if the distance is larger than the predefine interval, stop the slider desc[0].m_Accel = Newton.NewtonCorkscrewCalculateStopAccel(corkscrew, ref desc[0], corkscrewLimit.Y); retCode |= 1; } // The second entry in NewtonHingeSliderUpdateDesc control the screw angular acceleration. // Make s small screw motor by setting the angular acceleration of the screw axis // We are not going to limit the angular rotation of the screw, but is we did we should // or return code with 2 float omega = Newton.NewtonCorkscrewGetJointOmega(corkscrew); desc[1].m_Accel = 1.5f - 0.2f * omega; // or with 0x10 to tell newton this axis is active retCode |= 2; // return the code return retCode; }; joint.NewtonCorkscrewCallback = corkscrewUpdate; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint); } // ///////////////////////////////////////////////////////////////// // // Add a universal joint visualObject with limits // // ///////////////////////////////////////////////////////////////// { Vector3 beatLocation = location; Vector3 beatSize = new Vector3(0.5f, 2.0f, 2.0f); beatLocation.X -= size.X * 0.45f; TransformNode pileTrans = new TransformNode(); pileTrans.Translation = beatLocation; Material beatMat = new Material(); beatMat.Diffuse = Color.YellowGreen.ToVector4(); beatMat.Specular = Color.White.ToVector4(); beatMat.SpecularPower = 10; GeometryNode beat = new GeometryNode("Beat Universal"); beat.Model = new Box(beatSize); beat.Material = beatMat; beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; beat.AddToPhysicsEngine = true; beat.Physics.Interactable = true; beat.Physics.Collidable = true; beat.Physics.Shape = ShapeType.Box; beat.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(beat); Vector3 pivot = beatLocation + parentTrans.Translation; Vector3 pin0 = Vector3.UnitX; Vector3 pin1 = Vector3.UnitY; universalLimit.X = -30.0f * MathHelper.Pi / 180.0f; universalLimit.Y = 30.0f * MathHelper.Pi / 180.0f; UniversalJoint joint = new UniversalJoint(pivot, pin0, pin1); universalUpdate = delegate(IntPtr universal, Newton.NewtonHingeSliderUpdateDesc[] desc) { // no action need it if the joint angle is with the limits uint retCode = 0; float omega = Newton.NewtonUniversalGetJointOmega0(universal); desc[0].m_Accel = -1.5f - 0.2f * omega; retCode |= 1; float angle = Newton.NewtonUniversalGetJointAngle1(universal); if (angle < universalLimit.X) { desc[1].m_Accel = Newton.NewtonUniversalCalculateStopAlpha1(universal, ref desc[1], universalLimit.X); retCode |= 2; } else if (angle > universalLimit.Y) { desc[1].m_Accel = Newton.NewtonUniversalCalculateStopAlpha1(universal, ref desc[1], universalLimit.Y); retCode |= 2; } // return the code return retCode; }; joint.NewtonUniversalCallback = universalUpdate; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint); } }
/********************* Basic Elements ****************/ public GeometryNode CreateCube(MarkerNode Marker, Vector4 CubeColor) { GeometryNode boxNode; // Create a geometry node with a model of a box boxNode = new GeometryNode("Box"); boxNode.Model = new TexturedBox(32.4f); // Add this box model to the physics engine for collision detection boxNode.AddToPhysicsEngine = true; boxNode.Physics.Shape = ShapeType.Box; // Make this box model cast and receive shadows boxNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene boxNode.Model.Shader = new SimpleShadowShader(GShadowMap); // Create a material to apply to the box model Material boxMaterial = new Material(); boxMaterial.Diffuse = CubeColor; boxMaterial.Specular = Color.White.ToVector4(); boxMaterial.SpecularPower = 10; boxNode.Material = boxMaterial; // Add this box model node to the ground marker node Marker.AddChild(boxNode); return boxNode; // Create a collision pair and add a collision callback function that will be // called when the pair collides //NewtonPhysics.CollisionPair pair = new NewtonPhysics.CollisionPair(boxNode.Physics, sphereNode.Physics); //((NewtonPhysics)scene.PhysicsEngine).AddCollisionCallback(pair, BoxSphereCollision); }
/// <summary> /// Creates a rope-like object by connecting several ball and socket joints. /// </summary> /// <param name="scene"></param> /// <param name="parentTrans"></param> public static void AddRope(Scene scene, TransformNode parentTrans) { Vector3 size = new Vector3(1.5f, 0.25f, 0.25f); Vector3 location = new Vector3(0, 9, 0); IPhysicsObject link0 = null; Color[] colors = {Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet}; PrimitiveModel capsule = new Capsule(size.Y, size.X, 12); for (int i = 0; i < 7; i++) { TransformNode pileTrans = new TransformNode(); pileTrans.Translation = location; Material linkMat = new Material(); linkMat.Diffuse = colors[i].ToVector4(); linkMat.Specular = Color.White.ToVector4(); linkMat.SpecularPower = 10; GeometryNode link1 = new GeometryNode("Link " + i); link1.Model = capsule; link1.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; link1.Material = linkMat; link1.AddToPhysicsEngine = true; link1.Physics.Interactable = true; link1.Physics.Collidable = true; link1.Physics.Shape = ShapeType.Capsule; link1.Physics.Mass = 2.0f; link1.Physics.LinearDamping = 1f; link1.Physics.AngularDamping = new Vector3(1f, 1f, 1f); parentTrans.AddChild(pileTrans); pileTrans.AddChild(link1); Vector3 pivot = location + parentTrans.Translation; pivot.Y += (size.X - size.Y) * 0.5f; BallAndSocketJoint joint = new BallAndSocketJoint(pivot); joint.Pin = -Vector3.UnitY; joint.MaxConeAngle = 0.0f; joint.MaxTwistAngle = 10.0f * MathHelper.Pi / 180; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link1.Physics, link0, joint); link0 = link1.Physics; location = new Vector3(location.X, location.Y - (size.X - size.Y), location.Z); } }
public static void AddDoubleSwingDoors(Scene scene, TransformNode parentTrans) { Vector3 size = new Vector3(2.0f, 5.0f, 0.5f); Vector3 location = new Vector3(0, 3.5f, -3); Material linkMat = new Material(); linkMat.Diffuse = Color.Cyan.ToVector4(); linkMat.Specular = Color.White.ToVector4(); linkMat.SpecularPower = 10; GeometryNode link1 = null; // Make first wing { TransformNode pileTrans = new TransformNode(); pileTrans.Translation = location; link1 = new GeometryNode("Door 1"); link1.Model = new Box(size.X, size.Y, size.Z); link1.Material = linkMat; link1.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; link1.AddToPhysicsEngine = true; link1.Physics.Interactable = true; link1.Physics.Collidable = true; link1.Physics.Shape = ShapeType.Box; link1.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(link1); Vector3 pivot = location + parentTrans.Translation; Vector3 pin = Vector3.UnitY; pivot.X += size.X * 0.5f; pivot.Y -= size.Y * 0.5f; HingeJoint joint = new HingeJoint(pivot, pin); joint.NewtonHingeCallback = doubleDoor; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link1.Physics, null, joint); } // Make second wing { location.X -= size.X; TransformNode pileTrans = new TransformNode(); pileTrans.Translation = location; GeometryNode link2 = new GeometryNode("Door 2"); link2.Model = new Box(size.X, size.Y, size.Z); link2.Material = linkMat; link2.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; link2.AddToPhysicsEngine = true; link2.Physics.Interactable = true; link2.Physics.Collidable = true; link2.Physics.Shape = ShapeType.Box; link2.Physics.Mass = 2.0f; parentTrans.AddChild(pileTrans); pileTrans.AddChild(link2); Vector3 pivot = location + parentTrans.Translation; Vector3 pin = Vector3.UnitY; pivot.X += size.X * 0.5f; pivot.Y -= size.Y * 0.5f; HingeJoint joint = new HingeJoint(pivot, pin); joint.NewtonHingeCallback = doubleDoor; ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link2.Physics, link1.Physics, joint); } }
private void CreateObjects() { // Create a sphere geometry { GeometryNode sphereNode = new GeometryNode("Sphere"); sphereNode.Model = new TexturedSphere(14, 20, 20); sphereNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; sphereNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); Material sphereMat = new Material(); sphereMat.Diffuse = Color.Red.ToVector4(); sphereMat.Specular = Color.White.ToVector4(); sphereMat.SpecularPower = 20; sphereNode.Material = sphereMat; TransformNode sphereTrans = new TransformNode(); sphereTrans.Translation = new Vector3(0, 0, 20); groundMarkerNode.AddChild(sphereTrans); sphereTrans.AddChild(sphereNode); } // Create a box geometry { GeometryNode boxNode = new GeometryNode("Box"); boxNode.Model = new TexturedBox(24); boxNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; boxNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); Material boxMat = new Material(); boxMat.Diffuse = Color.Blue.ToVector4(); boxMat.Specular = Color.White.ToVector4(); boxMat.SpecularPower = 20; boxNode.Material = boxMat; TransformNode boxTrans = new TransformNode(); boxTrans.Translation = new Vector3(-140, -72, 32); groundMarkerNode.AddChild(boxTrans); boxTrans.AddChild(boxNode); } // Create a cylinder geometry { GeometryNode cylinderNode = new GeometryNode("Cylinder"); cylinderNode.Model = new Cylinder(14, 14, 10, 20); cylinderNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; Material cylinderMat = new Material(); cylinderMat.Diffuse = Color.Green.ToVector4(); cylinderMat.Specular = Color.White.ToVector4(); cylinderMat.SpecularPower = 20; cylinderNode.Material = cylinderMat; TransformNode cylinderTrans = new TransformNode(); cylinderTrans.Translation = new Vector3(140, -72, 32); groundMarkerNode.AddChild(cylinderTrans); cylinderTrans.AddChild(cylinderNode); } // Create a torus geometry { GeometryNode torusNode = new GeometryNode("Torus"); torusNode.Model = new Torus(10, 24, 20, 20); torusNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; Material torusMat = new Material(); torusMat.Diffuse = Color.Yellow.ToVector4(); torusMat.Specular = Color.White.ToVector4(); torusMat.SpecularPower = 20; torusNode.Material = torusMat; TransformNode torusTrans = new TransformNode(); torusTrans.Translation = new Vector3(-140, 72, 32); groundMarkerNode.AddChild(torusTrans); torusTrans.AddChild(torusNode); } // Create a capsule geometry { GeometryNode capsuleNode = new GeometryNode("Capsule"); capsuleNode.Model = new Capsule(12, 48, 20); capsuleNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; Material capsuleMat = new Material(); capsuleMat.Diffuse = Color.Cyan.ToVector4(); capsuleMat.Specular = Color.White.ToVector4(); capsuleMat.SpecularPower = 20; capsuleNode.Material = capsuleMat; TransformNode capsuleTrans = new TransformNode(); capsuleTrans.Translation = new Vector3(140, 72, 32); groundMarkerNode.AddChild(capsuleTrans); capsuleTrans.AddChild(capsuleNode); } }
private void CreateGround() { GeometryNode groundNode = new GeometryNode("Ground"); groundNode.Model = new TexturedBox(340, 200, 0.1f); // Set this ground model to act as an occluder so that it appears transparent groundNode.IsOccluder = true; // Make the ground model to receive shadow casted by other objects with // CastShadows set to true groundNode.Model.ShadowAttribute = ShadowAttribute.ReceiveOnly; groundNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); Material groundMaterial = new Material(); groundMaterial.Diffuse = new Vector4(0.5f, 0.5f, 0.5f, 0.5f); groundMaterial.Specular = Color.White.ToVector4(); groundMaterial.SpecularPower = 20; groundNode.Material = groundMaterial; groundMarkerNode.AddChild(groundNode); }
private void CreateObject() { // Create a primitive mesh for creating our custom pyramid shape CustomMesh pyramid = new CustomMesh(); // Even though we really need 5 vertices to create a pyramid shape, since // we want to assign different normals for points with same position to have // more accurate lighting effect, we will use 16 vertices. // Also, we want to have position, normal, and texture information in our // vertices, we'll use VertexPositionNormalTexture format. There are other // types of Vertex format as well depending on your needs. VertexPositionNormalTexture[] verts = new VertexPositionNormalTexture[16]; // Create a pyramid with 8x8 base and height of 6 Vector3 vBase0 = new Vector3(-4, 0, 4); Vector3 vBase1 = new Vector3(4, 0, 4); Vector3 vBase2 = new Vector3(4, 0, -4); Vector3 vBase3 = new Vector3(-4, 0, -4); Vector3 vTop = new Vector3(0, 6, 0); verts[0].Position = vTop; verts[1].Position = vBase1; verts[2].Position = vBase0; verts[3].Position = vTop; verts[4].Position = vBase2; verts[5].Position = vBase1; verts[6].Position = vTop; verts[7].Position = vBase3; verts[8].Position = vBase2; verts[9].Position = vTop; verts[10].Position = vBase0; verts[11].Position = vBase3; verts[12].Position = vBase0; verts[13].Position = vBase1; verts[14].Position = vBase2; verts[15].Position = vBase3; verts[0].Normal = verts[1].Normal = verts[2].Normal = CalcNormal(vTop, vBase1, vBase0); verts[3].Normal = verts[4].Normal = verts[5].Normal = CalcNormal(vTop, vBase2, vBase1); verts[6].Normal = verts[7].Normal = verts[8].Normal = CalcNormal(vTop, vBase3, vBase2); verts[9].Normal = verts[10].Normal = verts[11].Normal = CalcNormal(vTop, vBase0, vBase3); verts[12].Normal = verts[13].Normal = verts[14].Normal = verts[15].Normal = CalcNormal(vBase0, vBase1, vBase3); Vector2 texCoordTop = new Vector2(0.5f, 0); Vector2 texCoordLeftBase = new Vector2(0, 1); Vector2 texCoordRightBase = new Vector2(1, 1); verts[0].TextureCoordinate = texCoordTop; verts[1].TextureCoordinate = texCoordLeftBase; verts[2].TextureCoordinate = texCoordRightBase; verts[3].TextureCoordinate = texCoordTop; verts[4].TextureCoordinate = texCoordLeftBase; verts[5].TextureCoordinate = texCoordRightBase; verts[6].TextureCoordinate = texCoordTop; verts[7].TextureCoordinate = texCoordLeftBase; verts[8].TextureCoordinate = texCoordRightBase; verts[9].TextureCoordinate = texCoordTop; verts[10].TextureCoordinate = texCoordLeftBase; verts[11].TextureCoordinate = texCoordRightBase; verts[12].TextureCoordinate = new Vector2(1, 1); verts[13].TextureCoordinate = new Vector2(1, 0); verts[14].TextureCoordinate = new Vector2(0, 0); verts[15].TextureCoordinate = new Vector2(0, 1); pyramid.VertexBuffer = new VertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionNormalTexture), 16, BufferUsage.None); pyramid.VertexDeclaration = VertexPositionNormalTexture.VertexDeclaration; pyramid.VertexBuffer.SetData(verts); pyramid.NumberOfVertices = 16; short[] indices = new short[18]; indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 3; indices[4] = 4; indices[5] = 5; indices[6] = 6; indices[7] = 7; indices[8] = 8; indices[9] = 9; indices[10] = 10; indices[11] = 11; indices[12] = 12; indices[13] = 13; indices[14] = 15; indices[15] = 13; indices[16] = 14; indices[17] = 15; pyramid.IndexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(short), 18, BufferUsage.WriteOnly); pyramid.IndexBuffer.SetData(indices); pyramid.PrimitiveType = PrimitiveType.TriangleList; pyramid.NumberOfPrimitives = 6; PrimitiveModel pyramidModel = new PrimitiveModel(pyramid); GeometryNode pyramidNode = new GeometryNode(); pyramidNode.Model = pyramidModel; Material pyramidMaterial = new Material(); pyramidMaterial.Diffuse = Color.White.ToVector4(); pyramidMaterial.Specular = Color.White.ToVector4(); pyramidMaterial.SpecularPower = 10; pyramidMaterial.Texture = Content.Load<Texture2D>("brick_wall_14"); pyramidNode.Material = pyramidMaterial; scene.RootNode.AddChild(pyramidNode); }
public static void CreateBall(MarkerNode Marker) { // Create a geometry node for Sphere PrimitiveModel PsphereModel = new Sphere(15f, 20, 20); // Create a material to apply to the sphere model Material sphereMaterial = new Material(); sphereMaterial.Diffuse = new Vector4(0, 0.5f, 0, 1); sphereMaterial.Specular = Color.White.ToVector4(); sphereMaterial.SpecularPower = 10; GeometryNode sphereNode = new GeometryNode("Sphere"); //sphereNode.Model = new TexturedSphere(16, 20, 20); sphereNode.Model = PsphereModel; sphereNode.Material = sphereMaterial; // Add this sphere model to the physics engine for collision detection sphereNode.Physics.Interactable = true; sphereNode.Physics.Collidable = true; sphereNode.Physics.Shape = ShapeType.Sphere; sphereNode.Physics.Mass = 30; //sphereNode.Physics.ApplyGravity = false; sphereNode.Physics.InitialLinearVelocity = new Vector3(30, 0, 0); //sphereNode.Physics.MaterialName = "Sphere"; //sphereNode.Physics.ApplyGravity = true; sphereNode.AddToPhysicsEngine = true; // Make this sphere model cast and receive shadows //sphereNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene //sphereNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); TransformNode sphereTransNode = new TransformNode(); sphereTransNode.Translation = new Vector3(50, 0, 50); // Now add the above nodes to the scene graph in the appropriate order. // Note that only the nodes added below the marker node are affected by // the marker transformation. Marker.AddChild(sphereTransNode); sphereTransNode.AddChild(sphereNode); }
/// <summary> /// Renders the model itself as well as the minimum bounding box if showBoundingBox /// is true. By default, SimpleEffectShader is used to render the model. /// </summary> /// <remarks> /// This function is called automatically to render the model, so do not call this method /// </remarks> /// <param name="material">Material properties of this model</param> /// <param name="renderMatrix">Transform of this model</param> public override void Render(ref Matrix renderMatrix, Material material) { if (!UseInternalMaterials) { material.InternalEffect = null; if ((shader.CurrentMaterial != material) || material.HasChanged) { shader.SetParameters(material); foreach (IShader afterEffect in afterEffectShaders) afterEffect.SetParameters(material); material.HasChanged = false; } } // Render the actual model foreach (ModelMesh modelMesh in this.mesh) { Matrix.Multiply(ref transforms[modelMesh.ParentBone.Index], ref renderMatrix, out tmpMat1); if (UseInternalMaterials && (shader is IAlphaBlendable)) ((IAlphaBlendable)shader).SetOriginalAlphas(modelMesh.Effects); foreach (ModelMeshPart part in modelMesh.MeshParts) { if (UseInternalMaterials) { material.InternalEffect = part.Effect; shader.SetParameters(material); ((SkinnedModelShader)shader).UpdateBones(this.transforms); } shader.Render( ref tmpMat1, (UseInternalMaterials) ? part.Effect.CurrentTechnique.Name : technique, delegate { State.Device.SetVertexBuffer(part.VertexBuffer); State.Device.Indices = part.IndexBuffer; State.Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, part.VertexOffset, 0, part.NumVertices, part.StartIndex, part.PrimitiveCount); }); foreach (IShader afterEffect in afterEffectShaders) { if (UseInternalMaterials) afterEffect.SetParameters(material); afterEffect.Render( ref tmpMat1, "", delegate { State.Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, part.VertexOffset, 0, part.NumVertices, part.StartIndex, part.PrimitiveCount); }); } } } }
/********************* Helpers **********************/ public static GeometryNode LoadModel(string DirModel, string Modelname, bool InternalMaterial) { GeometryNode MyNode = new GeometryNode(Modelname); //Intento cargar un modelo ModelLoader loader = new ModelLoader(); MyNode.Physics.Mass = 20; MyNode.Physics.Shape = ShapeType.ConvexHull; MyNode.Physics.MaterialName = Modelname; MyNode.Physics.ApplyGravity = true; //Debo probar mas esta propiedad MyNode.Physics.NeverDeactivate = true; MyNode.AddToPhysicsEngine = true; //Load Model MyNode.Model = (Model)loader.Load(DirModel, Modelname); //Define Material if (InternalMaterial) { ((Model)MyNode.Model).UseInternalMaterials = true; } else { // Create a material for the Model Material ModelMat = new Material(); ModelMat.Diffuse = Color.Blue.ToVector4(); ModelMat.Specular = Color.White.ToVector4(); ModelMat.SpecularPower = 20; //Add Material MyNode.Material = ModelMat; } return MyNode; }
private void CreateObjects() { // Create a geometry node with a model of a sphere that will be overlaid on // top of the ground marker array GeometryNode sphereNode = new GeometryNode("Sphere"); // We will use TexturedSphere instead of regular Box class since we will need the // texture coordinates elements for passing the vertices to the SimpleShadowShader // we will be using sphereNode.Model = new TexturedSphere(16, 20, 20); // Add this sphere model to the physics engine for collision detection sphereNode.AddToPhysicsEngine = true; sphereNode.Physics.Shape = ShapeType.Sphere; // Make this sphere model cast and receive shadows sphereNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene sphereNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); // Create a marker node to track a ground marker array. #if USE_NYARTOOLKIT groundMarkerNode = new MarkerNode(scene.MarkerTracker, "NyARToolkitGroundArray.xml", NyARToolkitTracker.ComputationMethod.Average); #else groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARGroundArray.xml"); #endif TransformNode sphereTransNode = new TransformNode(); sphereTransNode.Translation = new Vector3(0, 0, 50); // Create a material to apply to the sphere model Material sphereMaterial = new Material(); sphereMaterial.Diffuse = new Vector4(0, 0.5f, 0, 1); sphereMaterial.Specular = Color.White.ToVector4(); sphereMaterial.SpecularPower = 10; sphereNode.Material = sphereMaterial; // Now add the above nodes to the scene graph in the appropriate order. // Note that only the nodes added below the marker node are affected by // the marker transformation. scene.RootNode.AddChild(groundMarkerNode); groundMarkerNode.AddChild(sphereTransNode); sphereTransNode.AddChild(sphereNode); // Create a geometry node with a model of a box that will be overlaid on // top of the ground marker array initially. (When the toolbar marker array is // detected, it will be overlaid on top of the toolbar marker array.) boxNode = new GeometryNode("Box"); // We will use TexturedBox instead of regular Box class since we will need the // texture coordinates elements for passing the vertices to the SimpleShadowShader // we will be using boxNode.Model = new TexturedBox(32.4f); // Add this box model to the physics engine for collision detection boxNode.AddToPhysicsEngine = true; boxNode.Physics.Shape = ShapeType.Box; // Make this box model cast and receive shadows boxNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast; // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene boxNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); // Create a marker node to track a toolbar marker array. #if USE_NYARTOOLKIT toolbarMarkerNode = new MarkerNode(scene.MarkerTracker, "ToolbarNyARToolkit.xml", NyARToolkitTracker.ComputationMethod.Average); #else toolbarMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARToolbar.xml"); #endif scene.RootNode.AddChild(toolbarMarkerNode); // Create a material to apply to the box model Material boxMaterial = new Material(); boxMaterial.Diffuse = new Vector4(0.5f, 0, 0, 1); boxMaterial.Specular = Color.White.ToVector4(); boxMaterial.SpecularPower = 10; boxNode.Material = boxMaterial; // Add this box model node to the ground marker node groundMarkerNode.AddChild(boxNode); // Create a collision pair and add a collision callback function that will be // called when the pair collides NewtonPhysics.CollisionPair pair = new NewtonPhysics.CollisionPair(boxNode.Physics, sphereNode.Physics); ((NewtonPhysics)scene.PhysicsEngine).AddCollisionCallback(pair, BoxSphereCollision); }
public void CreateGround(bool Occluder) { GeometryNode groundNode = new GeometryNode("Ground"); //Cordenates X, y, Z groundNode.Model = new TexturedBox(324, 180, 0.1f); // Set this model Occluded ist or not groundNode.IsOccluder = Occluder; //Setup Physics Aspecte groundNode.Physics.Collidable = true; groundNode.Physics.Shape = GoblinXNA.Physics.ShapeType.Box; groundNode.Physics.MaterialName = "Ground"; groundNode.AddToPhysicsEngine = true; // Make the ground model to receive shadow casted by other objects groundNode.Model.ShadowAttribute = ShadowAttribute.ReceiveOnly; // Assign a shadow shader groundNode.Model.Shader = new SimpleShadowShader(GShadowMap); //Material Material groundMaterial = new Material(); groundMaterial.Diffuse = Color.Gray.ToVector4(); groundMaterial.Specular = Color.White.ToVector4(); groundMaterial.SpecularPower = 20; //Assig Material groundNode.Material = groundMaterial; //Add Model in the Scene parentTNodeGrd.AddChild(groundNode); }
public override void SetParameters(Material material) { if (material.InternalEffect != null) { effect = material.InternalEffect; GetMinimumParameters(); cameraPosition.SetValue(cameraPos); defaultTechnique = "GeneralLightingWithTexture"; } else { emissiveColor.SetValue(material.Emissive); diffuseColor.SetValue(material.Diffuse); specularColor.SetValue(material.Specular); specularPower.SetValue(material.SpecularPower); if (material.HasTexture) { diffuseTexture.SetValue(material.Texture); defaultTechnique = "GeneralLightingWithTexture"; } else { defaultTechnique = "GeneralLighting"; } } }
public virtual void SetParameters(Material material) { if (material.InternalEffect != null) { if (material.InternalEffect is BasicEffect) { BasicEffect be = (BasicEffect)material.InternalEffect; hasTexture.SetValue(be.TextureEnabled); if(be.TextureEnabled) diffuseTexture.SetValue(be.Texture); Vector4 diffuse = new Vector4(be.DiffuseColor, be.Alpha); diffuseColor.SetValue(diffuse); Vector4 specular = new Vector4(be.SpecularColor, 1); specularColor.SetValue(specular); specularPower.SetValue(be.SpecularPower); } else Log.Write("Passed internal effect is not BasicEffect, so we can not apply the " + "effect to this shader", Log.LogLevel.Warning); } else { hasTexture.SetValue(material.HasTexture); if (material.HasTexture) diffuseTexture.SetValue(material.Texture); diffuseColor.SetValue(material.Diffuse); specularColor.SetValue(material.Specular); specularPower.SetValue(material.SpecularPower); } }
private List<Bullet> WBullets; //Bullets For Weapon #endregion Fields #region Constructors public Game_Weapon(PrimitiveModel BulletModel, Material BulletMaterial, MarkerNode GrdMarkerNode) { FOV = NORMAL_FOV; DeltaGiro = DELTA_THETA; Active = true; ActAngle = 0; InitAngle = 0; MaxAng = 360; RadActAngle = 0; GirDir = RotDirection.RECHS; RotaMode = RotMode.CONTINUE; this.BulletModel = BulletModel; BulletMat = BulletMaterial; GMarkerNode = GrdMarkerNode; WBullets = new List<Bullet>(); //Config type of Shoot WaitBullet = WAIT_SHOOT; CountToShoot = WaitBullet; ReloadTime = WAIT_RELOAD; CountToReload = 0; CountOfBullets = 0; NumBullets = Game_Logic.MAX_BULLET; RadOffset = Math.PI * (95) / 180.0; BulletOffset = new Vector3(0, 10, 30); }
private void CreateGround() { GeometryNode groundNode = new GeometryNode("Ground"); // We will use TexturedBox instead of regular Box class since we will need the // texture coordinates elements for passing the vertices to the SimpleShadowShader // we will be using groundNode.Model = new TexturedBox(324, 180, 0.1f); // Set this ground model to act as an occluder so that it appears transparent groundNode.IsOccluder = true; // Make the ground model to receive shadow casted by other objects with // ShadowAttribute.ReceiveCast groundNode.Model.ShadowAttribute = ShadowAttribute.ReceiveOnly; // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene groundNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap); Material groundMaterial = new Material(); groundMaterial.Diffuse = Color.Gray.ToVector4(); groundMaterial.Specular = Color.White.ToVector4(); groundMaterial.SpecularPower = 20; groundNode.Material = groundMaterial; groundMarkerNode.AddChild(groundNode); }
private void CreateGround() { GeometryNode groundNode = new GeometryNode("Ground"); #if USE_ARTAG groundNode.Model = new Box(85, 66, 0.1f); #else groundNode.Model = new Box(95, 59, 0.1f); #endif // Set this ground model to act as an occluder so that it appears transparent groundNode.IsOccluder = true; // Make the ground model to receive shadow casted by other objects with // CastShadows set to true groundNode.Model.ReceiveShadows = true; Material groundMaterial = new Material(); groundMaterial.Diffuse = new Vector4(0.5f, 0.5f, 0.5f, 0.5f); groundMaterial.Specular = Color.White.ToVector4(); groundMaterial.SpecularPower = 20; groundNode.Material = groundMaterial; groundMarkerNode.AddChild(groundNode); }
public void SetParameters(Material material) { if (material.InternalEffect != null) { if (material.InternalEffect is BasicEffect) { BasicEffect be = (BasicEffect)material.InternalEffect; alphaEffect.Alpha = be.Alpha; alphaEffect.DiffuseColor = be.DiffuseColor; alphaEffect.Texture = be.Texture; alphaEffect.VertexColorEnabled = be.VertexColorEnabled; } else Log.Write("Passed internal effect is not BasicEffect, so we can not apply the " + "effect to this shader", Log.LogLevel.Warning); } else { alphaEffect.Alpha = material.Diffuse.W; alphaEffect.DiffuseColor = Vector3Helper.GetVector3(material.Diffuse); alphaEffect.Texture = material.Texture; } }
private void CreateObjects() { // Create a sphere geometry { GeometryNode sphereNode = new GeometryNode("Sphere"); sphereNode.Model = new Sphere(3.5f, 20, 20); sphereNode.Model.CastShadows = true; sphereNode.Model.ReceiveShadows = true; Material sphereMat = new Material(); sphereMat.Diffuse = Color.Red.ToVector4(); sphereMat.Specular = Color.White.ToVector4(); sphereMat.SpecularPower = 20; sphereNode.Material = sphereMat; TransformNode sphereTrans = new TransformNode(); sphereTrans.Translation = new Vector3(0, 0, 5); groundMarkerNode.AddChild(sphereTrans); sphereTrans.AddChild(sphereNode); } // Create a box geometry { GeometryNode boxNode = new GeometryNode("Box"); boxNode.Model = new Box(6); boxNode.Model.CastShadows = true; boxNode.Model.ReceiveShadows = true; Material boxMat = new Material(); boxMat.Diffuse = Color.Blue.ToVector4(); boxMat.Specular = Color.White.ToVector4(); boxMat.SpecularPower = 20; boxNode.Material = boxMat; TransformNode boxTrans = new TransformNode(); boxTrans.Translation = new Vector3(-35, -18, 8); groundMarkerNode.AddChild(boxTrans); boxTrans.AddChild(boxNode); } // Create a cylinder geometry { GeometryNode cylinderNode = new GeometryNode("Cylinder"); cylinderNode.Model = new Cylinder(3.5f, 3.5f, 10, 20); cylinderNode.Model.CastShadows = true; cylinderNode.Model.ReceiveShadows = true; Material cylinderMat = new Material(); cylinderMat.Diffuse = Color.Green.ToVector4(); cylinderMat.Specular = Color.White.ToVector4(); cylinderMat.SpecularPower = 20; cylinderNode.Material = cylinderMat; TransformNode cylinderTrans = new TransformNode(); cylinderTrans.Translation = new Vector3(35, -18, 8); groundMarkerNode.AddChild(cylinderTrans); cylinderTrans.AddChild(cylinderNode); } // Create a torus geometry { GeometryNode torusNode = new GeometryNode("Torus"); torusNode.Model = new Torus(2.5f, 6.0f, 20, 20); torusNode.Model.CastShadows = true; torusNode.Model.ReceiveShadows = true; Material torusMat = new Material(); torusMat.Diffuse = Color.Yellow.ToVector4(); torusMat.Specular = Color.White.ToVector4(); torusMat.SpecularPower = 20; torusNode.Material = torusMat; TransformNode torusTrans = new TransformNode(); torusTrans.Translation = new Vector3(-35, 18, 8); groundMarkerNode.AddChild(torusTrans); torusTrans.AddChild(torusNode); } // Create a capsule geometry { GeometryNode capsuleNode = new GeometryNode("Capsule"); capsuleNode.Model = new Capsule(3, 12, 20); capsuleNode.Model.CastShadows = true; capsuleNode.Model.ReceiveShadows = true; Material capsuleMat = new Material(); capsuleMat.Diffuse = Color.Cyan.ToVector4(); capsuleMat.Specular = Color.White.ToVector4(); capsuleMat.SpecularPower = 20; capsuleNode.Material = capsuleMat; TransformNode capsuleTrans = new TransformNode(); capsuleTrans.Translation = new Vector3(35, 18, 8); groundMarkerNode.AddChild(capsuleTrans); capsuleTrans.AddChild(capsuleNode); } }