private void DrawBoundingPrimitive(GameTime gameTime, ICollisionPrimitive collisionPrimitive, Color color) { if (collisionPrimitive is SphereCollisionPrimitive) { int primitiveCount = 0; vertexData = new VertexData <VertexPositionColor>(VertexFactory.GetSphereVertices(1, 10, out primitiveCount), PrimitiveType.LineStrip, primitiveCount); coll = collisionPrimitive as SphereCollisionPrimitive; world = Matrix.Identity * Matrix.CreateScale(coll.BoundingSphere.Radius) * Matrix.CreateTranslation(coll.BoundingSphere.Center); wireframeEffect.World = world; wireframeEffect.View = cameraManager.ActiveCamera.View; wireframeEffect.Projection = cameraManager.ActiveCamera.Projection; wireframeEffect.DiffuseColor = Color.White.ToVector3(); wireframeEffect.CurrentTechnique.Passes[0].Apply(); vertexData.Draw(gameTime, wireframeEffect); } else { BoxCollisionPrimitive coll = collisionPrimitive as BoxCollisionPrimitive; BoundingBoxBuffers buffers = BoundingBoxDrawer.CreateBoundingBoxBuffers(coll.BoundingBox, GraphicsDevice); BoundingBoxDrawer.DrawBoundingBox(buffers, wireframeEffect, GraphicsDevice, cameraManager.ActiveCamera); } }
public DefaultEntityRenderer(GameWindow window, Camera camera, Shader shader) : base(window, camera, shader) { vao = new VAO(); vertBuffer = new Vector3[4] { new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 1, 0), new Vector3(0, 1, 0), }; texBuffer = new Vector2[4] { new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0), new Vector2(0, 0), }; Console.WriteLine((Vector2.SizeInBytes * 8 * 000) / 1024); vao.registerAttribute(0, vertBuffer, Vector3.SizeInBytes, 3); vao.registerAttribute(1, texBuffer, Vector2.SizeInBytes, 2); /* * VBO = GL.GenBuffer(); * GL.BindBuffer(BufferTarget.ArrayBuffer, VBO); * GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vector2.SizeInBytes * vertBuffer.Length), vertBuffer, BufferUsageHint.StaticDraw); * GL.VertexPointer(2, VertexPointerType.Float, Vector2.SizeInBytes * 2, 0); * GL.TexCoordPointer(2, TexCoordPointerType.Float, Vector2.SizeInBytes * 2, Vector2.SizeInBytes); * GL.BindBuffer(BufferTarget.ArrayBuffer, 0);*/ }
protected override PropertyEditor AutoCreateMemberEditor(MemberInfo info) { if (info.IsEquivalent(ReflectionInfo.Property_DrawTechnique_PreferredVertexFormat)) { List <VertexDeclaration> vertexTypes = new List <VertexDeclaration>(); vertexTypes.Add(null); foreach (TypeInfo vertexType in DualityApp.GetAvailDualityTypes(typeof(IVertexData))) { if (vertexType.IsClass) { continue; } if (vertexType.IsAbstract) { continue; } if (vertexType.IsInterface) { continue; } IVertexData vertex = vertexType.CreateInstanceOf() as IVertexData; vertexTypes.Add(vertex.Declaration); } ObjectSelectorPropertyEditor e = new ObjectSelectorPropertyEditor(); e.EditedType = (info as PropertyInfo).PropertyType; e.Items = vertexTypes.Select(decl => new ObjectItem(decl, decl != null ? decl.DataType.Name : "None")); this.ParentGrid.ConfigureEditor(e); return(e); } return(base.AutoCreateMemberEditor(info)); }
public PrimitiveObject(string id, ObjectType objectType, Transform3D transform, IVertexData vertexData, Effect effect, Color color, float alpha) : base(id, objectType, transform, effect, color, alpha) { this.vertexData = vertexData; this.effect = effect; }
public PrimitiveObject(string id, ActorType actorType, Transform3D transform, BasicEffect effect, IVertexData vertexData) : base(id, actorType, transform, effect) { this.vertexData = vertexData; }
public PlatformCollidablePrimitiveObject(string id, ActorType actorType, Transform3D transform, EffectParameters effectParameters, StatusType statusType, IVertexData vertexData, ICollisionPrimitive collisionPrimitive, ManagerParameters managerParameters, EventDispatcher eventDispatcher) : base(id, actorType, transform, effectParameters, statusType, vertexData, collisionPrimitive, managerParameters.ObjectManager, eventDispatcher) { this.currentPosition = this.previousPosition = this.Transform.Translation; }
public PrimitiveObject(string id, ActorType actorType, Transform3D transform, Effect effect, IVertexData vertexData, Color color, float alpha, StatusType statusType) : base(id, actorType, transform, effect, color, alpha, statusType) { this.vertexData = vertexData; }
//used to draw billboards that have a texture public BillboardPrimitiveObject(string id, ActorType actorType, Transform3D transform, Effect effect, IVertexData vertexData, Texture2D texture, Color color, float alpha, StatusType statusType, BillboardType billBoardType) : base(id, actorType, transform, effect, vertexData, texture, color, alpha, statusType) { this.billboardParameters = new BillboardParameters(); this.BillboardType = billBoardType; }
/// <summary> /// Apply weighted transforms to the vertext data /// </summary> /// <param name="vertex">Vertex data</param> /// <param name="boneTransforms">Bone transforms list</param> /// <returns>Returns the weighted position</returns> public static Vector3 ApplyWeight(IVertexData vertex, IEnumerable <Matrix> boneTransforms) { Vector3 position = vertex.HasChannel(VertexDataChannels.Position) ? vertex.GetChannelValue <Vector3>(VertexDataChannels.Position) : Vector3.Zero; if (!IsSkinned(vertex.VertexType)) { return(position); } byte[] boneIndices = vertex.HasChannel(VertexDataChannels.BoneIndices) ? vertex.GetChannelValue <byte[]>(VertexDataChannels.BoneIndices) : null; float[] boneWeights = vertex.HasChannel(VertexDataChannels.Weights) ? vertex.GetChannelValue <float[]>(VertexDataChannels.Weights) : null; Matrix[] transforms = boneTransforms.ToArray(); Vector3 t = Vector3.Zero; for (int w = 0; w < boneIndices.Length; w++) { float weight = boneWeights[w]; if (weight > 0) { byte index = boneIndices[w]; var boneTransform = transforms != null ? transforms[index] : Matrix.Identity; Vector3.TransformCoordinate(ref position, ref boneTransform, out Vector3 p); t += (p * weight); } } return(t); }
public CollidablePlayerObject(string id, ActorType actorType, StatusType statusType, Transform3D transform, EffectParameters effectParameters, IVertexData vertexData, ICollisionPrimitive collisionPrimitive, ObjectManager objectManager, Keys[] moveKeys, KeyboardManager keyboardManager) : base(id, actorType, statusType, transform, effectParameters, vertexData, collisionPrimitive, objectManager) { this.moveKeys = moveKeys; this.keyboardManager = keyboardManager; }
public TexturedPrimitiveObject(string id, ActorType actorType, Transform3D transform, BasicEffect effect, IVertexData vertexData, Texture2D texture) : base(id, actorType, transform, effect, vertexData) { this.texture = texture; }
public TexturedPrimitiveObject(string id, ActorType actorType, Transform3D transform, Effect effect, IVertexData vertexData, Texture2D texture, Color color, float alpha, StatusType statusType) : base(id, actorType, transform, effect, vertexData, color, alpha, statusType) { this.texture = texture; }
internal Vertex(T value) { this.value = value; this.ownerID = null; this.handle = null; this.valueCore = 0; this.color = Color.Empty; this.data = null; }
public BetterEntityRenderer(GameWindow window, Camera camera, Shader shader) : base(window, camera, shader) { vao = new VAO(); vertBuffer = new Vector3[maxSize]; texBuffer = new Vector2[maxSize]; //ibo = new int[maxSize]; //vertexCache = new Dictionary<Tuple<Vector3, Vector2>, int>(); }
public Model(ShaderProgram shaderProgram, IVertexData vertexData) { this.ShaderProgram = shaderProgram; VertexData = vertexData; GenerateVAO(); GenerateVBO(); LinkVertexAttributes(VertexData.Structure); GL.BindVertexArray(0); }
private PrimitiveObject GetTexturedPyramidSquare(GraphicsDevice graphics, ShapeType shapeType, EffectParameters effectParameters) { //get the vertices VertexPositionColorTexture[] vertices = PrimitiveUtility.GetTexturedPyramidSquare(out primitiveType, out primitiveCount); vertexData = new BufferedVertexData <VertexPositionColorTexture>(graphics, vertices, primitiveType, primitiveCount); //instanciate the object and return a reference return(GetPrimitiveObjectFromVertexData(vertexData, shapeType, effectParameters)); }
//used to draw collidable primitives that a value associated with them e.g. health public CollidablePickupObject(string id, ActorType actorType, StatusType statusType, Transform3D transform, EffectParameters effectParameters, IVertexData vertexData, ICollisionPrimitive collisionPrimitive, ObjectManager objectManager, PickupParameters pickupParameters) : base(id, actorType, statusType, transform, effectParameters, vertexData, collisionPrimitive, objectManager) { this.pickupParameters = pickupParameters; }
//used to draw collidable primitives that have a texture i.e. use VertexPositionColor vertex types only public CollidablePrimitiveObject(string id, ActorType actorType, StatusType statusType, Transform3D transform3D, EffectParameters effectParameters, IVertexData vertexData, ICollisionPrimitive collisionPrimitive, ObjectManager objectManager) : base(id, actorType, statusType, transform3D, effectParameters, vertexData) { this.effectParameters = effectParameters; this.collisionPrimitive = collisionPrimitive; //unusual to pass this in but we use it to test for collisions - see Update(); this.objectManager = objectManager; }
private PrimitiveObject GetWireframeSpiral(GraphicsDevice graphics, ShapeType shapeType, EffectParameters effectParameters) { //get the vertices VertexPositionColor[] vertices = PrimitiveUtility.GetWireframeSpiral(15, 1, out primitiveType, out primitiveCount); //create the buffered data vertexData = new BufferedVertexData <VertexPositionColor>(graphics, vertices, primitiveType, primitiveCount); //instanciate the object and return a reference return(GetPrimitiveObjectFromVertexData(vertexData, shapeType, effectParameters)); }
private PrimitiveObject GetNormalTexturedCube(GraphicsDevice graphics, ShapeType shapeType, EffectParameters effectParameters) { //get the vertices VertexPositionNormalTexture[] vertices = PrimitiveUtility.GetNormalTexturedCube(out primitiveType, out primitiveCount); //create the buffered data using indexed since it will reduce the number of vertices required from 36 - 12 - see GetTexturedCube() comment vertexData = new IndexedBufferedVertexData <VertexPositionNormalTexture>(graphics, vertices, primitiveType, primitiveCount); //instanciate the object and return a reference return(GetPrimitiveObjectFromVertexData(vertexData, shapeType, effectParameters)); }
public PrimitiveDebugDrawer(Game game, EventDispatcher eventDispatcher, StatusType statusType, ManagerParameters managerParameters, bool bShowCollisionSkins, bool bShowFrustumCullingSphere, bool bShowZones, IVertexData sphereVertexData) : base(game, eventDispatcher, statusType) { this.managerParameters = managerParameters; this.bShowCollisionSkins = bShowCollisionSkins; this.bShowFrustumCullingSphere = bShowFrustumCullingSphere; this.bShowZones = bShowZones; //used to draw the default BoundingSphere for any primitive and the collision skin for any primitive with a sphere collision primitive this.sphereVertexData = sphereVertexData; }
public PlayerCollidablePrimitiveObject(string id, ActorType actorType, Transform3D transform, EffectParameters effectParameters, StatusType statusType, IVertexData vertexData, ICollisionPrimitive collisionPrimitive, ManagerParameters managerParameters, Keys[] moveKeys, float moveSpeed, float rotationSpeed) : base(id, actorType, transform, effectParameters, statusType, vertexData, collisionPrimitive, managerParameters.ObjectManager) { this.moveKeys = moveKeys; this.moveSpeed = moveSpeed; this.rotationSpeed = rotationSpeed; //for input this.managerParameters = managerParameters; }
private PrimitiveObject GetColoredQuad(GraphicsDevice graphics, ShapeType shapeType, EffectParameters effectParameters) { //vertex colors for the quad Color[] vertexColorArray = { Color.Red, Color.Green, Color.Blue, Color.Orange }; //get the vertices VertexPositionColor[] vertices = PrimitiveUtility.GetColoredQuad(vertexColorArray, out primitiveType, out primitiveCount); //create the buffered data vertexData = new BufferedVertexData <VertexPositionColor>(graphics, vertices, primitiveType, primitiveCount); //instanciate the object and return a reference return(GetPrimitiveObjectFromVertexData(vertexData, shapeType, effectParameters)); }
protected PrimitiveObject GetPrimitiveObjectFromVertexData(IVertexData vertexData, ShapeType shapeType, EffectParameters effectParameters) { //instanicate the object PrimitiveObject primitiveObject = new PrimitiveObject("Archetype - " + shapeType.ToString(), ActorType.NotYetAssigned, Transform3D.Zero, effectParameters.Clone() as EffectParameters, StatusType.Update | StatusType.Drawn, vertexData); //add to the dictionary for re-use in any subsequent call to this method primitiveDictionary.Add(shapeType, primitiveObject); //return a reference to a CLONE of our original object - remember we always clone the dictionary object, rather than modify the archetype in the dictionary return(primitiveObject.Clone() as PrimitiveObject); }
public CollidablePlayerObject(string id, ActorType actorType, StatusType statusType, Transform3D transform, EffectParameters effectParameters, IVertexData vertexData, ICollisionPrimitive collisionPrimitive, ObjectManager objectManager, Keys[] moveKeys, float moveSpeed, float rotationSpeed, KeyboardManager keyboardManager, Game game) : base(id, actorType, statusType, transform, effectParameters, vertexData, collisionPrimitive, objectManager) { this.moveKeys = moveKeys; this.moveSpeed = moveSpeed; this.rotationSpeed = 0.1f; //for movement this.keyboardManager = keyboardManager; this.game = game; this.deathCount = 0; }
public static VertexDeclaration Get(Type vertexType) { if (vertexType == null) { return(null); } TypeInfo vertexTypeInfo = vertexType.GetTypeInfo(); if (!typeof(IVertexData).GetTypeInfo().IsAssignableFrom(vertexTypeInfo)) { return(null); } IVertexData dummyVertex = vertexTypeInfo.CreateInstanceOf() as IVertexData; return(dummyVertex != null ? dummyVertex.Declaration : null); }
private PrimitiveObject GetTexturedCube(GraphicsDevice graphics, ShapeType shapeType, EffectParameters effectParameters) { //get the vertices VertexPositionColorTexture[] vertices = PrimitiveUtility.GetTexturedCube(out primitiveType, out primitiveCount); /* * Remember we saw in PrimitiveUtility.GetTexturedCube() that we were using too many vertices? * We can use IndexedBufferedVertexData to now reduce the 36 vertices to 12. * * Notice however that we are STILL using TriangleList as our PrimitiveType. The optimal solution is to use an IndexedBufferedVertexData object where you define the indices and vertices * and also choose TriangleStrip or LineStrip as your PrimitiveType. */ vertexData = new IndexedBufferedVertexData <VertexPositionColorTexture>(graphics, vertices, primitiveType, primitiveCount); //instanciate the object and return a reference return(GetPrimitiveObjectFromVertexData(vertexData, shapeType, effectParameters)); }
public TexturedPrimitiveObject(string id, ObjectType objectType, Transform3D transform, IVertexData vertexData, Effect effect, Color color, float alpha, Texture2D texture) : base(id, objectType, transform, vertexData, effect, color, alpha) { this.texture = texture; }
//used to draw billboards that have a texture public BillboardPrimitiveObject(string id, ObjectType objectType, Transform3D transform, IVertexData vertexData, Effect effect, Color color, float alpha, Texture2D texture, BillboardType billBoardType) : base(id, objectType, transform, vertexData, effect, color, alpha, texture) { this.billBoardType = billBoardType; this.billboardParameters = new BillboardParameters(); if (billBoardType == BillboardType.Normal) { this.billboardParameters.Technique = "Normal"; this.billboardParameters.BillboardType = BillboardType.Normal; } else if (billBoardType == BillboardType.Cylindrical) { this.billboardParameters.Technique = "Cylindrical"; this.billboardParameters.BillboardType = BillboardType.Cylindrical; this.billboardParameters.Up = this.Transform3D.Up; } else { this.billboardParameters.Technique = "Spherical"; this.billboardParameters.BillboardType = BillboardType.Spherical; } }
public new object Clone() { CollidablePrimitiveObject primitive = new CollidablePrimitiveObject(ID, ActorType, StatusType, Transform3D.Clone() as Transform3D, EffectParameters.Clone() as EffectParameters, IVertexData.Clone() as IVertexData, CollisionPrimitive.Clone() as ICollisionPrimitive, ObjectManager); primitive.ControllerList.AddRange(GetControllerListClone()); return(primitive); }
public CollidableProjectile(string id, ActorType actorType, StatusType statusType, Transform3D transform3D, EffectParameters effectParameters, IVertexData vertexData, ICollisionPrimitive collisionPrimitive, ObjectManager objectManager) : base(id, actorType, statusType, transform3D, effectParameters, vertexData, collisionPrimitive, objectManager) { }
public new object Clone() { MovingObstacleSpawner spawner = new MovingObstacleSpawner(ID, ActorType, StatusType, Transform3D.Clone() as Transform3D, EffectParameters.Clone() as EffectParameters, IVertexData.Clone() as IVertexData, CollisionPrimitive.Clone() as ICollisionPrimitive, ObjectManager); spawner.ControllerList.AddRange(GetControllerListClone()); return(spawner); }
public MovingObstacleSpawner(string id, ActorType actorType, StatusType statusType, Transform3D transform3D, EffectParameters effectParameters, IVertexData vertexData, ICollisionPrimitive collisionPrimitive, ObjectManager objectManager) : base(id, actorType, statusType, transform3D, effectParameters, vertexData, collisionPrimitive, objectManager) { }