// I’ll draw anyone supporting IDraw3D. static void DrawIn3D( IDraw3D itf3d) { if(itf3d is IDraw3d) { Console.WriteLine("-> Drawing IDraw3D compatible type"); itf3d.Draw3D(); } }
// I’ll draw anyone supporting IDraw3D. static void DrawIn3D(IDraw3D itf3d) { if (itf3d is IDraw3d) { Console.WriteLine("-> Drawing IDraw3D compatible type"); itf3d.Draw3D(); } }
public static void Draw3D(IDraw3D drawMe, Camera2D camera) { Vector3 position = new Vector3(drawMe.Position.X * 100, -drawMe.Position.Y * 100, 0); Vector3 cameraPosition = new Vector3(camera.Position.X, -camera.Position.Y, 1000); Vector3 cameraTarget = new Vector3(cameraPosition.X, cameraPosition.Y, 0); // Copy any parent transforms. Matrix[] transforms = new Matrix[drawMe.DrawModel.Bones.Count]; drawMe.DrawModel.CopyAbsoluteBoneTransformsTo(transforms); // Draw the model. A model can have multiple meshes, so loop. foreach (ModelMesh mesh in drawMe.DrawModel.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); var modelMatrix = Matrix.Identity; modelMatrix *= Matrix.CreateScale(drawMe.DrawData.Scale); //Note: Be sure to normalize the matrices input into CreateFromAxisAngle, otherwise the rotation is scaled, which doesn't make sense conceptually, but is probably an optimization. modelMatrix *= Matrix.CreateFromAxisAngle(modelMatrix.Right / modelMatrix.Right.Length(), drawMe.DrawData.Pitch + drawMe.DrawData.PitchOffset); modelMatrix *= Matrix.CreateFromAxisAngle(modelMatrix.Forward / modelMatrix.Forward.Length(), drawMe.DrawData.Roll + drawMe.DrawData.RollOffset); modelMatrix *= Matrix.CreateFromAxisAngle(modelMatrix.Up / modelMatrix.Up.Length(), -drawMe.Rotation + drawMe.DrawData.YawOffset); modelMatrix *= Matrix.CreateTranslation(position); effect.World = modelMatrix; //As things are drawn now, the Z axis points into the screen. Not sure which direction is positive. //effect.World = Matrix.Identity * Matrix.CreateFromYawPitchRoll(drawMe.DrawData.Pitch + drawMe.DrawData.PitchOffset, drawMe.DrawData.Roll + drawMe.DrawData.RollOffset, -drawMe.Rotation + drawMe.DrawData.YawOffset) * Matrix.CreateTranslation(position); effect.View = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up) * Matrix.CreateScale(camera.Zoom) * Matrix.CreateRotationZ(camera.CameraAngle);//TODO: Not sure if CameraAngle needs a negative sign. If the ships shake in the opposite direction of the 2D assets, negate the angle. //effect.Projection = Matrix.CreatePerspective(MathHelper.ToRadians(45), aspectRatio, 1.0f, 10000.0f); effect.Projection = Matrix.CreateOrthographic(camera.GameWindow.ClientBounds.Width, camera.GameWindow.ClientBounds.Height, 100, 10000); } // Draw the mesh, using the effects set above. mesh.Draw(); } //base.Draw(camera); }
public NiceShapes() { circle = new Circle(); circle.GetRadius(); x = 5; //draw3D = new Triangle(); draw3D = new Circle(); //draw3D = new Canvas(); object obj = circle; draw3D.DrawIn3D(); }
public static void DemoExplicitInterface() { Rectangle <int> rectangle = new Rectangle <int>("Rectangle With Explicit Inteface Implementation", 10, 30); IDraw3D draw = rectangle as IDraw3D; if (draw != null) { draw.Draw(); } IDrawHologram drawHolo = rectangle as IDrawHologram; if (drawHolo != null) { drawHolo.Draw(); } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Shape[] shapes = new Shape[] { new Triangle(), new Hexagon() }; foreach (Shape shape in shapes) { if (shape is IPointy) { ((IPointy)shape).Draw(); } IDraw3D idraw3d = shape as IDraw3D; if (idraw3d != null) { //Draw "normally" idraw3d.Draw3D(); //Draw as interface parameter DrawIn3D(idraw3d); } } Console.ReadLine(); }
static void DrawIn3D(IDraw3D i3d) { Console.WriteLine($"-> Drawing IDraw3D compatible type {i3d.GetType().Name}"); i3d.Draw3D(); }
// I'll darw anyone supporting IDraw3D static void DrawIn3D(IDraw3D<Shape> itf3d) { Console.WriteLine("-> Drawing IDraw3D compatible type"); itf3d.Draw3D(); }
// INTERFACE AS PARAMETERS public static void Draw3DShapes(IDraw3D shape) { shape.Draw3D(); }
static void DrawIn3D(IDraw3D itf3D) { Console.WriteLine("->Drawing IDraw3D compatible type."); itf3D.Draw3D(); }
// I'll draw anyone supporting IDraw3D. static void DrawIn3D(IDraw3D itf3D) { Console.WriteLine("-> Drawing IDraw3D compatible type"); itf3D.Draw3D(); }
// I'll draw anyone supporting IDraw3D. static void DrawIn3D(IDraw3D interface3d) { Console.Write("-> Drawing IDraw3D compatible type: "); interface3d.Draw3D(); }
public NiceShapes(int x, Circle circle, IDraw3D draw3D) { this.x = x; this.circle = circle; this.draw3D = draw3D; }
static void Main(string[] args) { Shape[] s = { new Hexagon(), new Circle(), new Triangle("Trident"), new Circle("Ring") }; Console.WriteLine("\n==========================================================="); Console.WriteLine("==========================================================="); Hexagon testHexagon = new Hexagon(); // my changes create new obj for test with explicied implimentes Interface.. IDraw3D Qdraw3D = testHexagon; Qdraw3D.Draw(); DrawIn3D(testHexagon); testHexagon.Draw(); IDraw3D draw3D = testHexagon; draw3D.Draw(); Console.WriteLine("==========================================================="); Console.WriteLine("==========================================================="); for (int i = 0; i < s.Length; i++) { // Recall the Shape base class defines an abstract Draw() member, // so all shapes know how to draw themselves. s[i].Draw(); // Who's pointy? if (s[i] is IPointy) { Console.WriteLine("-> Points: {0} ", ((IPointy)s[i]).Points); } else { Console.WriteLine("-> {0}\'s not pointy!", s[i].PetName); } // Can I draw you in 3D? if (s[i] is IDraw3D) { DrawIn3D((IDraw3D)s[i]); } Console.WriteLine("----------------------------"); } #region Interfaces as return values // Attempt to get IPointy. Circle c = new Circle(); // IPointy itfPt = c as IPointy; IPointy itfPt = ExtractPointyness(c); if (itfPt != null) { Console.WriteLine("Object has {0} points.", itfPt.Points); } #endregion #region Print all the members in IPointy array Console.WriteLine("\n***** Printing out members in IPointy array *****"); IPointy[] myPointyObjects = new IPointy[] { new Hexagon(), new Spear(), new Triangle(), new Fork(), new PitchFork() }; for (int i = 0; i < myPointyObjects.Length; i++) { Console.WriteLine("Object has {0} points.", myPointyObjects[i].Points); } #endregion Console.ReadLine(); }
public static void DrawIn3D(IDraw3D itf3d) { Console.WriteLine("\n=> Drawing IDRaw3d compatible type"); itf3d.Draw3D(); }
static void DrawIn3D(IDraw3D draw3D) { Console.WriteLine("Drawing IDraw3D compatible type"); draw3D.Draw3D(); }
/// <summary> /// Remove an object of type IDraw3D to the engine. /// </summary> /// <param name="e"></param> public void UntrackDraw3D(IDraw3D e) { Draw3DList.Remove(e); }
static void Draw3D(IDraw3D draw3D) { draw3D.DrawIn3D(); }
public static int Main(string[] args) { Line l = new Line(); l.Draw(); IDraw3D itfDraw3d = (IDraw3D)l; itfDraw3d.Draw(); // First way to obtain an interface: Circle c = new Circle("Mitch"); IPointy itfPt; try { itfPt = (IPointy)c; Console.WriteLine("Got interface using casting..."); } catch (InvalidCastException e) { Console.WriteLine("OOPS! Not pointy..."); } // Second way to obtain an interface: Hexagon hex = new Hexagon("Fran"); IPointy itfPt2; itfPt2 = hex as IPointy; if (itfPt2 != null) { Console.WriteLine("Got interface using as keyword"); } else { Console.WriteLine("OOPS! Not pointy..."); } // Third way to grab an interface. Triangle t = new Triangle(); if (t is IPointy) { Console.WriteLine("Got interface using is keyword"); } else { Console.WriteLine("OOPS! Not pointy..."); } Console.WriteLine(); // The C# base class pointer trick. Shape[] s = { new Hexagon(), new Circle(), new Triangle("Joe"), new Circle("JoJo") }; for (int i = 0; i < s.Length; i++) { s[i].Draw(); // Who's pointy? if (s[i] is IPointy) { Console.WriteLine("Points: {0}\n", ((IPointy)s[i]).GetNumberOfPoints()); } else { Console.WriteLine(s[i].PetName + "\'s not pointy!\n"); } // Can I draw you in 3D? if (s[i] is IDraw3D) { DrawThisShapeIn3D((IDraw3D)s[i]); } Console.WriteLine(); } return(0); }
/// <summary> /// Add an object of type IDraw3D to the engine. /// </summary> /// <param name="e"></param> public void TrackDraw3D(IDraw3D e) { Draw3DList.Add(e); }
// I'll Draw anything! public static void DrawThisShapeIn3D(IDraw3D itf3d) { itf3d.Draw(); }
//I'll draw anyone supporting IDraw3D static void DrawIn3D(IDraw3D itf3d) { Console.WriteLine("=> Drawing IDraw3D compatimble type"); itf3d.Draw3D(); }
static void DrawIn3D(IDraw3D itf3d) { itf3d.Draw3D(); }
private static void DrawIn3D(IDraw3D idrawin3d) { Console.WriteLine($"-> Drawing {idrawin3d.GetType().ToString()} compatible type..."); idrawin3d.Draw3D(); }