public static void Draw(Matrix world, Matrix view, Matrix projection, Color newcolor, float scale) { // Set BasicEffect parameters. basicEffect.World = Matrix.CreateRotationZ((float) (Math.PI)) * Matrix.CreateScale(2.0f) * world; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.DiffuseColor = newcolor.ToVector3(); //basicEffect.VertexColorEnabled = true; basicEffect.Alpha = newcolor.A / 255.0f; basicEffect.EmissiveColor = newcolor.ToVector3(); //basicEffect.EmissiveColor = new Color(100,100,0).ToVector3(); basicEffect.SpecularColor = new Color(255, 255, 0).ToVector3(); basicEffect.SpecularPower = 10f; //basicEffect.Texture = Texture2D.FromStream(Game1.device, new FileStream(@"Content\suntexture.png", FileMode.Open)); // basicEffect.TextureEnabled = true; GraphicsDevice device = basicEffect.GraphicsDevice; device.DepthStencilState = DepthStencilState.Default; device.BlendState = BlendState.AlphaBlend; // Draw the model, using BasicEffect. Matrix translationMatrix = Matrix.CreateRotationY((float)(Math.PI / 2.0f)); foreach (ModelMesh mesh in beam.Meshes) { mesh.Draw(); } }
public int AddFace(Face.Facing facing, float x, float y, float z, Vector3 size, ref Color color) { if (color == Color.Black) Console.WriteLine("Black detected."); for (int i = 0; i < buffers.Count; i++) { if (!buffers[i].Full) { //int k = buffers[i].AddFace(Face.getFace(facing, new Vector3(x, y, z), size, color.ToVector3())); int k = buffers[i].AddFace(Face.getInstancedFace(facing, new Vector3(x, y, z), size, color.ToVector3())); if (k > -1) return (i * Size) + k; return -1; } } buffers.Add(new BatchBuffer(Size)); int j = buffers[buffers.Count - 1].AddFace(Face.getInstancedFace(facing, new Vector3(x, y, z), size, color.ToVector3())); if (j > -1) return ((buffers.Count - 1) * Size) + j; return -1; }
public void Draw(Matrix world, Matrix view, Matrix projection, Color newcolor, float scale, float hoveringHeight) { // Set BasicEffect parameters. Matrix worldMatrix = Matrix.CreateScale(scale) * Matrix.CreateRotationX((float)(Math.PI)) * Matrix.CreateTranslation(new Vector3(0, 0, hoveringHeight)) * world; basicEffect.World = worldMatrix; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.DiffuseColor = newcolor.ToVector3(); // basicEffect.VertexColorEnabled = true; //basicEffect.Alpha = color.A / 255.0f; basicEffect.EmissiveColor = newcolor.ToVector3(); GraphicsDevice device = basicEffect.GraphicsDevice; device.DepthStencilState = DepthStencilState.Default; device.BlendState = BlendState.AlphaBlend; // Draw the model, using BasicEffect. foreach (ModelMesh mesh in ship.Meshes) { mesh.Draw(); } }
public void AnnotateAvoidNeighbor(IVehicle threat, Vector3 ourFuture, Vector3 threatFuture) { Color green = new Color((byte)(255.0f * 0.15f), (byte)(255.0f * 0.6f), 0); annotation.Line(Position, ourFuture, green.ToVector3().FromXna()); annotation.Line(threat.Position, threatFuture, green.ToVector3().FromXna()); annotation.Line(ourFuture, threatFuture, Color.Red.ToVector3().FromXna()); annotation.CircleXZ(Radius, ourFuture, green.ToVector3().FromXna(), 12); annotation.CircleXZ(Radius, threatFuture, green.ToVector3().FromXna(), 12); }
/// <summary> /// Button Row Constructor /// </summary> /// <param name="name">Control Name</param> /// <param name="position">Control Position</param> /// <param name="width">Control Width</param> /// <param name="titles">Button Titles</param> /// <param name="backColor">Backcolor</param> /// <param name="foreColor">Forecolor</param> public ButtonRow(string name, Vector2 position, float width, string[] titles, Color backColor, Color foreColor) : base(name) { this.Position = position; this.size = new Vector2(width, 0f); this.titles = titles; this.BackColor = backColor; this.highlight = new Color(backColor.ToVector3() * 0.9f); this.dimColor = new Color(backColor.ToVector3() * 0.85f); this.ForeColor = foreColor; }
public static void Render(BoundingSphere sphere, GraphicsDevice graphicsDevice, Matrix view, Matrix projection, Color color, Guid id) { var subscription = Subscriptions[id]; graphicsDevice.SetVertexBuffer(subscription.VertexBuffer); subscription.BasicEffect.World = Matrix.CreateScale(sphere.Radius)* Matrix.CreateTranslation(sphere.Center); subscription.BasicEffect.View = view; subscription.BasicEffect.Projection = projection; subscription.BasicEffect.DiffuseColor = color.ToVector3(); foreach (var pass in subscription.BasicEffect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, 0, SphereResolution); graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, SphereResolution + 1, SphereResolution); graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, (SphereResolution + 1)*2, SphereResolution); } }
public void Draw(Matrix world, Matrix view, Matrix projection, Color color) { // Set BasicEffect parameters. basicEffect.World = world; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.DiffuseColor = color.ToVector3(); basicEffect.Alpha = color.A / 255.0f; GraphicsDevice device = basicEffect.GraphicsDevice; device.DepthStencilState = DepthStencilState.Default; if (color.A < 255) { // Set renderstates for alpha blended rendering. device.BlendState = BlendState.AlphaBlend; } else { // Set renderstates for opaque rendering. device.BlendState = BlendState.Opaque; } // Draw the model, using BasicEffect. Draw(basicEffect); }
public static void DaySettings() { SunPosition = new Vector3(0,-0.8f,-0.2f); SunColor = new Vector3(.8f, .8f, .8f); SkyColor = new Color(0, 0.8f, 1); FogColor = SkyColor.ToVector3(); }
public ActDye(Color TargetColor, float Time, bool isSolid = true, bool isRelative = false) : base(isSolid) { this.targetColor = TargetColor.ToVector3(); this.frames = (int)(Time * Tool.GetFPS()); this.isRelative = isRelative; }
public static void NightSettings() { SunPosition = new Vector3(0, -0.4f, -0.6f); //The moon in this case. SunColor = new Vector3(0.05f, 0.15f, 0.2f); SkyColor = new Color(0.06f, 0.06f, 0.15f); FogColor = SkyColor.ToVector3(); }
public static void DrawCube(Matrix W, Matrix V, Matrix P, Color color) { foreach (ModelMesh mesh in cube.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { // fontos a sorrend !! // ha a forgatást a mozgatás után végeznénk el akkor is a (0, 0, 0) pont körül forgatna de mivel az már // nem a középpontja ezért teljesen más eredményt kapnánk // ha előbb skáláznánk aztán mozgatnánk akkor a skálázás arányának megfelelően kéne változtatni // a mozgatást is // a forgatást a skálázás után kell elvégezni valószinüleg..mármint hogy ne legyen semmi féle szétnyúlás // ami valószinüleg nem kívánt basicEffect.EnableDefaultLighting(); basicEffect.DiffuseColor = color.ToVector3(); basicEffect.World = W; basicEffect.View = V; basicEffect.Projection = P; part.Effect = basicEffect; } mesh.Draw(); } }
public void ShouldConvertToVector3() { var color = new Color(0.1f, 0.2f, 0.3f); var vector = color.ToVector3(); Assert.AreEqual(vector.X, color.R); Assert.AreEqual(vector.Y, color.G); Assert.AreEqual(vector.Z, color.B); }
public LambertPointLightMaterial(Color ambientColor, Color lightColor, Vector3 lightPosition, float attenuation, float falloff) { AmbientLightColor = ambientColor.ToVector3(); LightColor = lightColor.ToVector3(); LightPosition = lightPosition; LightAttenuation = attenuation; LightFalloff = falloff; }
public Label( string name, Vector2 position, string text, Color color, float scale )//, Font font) { this.Type = ControlType.Label; this.name = name; this.position = position; this.text = text; this.scale = scale; this.color = new Color( new Vector4( color.ToVector3(), 1f ) ); }
public static void Draw(this BoundingBox boundingBox, RenderContext renderContext, Color color) { if (_basicEffect == null) _basicEffect = new BasicEffect(renderContext.GraphicsDevice); var lineList = new VertexPositionColor[8]; var lineListIndices = new short[24]; var index = 0; var min = boundingBox.Min; var max = boundingBox.Max; var boundingCorners = boundingBox.GetCorners(); for (var i = 0; i < 8; ++i) lineList[i] = new VertexPositionColor(boundingCorners[i], color); index = 0; lineListIndices[index] = 0; lineListIndices[++index] = 1; lineListIndices[++index] = 1; lineListIndices[++index] = 2; lineListIndices[++index] = 2; lineListIndices[++index] = 3; lineListIndices[++index] = 3; lineListIndices[++index] = 0; lineListIndices[++index] = 4; lineListIndices[++index] = 5; lineListIndices[++index] = 5; lineListIndices[++index] = 6; lineListIndices[++index] = 6; lineListIndices[++index] = 7; lineListIndices[++index] = 7; lineListIndices[++index] = 4; lineListIndices[++index] = 0; lineListIndices[++index] = 4; lineListIndices[++index] = 1; lineListIndices[++index] = 5; lineListIndices[++index] = 2; lineListIndices[++index] = 6; lineListIndices[++index] = 3; lineListIndices[++index] = 7; _basicEffect.Projection = renderContext.Camera.Projection; _basicEffect.View = renderContext.Camera.View; _basicEffect.DiffuseColor = color.ToVector3(); foreach (var pass in _basicEffect.CurrentTechnique.Passes) { pass.Apply(); renderContext.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, lineList, 0, lineList.Length, lineListIndices, 0, 12); } }
public XNABasicShaderDescription(Color AmbientColor, Color EmissiveColor, Color SpecularColor, float specularPower = 50, float alpha = 1, bool EnableLightning = true, bool EnableTexture = true) { this.AmbientColor = AmbientColor.ToVector3(); this.EmissiveColor = EmissiveColor.ToVector3(); this.SpecularColor = SpecularColor.ToVector3(); this.SpecularPower = specularPower; this.alpha = alpha; this.EnableLightning = EnableLightning; this.EnableTexture = EnableTexture; DefaultLightning = false; }
/// <summary> /// Adiciona uma luz ao interpolador /// As cores das luzes adicionadas serao gerenciadas por este component /// </summary> /// <param name="dl">luz</param> /// <param name="c1">Cor original</param> /// <param name="c2">Cor destino</param> /// <param name="duration">Duracao da interpolacao em SEGUNDOS</param> public void AddLight(DeferredLight dl, Color c1, Color c2, double duration) { lightInterpolation l = new lightInterpolation(); l.dl = dl; l.duration = duration; l.v1 = c1.ToVector3(); l.v2 = c2.ToVector3(); lights.Add(l); l.vi = new Vec3Interpolator(); l.vi.Start(l.v1, l.v2, duration, true); }
private void DrawSphere(BoundingSphere bs, Matrix orientation, Color color) { if (bs == null) { return; } GraphicsDevice device = FrameworkCore.Graphics.GraphicsDevice; Matrix scaleMatrix = Matrix.CreateScale(bs.Radius); Matrix translateMat = Matrix.CreateTranslation(bs.Center); Matrix rotateYMatrix = Matrix.CreateRotationY(RADIANS_FOR_90DEGREES); Matrix rotateXMatrix = Matrix.CreateRotationX(RADIANS_FOR_90DEGREES); basicEffect.Alpha = ((float)color.A / (float)byte.MaxValue); basicEffect.World = orientation * scaleMatrix * translateMat; basicEffect.DiffuseColor = color.ToVector3(); basicEffect.CurrentTechnique.Passes[0].Apply(); device.DrawIndexedPrimitives( PrimitiveType.LineStrip, 0, // vertex buffer offset to add to each element of the index buffer 0, // minimum vertex index CIRCLE_NUM_POINTS + 1, // number of vertices. If this gets an exception for you try changing it to 0. Seems to work just as well. 0, // first index element to read CIRCLE_NUM_POINTS); // number of primitives to draw basicEffect.World = rotateYMatrix * orientation * scaleMatrix * translateMat; //basicEffect.DiffuseColor = color.ToVector3(); basicEffect.CurrentTechnique.Passes[0].Apply(); device.DrawIndexedPrimitives( PrimitiveType.LineStrip, 0, // vertex buffer offset to add to each element of the index buffer 0, // minimum vertex index CIRCLE_NUM_POINTS + 1, // number of vertices. If this gets an exception for you try changing it to 0. Seems to work just as well. 0, // first index element to read CIRCLE_NUM_POINTS); // number of primitives to draw basicEffect.World = rotateXMatrix * orientation * scaleMatrix * translateMat; //basicEffect.DiffuseColor = color.ToVector3(); basicEffect.CurrentTechnique.Passes[0].Apply(); device.DrawIndexedPrimitives( PrimitiveType.LineStrip, 0, // vertex buffer offset to add to each element of the index buffer 0, // minimum vertex index CIRCLE_NUM_POINTS + 1, // number of vertices. If this gets an exception for you try changing it to 0. Seems to work just as well. 0, // first index element to read CIRCLE_NUM_POINTS); // number of primitives to draw }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); basicEffect.View = viewMatrix; basicEffect.Begin(); // Debug draw basicEffect.VertexColorEnabled = true; basicEffect.LightingEnabled = false; basicEffect.World = Matrix.Identity; basicEffect.CurrentTechnique.Passes[0].Begin(); DebugDrawer.DrawDebugWorld(physics.World); basicEffect.CurrentTechnique.Passes[0].End(); // Draw shapes basicEffect.VertexColorEnabled = false; basicEffect.LightingEnabled = true; foreach (RigidBody body in physics.World.CollisionObjectArray) { basicEffect.World = body.MotionState.WorldTransform; if ("Ground".Equals(body.UserObject)) { basicEffect.DiffuseColor = groundColor.ToVector3(); basicEffect.CurrentTechnique.Passes[0].Begin(); VertexHelper.DrawBox(device, groundBox); basicEffect.CurrentTechnique.Passes[0].End(); continue; } if (body.ActivationState == ActivationState.ActiveTag) { basicEffect.DiffuseColor = activeColor.ToVector3(); } else { basicEffect.DiffuseColor = passiveColor.ToVector3(); } basicEffect.CurrentTechnique.Passes[0].Begin(); VertexHelper.DrawBox(device, box); basicEffect.CurrentTechnique.Passes[0].End(); } basicEffect.End(); base.Draw(gameTime); }
public override void PostDraw(int i, int j, SpriteBatch spriteBatch) { Tile tile = Main.tile[i, j]; int off = i + j; float sin = (float)Math.Sin(StarlightWorld.rottime + off * 0.2f * 0.2f); Color color = new Color(1 - sin * 0.5f, 1, 1); float mult = 0.2f - Lighting.Brightness(i, j) * 0.2f; spriteBatch.Draw(Main.tileTexture[tile.type], (new Vector2(i, j) + Helper.TileAdj) * 16 - Main.screenPosition, new Rectangle(tile.frameX, tile.frameY, 16, 16), color * mult); Lighting.AddLight(new Vector2(i, j) * 16, color.ToVector3() * 0.1f); }
public Obstacle(Vector3 position, Color color) { unitCube = GameMultiVerse.Instance.Content.Load<Model>("Models/cube"); basicEffect = new BasicEffect(GameMultiVerse.Instance.GraphicsDevice); Matrix W = Matrix.CreateTranslation(position); boundingBox = Collision.UpdateBoundingBox(unitCube, W); basicEffect.EnableDefaultLighting(); basicEffect.World = W; basicEffect.DiffuseColor = color.ToVector3(); }
public override void PostDraw(int i, int j, SpriteBatch spriteBatch) { Tile tile = Framing.GetTileSafely(i, j); if (tile.frameY >= 4 * 18 || checkIce(i - 1, j) || checkIce(i, j - 1) || checkIce(i + 1, j) || checkIce(i, j + 1)) { float offBack = (float)Math.Sin((i + j) * 0.2f) * 300 + (float)Math.Cos(j * 0.15f) * 200; float sinBack = (float)Math.Sin(StarlightWorld.rottime + offBack * 0.01f * 0.2f); float cosBack = (float)Math.Cos(StarlightWorld.rottime + offBack * 0.01f); Color colorBack = new Color(100 * (1 + sinBack) / 255f, 140 * (1 + cosBack) / 255f, 180 / 255f); Color light = Lighting.GetColor(i, j) * 0.68f; //why am I multiplying by a constant here? because terraria lighting falloff is consistent and this is close enough that it's visually indecipherable Color final = new Color(light.R + (int)(colorBack.R * 0.1f), light.G + (int)(colorBack.G * 0.1f), light.B + (int)(colorBack.B * 0.1f)); spriteBatch.Draw(GetTexture("StarlightRiver/Assets/Tiles/Permafrost/AuroraIceUnder"), (new Vector2(i, j) + Helper.TileAdj) * 16 - Main.screenPosition, new Rectangle(tile.frameX, tile.frameY % (4 * 18), 16, 16), final); } if (tile.frameY >= 4 * 18) { return; } int off = i + j; float time = Main.GameUpdateCount / 600f * 6.28f; float sin2 = (float)Math.Sin(time + off * 0.2f * 0.2f); float cos = (float)Math.Cos(time + off * 0.2f); Color color = new Color(100 * (1 + sin2) / 255f, 140 * (1 + cos) / 255f, 180 / 255f); if (color.R < 80) { color.R = 80; } if (color.G < 80) { color.G = 80; } spriteBatch.Draw(Main.tileTexture[tile.type], (new Vector2(i, j) + Helper.TileAdj) * 16 - Main.screenPosition, new Rectangle(tile.frameX, tile.frameY, 16, 16), color * 0.3f); spriteBatch.Draw(GetTexture("StarlightRiver/Assets/Tiles/Permafrost/AuroraIce"), (new Vector2(i, j) + Helper.TileAdj) * 16 - Main.screenPosition, new Rectangle(tile.frameX, tile.frameY, 16, 16), Color.Lerp(color, Color.White, 0.2f) * 0.1f); spriteBatch.Draw(GetTexture("StarlightRiver/Assets/Tiles/Permafrost/AuroraIceGlow2"), (new Vector2(i, j) + Helper.TileAdj) * 16 - Main.screenPosition, new Rectangle(tile.frameX, tile.frameY, 16, 16), Color.Lerp(color, Color.White, 0.4f) * 0.4f); spriteBatch.Draw(GetTexture("StarlightRiver/Assets/Tiles/Permafrost/AuroraIceGlow"), (new Vector2(i, j) + Helper.TileAdj) * 16 - Main.screenPosition, new Rectangle(tile.frameX, tile.frameY, 16, 16), Color.Lerp(color, Color.White, 0.7f) * 0.8f); Lighting.AddLight(new Vector2(i, j) * 16, color.ToVector3() * 0.35f); if (Main.rand.Next(24) == 0) { Dust d = Dust.NewDustPerfect(new Vector2(i, j) * 16 + new Vector2(Main.rand.Next(16), Main.rand.Next(16)), DustType <Dusts.Aurora>(), Vector2.Zero, 100, color, 0); d.customData = Main.rand.NextFloat(0.25f, 0.5f); } }
/// <summary> /// Initializes a new instance of the <see cref="ForwardXNABasicShaderDescription"/> struct. /// </summary> /// <param name="AmbientColor">Color of the ambient.</param> /// <param name="EmissiveColor">Color of the emissive.</param> /// <param name="SpecularColor">Color of the specular.</param> /// <param name="specularPower">The specular power.</param> /// <param name="alpha">The alpha.</param> /// <param name="EnableLightning">if set to <c>true</c> [enable lightning].</param> /// <param name="DefaultLightning">if set to <c>true</c> [default lightning].</param> /// <param name="EnableTexture">if set to <c>true</c> [enable texture].</param> public ForwardXNABasicShaderDescription(Color AmbientColor, Color EmissiveColor, Color SpecularColor, float specularPower = 50, float alpha = 1, bool EnableLightning = true, bool DefaultLightning = true, bool EnableTexture = true) { this.AmbientColor = AmbientColor.ToVector3(); this.EmissiveColor = EmissiveColor.ToVector3(); this.SpecularColor = SpecularColor.ToVector3(); this.SpecularPower = specularPower; this.alpha = alpha; this.EnableLightning = EnableLightning; this.EnableTexture = EnableTexture; this.DefaultLightning = DefaultLightning; ObjectColor = Vector3.Zero; }
private void DrawRing(SpriteBatch sb, Vector2 pos, float w, float h, float rotation, float prog, Color color) //optimization nightmare. Figure out smth later { var texRing = GetTexture(AssetDirectory.VitricItem + "BossBowRing"); var effect = Filters.Scene["BowRing"].GetShader().Shader; effect.Parameters["uProgress"].SetValue(rotation); effect.Parameters["uColor"].SetValue(color.ToVector3()); effect.Parameters["uImageSize1"].SetValue(new Vector2(Main.screenWidth, Main.screenHeight)); effect.Parameters["uOpacity"].SetValue(prog); sb.End(); sb.Begin(default, BlendState.Additive, default, default, default, effect, Main.GameViewMatrix.ZoomMatrix);
private void DrawCube(float size, Vector3I pos, ref Color color, string text) { var local = Matrix.CreateScale(size * 1.02f) * Matrix.CreateTranslation(pos * size); Matrix box = local * m_grid.WorldMatrix; MyRenderProxy.DebugDrawOBB(box, color.ToVector3(), 0.5f, true, true); if (DrawText && text != null && text != "0.00" && (Vector3D.Distance(box.Translation, Sandbox.Game.World.MySector.MainCamera.Position) < 30)) { MyRenderProxy.DebugDrawText3D(box.Translation, text, Color.White, 0.5f, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER); } }
public override void AI() { _trail?.SetCustomPositionMethod((proj) => proj.Center + new Vector2(-4, 0).RotatedBy((proj as Projectile).rotation)); Lighting.AddLight(projectile.Center, EffectColor.ToVector3() * 0.2f); if (Main.rand.NextBool(3)) { var dust = Main.dust[Dust.NewDust(projectile.position, projectile.width, projectile.height, 60, 0f, 0f)]; dust.noLight = true; dust.noGravity = true; } }
public override void SetEffect(GameTime gameTime, Effect effect) { base.SetEffect(gameTime, effect); ((BasicEffect)effect).World = World; ((BasicEffect)effect).View = camera.View; ((BasicEffect)effect).Projection = camera.Projection; ((BasicEffect)effect).LightingEnabled = false; ((BasicEffect)effect).DiffuseColor = Color.ToVector3(); ((BasicEffect)effect).AmbientLightColor = Color.ToVector3(); }
/// <summary> /// Casts basic light. /// </summary> /// <param name="lightColor">RGB color value.</param> /// <param name="strength">Radius multiplier.</param> /// <param name="delegateLighting">Set to true for PlotTileLine lighting.</param> public virtual void CastLight(Color lightColor, float strength = 40f, bool delegateLighting = false) { if (delegateLighting) { DelegateMethods.v3_1 = lightColor.ToVector3() / 255; Utils.PlotTileLine(projectile.Center, projectile.Center + projectile.velocity * 4f, strength, DelegateMethods.CastLightOpen); } else { Lighting.AddLight(projectile.Center, (int)lightColor.R / 255f * strength, (int)lightColor.G / 255f * strength, (int)lightColor.B / 255f * strength); } }
public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int height, Color color) { Texture2D texture = new Texture2D(graphicsDevice, width, height, true, SurfaceFormat.Color); Color[] colors = new Color[width * height]; for (int i = 0; i < width * height; i++) colors[i] = new Color(color.ToVector3()); texture.SetData(colors); return texture; }
public BoundingBoxO(Model m, Color c) { this.model = m; this.boundingBox = CreateBoundingBox(model); _buffers = CreateBoundingBoxBuffers(boundingBox, Settings.gDevice); _effect = new BasicEffect(Settings.gDevice); _effect.LightingEnabled = false; _effect.TextureEnabled = false; _effect.VertexColorEnabled = true; _effect.DiffuseColor = c.ToVector3(); }
//private void CheckVisibility ( Vector2 formPosition, Vector2 formSize ) //{ // if (position.X + buttonArea.Width > formPosition.X + formSize.X - 15f) // bVisible = false; // else if (position.Y + buttonArea.Height > formPosition.Y + formSize.Y - 25f) // bVisible = false; // else // bVisible = true; //} #endregion #region Draw public override void Draw(SpriteBatch spriteBatch, float alpha) { Color dynamicColor = Color.White; if (!bMouseOver && !bPressed) { dynamicColor = new Color(new Vector4(color.ToVector3().X * 0.95f, color.ToVector3().Y * 0.95f, color.ToVector3().Z * 0.95f, alpha)); } else if (bPressed) { dynamicColor = new Color(new Vector4(color.ToVector3().X * 0.9f, color.ToVector3().Y * 0.9f, color.ToVector3().Z * 0.9f, alpha)); } else if (bMouseOver) { dynamicColor = new Color(new Vector4(color.ToVector3().X * 1.5f, color.ToVector3().Y * 1.5f, color.ToVector3().Z * 1.5f, alpha)); } spriteBatch.Draw(buttonTexture, destRect[0], sourceRect[0], dynamicColor, 0, Vector2.Zero, SpriteEffects.None, LayerDepth.UI); spriteBatch.Draw(buttonTexture, destRect[1], sourceRect[1], dynamicColor, 0, Vector2.Zero, SpriteEffects.None, LayerDepth.UI); spriteBatch.Draw(buttonTexture, destRect[2], sourceRect[2], dynamicColor, 0, Vector2.Zero, SpriteEffects.None, LayerDepth.UI); Color dynamicTextColor = new Color(new Vector4(0f, 0f, 0f, alpha)); int spacing = (destRect[1].Width - text.Length * fontSize.X) / 2; BaseGame.FontMgr.DrawInScrnCoord(text, new Vector2(destRect[0].X + destRect[0].Width + spacing, destRect[0].Y + 3f), Control.fontScale, dynamicTextColor, LayerDepth.Text, Control.fontName); }
internal static void DebugDrawBlockGroups <TNode, TGroupData>(MyGroups <TNode, TGroupData> groups) where TNode : MySlimBlock where TGroupData : IGroupData <TNode>, new() { int num = 0; using (HashSet <MyGroups <TNode, TGroupData> .Group> .Enumerator enumerator = groups.Groups.GetEnumerator()) { while (enumerator.MoveNext()) { num++; Color colorFrom = new Vector3(((float)(num % 15)) / 15f, 1f, 1f).HSVtoColor(); HashSetReader <MyGroups <TNode, TGroupData> .Node> nodes = enumerator.Current.Nodes; foreach (MyGroups <TNode, TGroupData> .Node node in nodes) { try { BoundingBoxD xd; node.NodeData.GetWorldBoundingBox(out xd, false); SortedDictionaryValuesReader <long, MyGroups <TNode, TGroupData> .Node> children = node.Children; foreach (MyGroups <TNode, TGroupData> .Node node2 in children) { m_tmpBlocksDebugHelper.Add(node2); } foreach (object obj2 in m_tmpBlocksDebugHelper) { BoundingBoxD xd2; MyGroups <TNode, TGroupData> .Node node3 = null; int num2 = 0; children = node.Children; foreach (MyGroups <TNode, TGroupData> .Node node4 in children) { if (obj2 == node4) { node3 = node4; num2++; } } node3.NodeData.GetWorldBoundingBox(out xd2, false); MyRenderProxy.DebugDrawLine3D(xd.Center, xd2.Center, colorFrom, colorFrom, false, false); MyRenderProxy.DebugDrawText3D((xd.Center + xd2.Center) * 0.5, num2.ToString(), colorFrom, 1f, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false); } Color color = new Color(colorFrom.ToVector3() + 0.25f); MyRenderProxy.DebugDrawSphere(xd.Center, 0.2f, color.ToVector3(), 0.5f, false, true, true, false); MyRenderProxy.DebugDrawText3D(xd.Center, node.LinkCount.ToString(), color, 1f, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, -1, false); } finally { m_tmpBlocksDebugHelper.Clear(); } } } } }
private Color getColorVariation(Terrain terrain) { Color color = getColor(terrain); Vector3 colVec = color.ToVector3(); colVec.X *= terrain.Variation; colVec.Y *= terrain.Variation; colVec.Z *= terrain.Variation; return(new Color(colVec)); }
public Hoop(GraphicsDeviceManager g, ContentManager c, Vector3 position, Vector3 scale, Color color) { this.Scale = scale; this.Position = position; this.color = color.ToVector3(); graphics = g; Content = c; aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; cuboidModel = Content.Load<Model>("Models\\hoop"); }
public void DrawAdditive(SpriteBatch spriteBatch) { if (projectile.ai[0] <= 50) { Texture2D tex = GetTexture("StarlightRiver/Assets/Bosses/GlassMiniboss/SpikeTell"); float factor = 2 * projectile.ai[0] / 25f - (float)Math.Pow(projectile.ai[0], 2) / 625f; Color color = new Color(255, 180, 50) * factor; spriteBatch.Draw(tex, projectile.Center - Main.screenPosition, null, color, 0, new Vector2(tex.Width / 2, tex.Height + 8), 2, 0, 0); spriteBatch.Draw(tex, projectile.Center - Main.screenPosition, null, Color.White * factor, 0, new Vector2(tex.Width / 2, tex.Height + 8), 1, 0, 0); Lighting.AddLight(projectile.Center, color.ToVector3() * 0.75f); } }
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { Texture2D tex = ModContent.GetTexture(Texture); float sin = 1 + (float)Math.Sin(projectile.ai[1]); float cos = 1 + (float)Math.Cos(projectile.ai[1]); Color color = new Color(0.5f + cos * 0.2f, 0.8f, 0.5f + sin * 0.2f); spriteBatch.Draw(tex, projectile.Center - Main.screenPosition, tex.Frame(), color, projectile.rotation, tex.Size() / 2, projectile.scale, 0, 0); Lighting.AddLight(projectile.Center, color.ToVector3()); return(false); }
public override void AI() { // travel in a straight line along velocity if (!hasSpawned) { SpawnDust(); hasSpawned = true; } Color lightColor = new Color(0.75f, 0f, 1f, 1f); projectile.rotation = (float)Math.PI / 4 + projectile.velocity.ToRotation(); Lighting.AddLight(projectile.Center, lightColor.ToVector3()); }
public Object Clone() { Actor actorCopy = new Actor(texture, hitBox.Width, hitBox.Height, body.Width, body.Height); actorCopy.animations = animations; actorCopy.className = className; actorCopy.color = new Color(color.ToVector3()); actorCopy.health = health; actorCopy.sight = sight; actorCopy.sightVector = new Vector2(sightVector.X, sightVector.Y); actorCopy.reach = reach; return(actorCopy); }
public override void PostDraw(int i, int j, SpriteBatch spriteBatch) { Tile tile = Main.tile[i, j]; float off = (float)Math.Sin((i + j) * 0.2f) * 300 + (float)Math.Cos(j * 0.15f) * 200; float sin = 0.3f + (float)Math.Sin(StarlightWorld.rottime + off * 0.008f * 0.2f) * 0.7f; float cos = 0.3f + (float)Math.Cos(StarlightWorld.rottime + off * 0.008f) * 0.7f; Color color = new Color(100 * (1 + sin) / 255f, 140 * (1 + cos) / 255f, 180 / 255f); spriteBatch.Draw(Main.tileTexture[tile.type], (new Vector2(i, j) + Helper.TileAdj) * 16 - Main.screenPosition, new Rectangle(tile.frameX, tile.frameY, 16, 16), color * 0.35f); spriteBatch.Draw(GetTexture("StarlightRiver/Assets/Tiles/Permafrost/IceSpikeGlow"), (new Vector2(i, j) + Helper.TileAdj) * 16 - Main.screenPosition, new Rectangle(tile.frameX, tile.frameY, 16, 16), Color.White * 0.1f); Lighting.AddLight(new Vector2(i, j) * 16, color.ToVector3() * 0.2f); }
public override bool Update(Gore gore) { if (gore.timeLeft > 90) { gore.timeLeft = 90; } var color = new Color(50, 150, 255) * (gore.timeLeft / 55f); Dust.NewDustPerfect(gore.position + Vector2.One * 29 + Vector2.One.RotatedByRandom(6.28f) * Main.rand.NextFloat(3), DustType <Dusts.Ink>(), Vector2.One.RotatedByRandom(6.28f) * Main.rand.NextFloat(2), 0, color, 0.7f); Lighting.AddLight(gore.position, color.ToVector3() * 0.3f); return(true); }
public static void DrawAsBasicEffect(ModelMesh mesh, Matrix world, Matrix view, Matrix projection, Color color) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.World = world; effect.View = view; effect.Projection = projection; effect.AmbientLightColor = new Vector3(0.01f, 0.01f, 0.01f); effect.DiffuseColor = color.ToVector3(); } mesh.Draw(); }
public void Draw(GraphicsDevice graphics, Camera camera) { foreach (ModelMesh mesh in model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { var effect = part.Effect; if (part.PrimitiveCount > 0) { BasicEffect basicEffect = effect as BasicEffect; if (basicEffect != null) { basicEffect.View = camera.View; basicEffect.Projection = camera.Projection; basicEffect.World = Matrix.CreateScale(Size) * WorldMatrix; if (Texture != null) { basicEffect.TextureEnabled = true; basicEffect.Texture = Texture; } basicEffect.SpecularColor = SpecularColor.ToVector3(); basicEffect.DiffuseColor = Color.ToVector3(); basicEffect.SpecularPower = 0.5f; basicEffect.LightingEnabled = true; basicEffect.EnableDefaultLighting(); //basicEffect.DirectionalLight0.DiffuseColor = new Vector3(0.5f, 0.5f, 0.5f)*Position; //basicEffect.DirectionalLight0.Direction = new Vector3(1, 0, 0); //basicEffect.DirectionalLight0.SpecularColor = new Vector3(1, 1, 1); basicEffect.AmbientLightColor = camera.Ambient.ToVector3(); basicEffect.FogColor = camera.FogColor.ToVector3(); basicEffect.FogStart = camera.FogStart; basicEffect.FogEnd = camera.FogEnd; // lighting.ApplyLightSources(this, basicEffect); } else { effect.Parameters["WorldViewProjection"].SetValue(Matrix.Identity * camera.View * camera.Projection); } graphics.SetVertexBuffer(part.VertexBuffer); graphics.Indices = part.IndexBuffer; for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++) { effect.CurrentTechnique.Passes[i].Apply(); graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, part.VertexOffset, part.StartIndex, part.PrimitiveCount); } } } } }
void Behave(GameTime gameTime) { if (bracketDistanceIncreasing) { bracketDistance += bracketVelocity; if (bracketDistance > maxBracketDistance) { bracketDistanceIncreasing = !bracketDistanceIncreasing; } } else { bracketDistance -= bracketVelocity; if (bracketDistance < 0) { bracketDistanceIncreasing = !bracketDistanceIncreasing; } } if (!FixedAlpha) { foreach (MenuItem item in Items) { item.Alpha += item.AlphaV; if (item.Alpha > maxItemAlpha) { item.AlphaV *= -1f; item.Alpha = maxItemAlpha; } else if (item.Alpha < minItemAlpha) { item.AlphaV *= -1f; item.Alpha = minItemAlpha; } } Vector3 c = SelectedItemForeground.ToVector3(); if (selectedItemColor > 1f) { selectedItemColor = 1f; selectedItemColorRate = -Math.Abs(selectedItemColorRate); } else if (c.Y < 0.5f) { selectedItemColor = 0.5f; selectedItemColorRate = Math.Abs(selectedItemColorRate); } selectedItemColor += selectedItemColorRate; c.Y = selectedItemColor; SelectedItemForeground = new Color(c); } }
public override void Draw(SpriteBatch spriteBatch, float alpha) { Color dynamicListColor = new Color(new Vector4(backcolor.ToVector3().X, backcolor.ToVector3().Y, backcolor.ToVector3().Z, alpha)); spriteBatch.Draw(listBackground, position, null, dynamicListColor, 0, Vector2.Zero, 1, SpriteEffects.None, LayerDepth.UI); //Items int endIndex = Items.Count; if (startIndex + visibleItems < Items.Count) { endIndex = startIndex + visibleItems; } int lastItem = Items.Count; if (lastItem > visibleItems) { lastItem = visibleItems; } for (int i = 0; i < lastItem; i++) { Color dynamicTextColor = new Color(new Vector4(forecolor.ToVector3().X, forecolor.ToVector3().Y, forecolor.ToVector3().Z, alpha)); //font.Draw(Items[i + startIndex], position + new Vector2(4f, 4f) + new Vector2(0f, charHeight * i), 1f, dynamicTextColor, spriteBatch); BaseGame.FontMgr.DrawInScrnCoord(Items[i + startIndex], position + new Vector2(4f, 4f) + new Vector2(0f, charHeight * i), Control.fontScale, dynamicTextColor, 0f, Control.fontName); //Selected Area Color dynamicAreaColor = new Color(new Vector4(Color.White.ToVector3().X, Color.White.ToVector3().Y, Color.White.ToVector3().Z, alpha)); if (Items[i + startIndex] == selectedItem) { spriteBatch.Draw(selectionArea, position + new Vector2(4f, 4f) + new Vector2(0f, charHeight * i), null, dynamicAreaColor, 0, Vector2.Zero, 1, SpriteEffects.None, LayerDepth.UI); } //Selection Area if (ms.LeftButton == ButtonState.Released /*&& !Form.isInUse*/) { if (bIsOverItem(i)) { spriteBatch.Draw(selectionArea, position + new Vector2(4f, 4f) + new Vector2(0f, charHeight * i), null, dynamicAreaColor, 0, Vector2.Zero, 1, SpriteEffects.None, LayerDepth.UI); } } } if (scrollbar != null) { scrollbar.Draw(spriteBatch, alpha); } }
private Color GetShadedColor(Vector2 position, Color color) { // Ambient Vector3 shadedColor = color.ToVector3() * 0.03f; // Diffuse foreach (PointLight light in lightSources) { if (!IsInShadow(light.Position, position)) { shadedColor += color.ToVector3() * light.Color.ToVector3() * light.CalculatePower(position); } } // Bloom Chunk chunk = GetChunk(position); int x = (int)position.X - chunk.ChunkPosition.X * chunkSize; int y = (int)position.Y - chunk.ChunkPosition.Y * chunkSize; if (x > 0 && tileSetup[chunk.Grid[x - 1, y]].Unshaded) { shadedColor += tileSetup[chunk.Grid[x - 1, y]].Color.ToVector3() * 0.4f; } if (x < chunkSize - 1 && tileSetup[chunk.Grid[x + 1, y]].Unshaded) { shadedColor += tileSetup[chunk.Grid[x + 1, y]].Color.ToVector3() * 0.4f; } if (y > 0 && tileSetup[chunk.Grid[x, y - 1]].Unshaded) { shadedColor += tileSetup[chunk.Grid[x, y - 1]].Color.ToVector3() * 0.4f; } if (y < chunkSize - 1 && tileSetup[chunk.Grid[x, y + 1]].Unshaded) { shadedColor += tileSetup[chunk.Grid[x, y + 1]].Color.ToVector3() * 0.4f; } return(new Color(shadedColor.X, shadedColor.Y, shadedColor.Z)); }
private void initializeGraphics() { _spriteBatch = new SpriteBatch(Game1.DefaultGraphicsDevice); _basicEffect = new BasicEffect(Game1.DefaultGraphicsDevice, null); Orthographic.SetOrthoEffect(_basicEffect); _vertexDeclaration = new VertexDeclaration(Game1.DefaultGraphics.GraphicsDevice, new VertexElement[] { new VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0) } ); // create vertices for the background quad _vertices = new Vector3[] { new Vector3(0, 0, 0), new Vector3(_xSize, 0, 0), new Vector3(_xSize, _ySize, 0), new Vector3(0, _ySize, 0), }; // create indices for the background quad _indices = new short[] { 0, 1, 2, 2, 3, 0 }; // create an orthographic projection to draw the quad as a sprite _basicEffect.Projection = Matrix.CreateOrthographicOffCenter(0, Game1.DefaultGraphics.GraphicsDevice.Viewport.Width, Game1.DefaultGraphics.GraphicsDevice.Viewport.Height, 0, 0, 1); _basicEffect.DiffuseColor = BackgroundColor.ToVector3(); _basicEffect.Alpha = BackgroundAlpha; // move to correct position _basicEffect.World = Matrix.CreateTranslation(_position.X, _position.Y, 0); }
public override void PostDraw(SpriteBatch spriteBatch, Color drawColor) { Texture2D tex = GetTexture("StarlightRiver/NPCs/Boss/SquidBoss/AurorabornGlow"); Texture2D tex2 = GetTexture("StarlightRiver/NPCs/Boss/SquidBoss/AurorabornGlow2"); float sin = 1 + (float)Math.Sin(npc.ai[0] / 10f); float cos = 1 + (float)Math.Cos(npc.ai[0] / 10f); Color color = new Color(0.5f + cos * 0.2f, 0.8f, 0.5f + sin * 0.2f); spriteBatch.Draw(GetTexture(Texture), npc.Center - Main.screenPosition, npc.frame, drawColor * 1.2f, npc.rotation, npc.Size / 2, 1, 0, 0); spriteBatch.Draw(tex, npc.Center - Main.screenPosition, npc.frame, color * 0.8f, npc.rotation, npc.Size / 2, 1, 0, 0); spriteBatch.Draw(tex2, npc.Center - Main.screenPosition, npc.frame, color, npc.rotation, npc.Size / 2, 1, 0, 0); Lighting.AddLight(npc.Center, color.ToVector3() * 0.5f); }
private void PrzygotujShadery() { phong.diffuseColor = Color.Gray; phong.viewPosition = kamera.Position; phong.diffuseLightDirection = swiatloKierunkowe; phong.diffuseLightColor = Color.DimGray; phong.materialEmissive = new Vector3(0f, 0f, 0f); phong.materialAmbient = new Vector3(.05f, .05f, .1f); phong.materialDiffuse = Color.White.ToVector3(); phong.materialSpecular = Color.White.ToVector3(); phong.materialPower = 50f; phong.specularIntensity = 1f; phong.pointLightFalloff = 1f; phong.pointLightRange = 300f; phong.pointLightPos = swiatloPunktowe; phong.pointLightColor = swiatloPunktoweKolor.ToVector4() / 1.5f; texPhong.diffuseColor = Color.Gray; texPhong.viewPosition = kamera.Position; texPhong.diffuseLightDirection = swiatloKierunkowe; texPhong.diffuseLightColor = Color.DimGray; texPhong.materialEmissive = new Vector3(0f, 0f, 0f); texPhong.materialAmbient = new Vector3(.05f, .05f, .1f); texPhong.materialDiffuse = Color.White.ToVector3(); texPhong.materialSpecular = Color.White.ToVector3(); texPhong.materialPower = 50f; texPhong.specularIntensity = 1f; texPhong.pointLightFalloff = 1f; texPhong.pointLightRange = 300f; texPhong.pointLightPos = swiatloPunktowe; texPhong.pointLightColor = swiatloPunktoweKolor.ToVector4() / 1.5f; ocean.diffuseColor = Color.Gray; ocean.viewPosition = kamera.Position; ocean.diffuseLightDirection = swiatloKierunkowe; ocean.diffuseLightColor = Color.DimGray; ocean.materialEmissive = new Vector3(0f, 0f, 0f); ocean.materialAmbient = new Vector3(.05f, .05f, .1f); ocean.materialDiffuse = Color.White.ToVector3(); phong.materialSpecular = Color.White.ToVector3(); ocean.materialPower = 50f; ocean.specularIntensity = 1f; ocean.pointLightFalloff = 1f; ocean.pointLightRange = 300f; ocean.pointLightPos = swiatloPunktowe; ocean.pointLightColor = swiatloPunktoweKolor.ToVector4() / 1.5f; ocean.Displacement = przesuniecieMorza; krysztal.shader.efekt.Parameters["materialEmissive"].SetValue(swiatloPunktoweKolor.ToVector3()); }
public void DrawAdditive(SpriteBatch spriteBatch) { var tex = GetTexture("StarlightRiver/Assets/Keys/Glow"); var texDisc = GetTexture("StarlightRiver/Assets/Items/Permafrost/AuroraDisc"); float sin = 1 + (float)Math.Sin(-StarlightWorld.rottime); float cos = 1 + (float)Math.Cos(-StarlightWorld.rottime); Color color = new Color(0.5f + cos * 0.2f, 0.8f, 0.5f + sin * 0.2f) * 1.1f; spriteBatch.Draw(tex, projectile.Center - Main.screenPosition, null, color * 0.75f, 0, tex.Size() / 2, 1, 0, 0); spriteBatch.Draw(texDisc, projectile.Center - Main.screenPosition, null, Lighting.GetColor((int)projectile.Center.X / 16, (int)projectile.Center.Y / 16), 0, texDisc.Size() / 2, 1, 0, 0); Lighting.AddLight(projectile.Center, color.ToVector3() * 0.5f); }
public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int heigth, Color color) { Texture2D texture = new Texture2D(graphicsDevice, width, heigth, false, SurfaceFormat.Color); Color[] colors = new Color[width * heigth]; for (int i = 0; i < colors.Length; i++) { colors[i] = new Color(color.ToVector3()); } texture.SetData(colors); return texture; }
public static void Draw(Matrix world, Matrix view, Matrix projection, Color newcolor, float scale, bool isPopulated, float curAngle) { // Set BasicEffect parameters. Matrix worldMatrix = Matrix.CreateScale(scale) * Matrix.CreateRotationZ( (float) ((curAngle / 360.0) * 2 * Math.PI)) * world; basicEffect.World = worldMatrix; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.DiffuseColor = newcolor.ToVector3(); //basicEffect.VertexColorEnabled = true; //basicEffect.Alpha = color.A / 255.0f; basicEffect.EmissiveColor = newcolor.ToVector3(); GraphicsDevice device = basicEffect.GraphicsDevice; device.DepthStencilState = DepthStencilState.Default; device.BlendState = BlendState.AlphaBlend; // Draw the model, using BasicEffect. if (isPopulated) { foreach (ModelMesh mesh in poplulatedPlanet.Meshes) { mesh.Draw(); } } else { foreach (ModelMesh mesh in unpoplulatedPlanet.Meshes) { mesh.Draw(); } } }
public SpaceshipCursor(Scene scene, Vector3 initialPosition, float speed, double visualPriority, Color color, string image, bool visible) : base(scene, initialPosition, speed, visualPriority, image, false) { FrontImage.SizeX = 4; SetBackImage(image + "Back", 4, color); Circle.Radius = FrontImage.Size.X / 2; FiringCursor = new Image("FiringDirection") { SizeX = 4, Alpha = 150, VisualPriority = visualPriority + 0.00001 }; FiringCursor.Origin = new Vector2(FiringCursor.Center.X, FrontImage.Center.Y + 7); Color = color; ShowTrail = true; TrailEffect = Scene.Particles.Get(@"spaceshipTrail"); TrailEffect.Model[0].ReleaseColour = Color.ToVector3(); TrailEffect.VisualPriority = BackImage.VisualPriority + 0.00001; TrailEffect2 = Scene.Particles.Get(@"spaceshipTrail2"); TrailEffect2.VisualPriority = BackImage.VisualPriority + 0.00002; LastPosition = Position; NotMovingReleaseSpeed = new ProjectMercury.VariableFloat() { Value = 50, Variation = 0 }; MovingReleaseSpeed = new ProjectMercury.VariableFloat() { Value = 0, Variation = 25 }; TrailEffect.Model[0].ReleaseSpeed = NotMovingReleaseSpeed; TrailEffect2.Model[0].ReleaseSpeed = NotMovingReleaseSpeed; ShowFiringCursor = false; }
public void InitBeginState(Model block, Model startBlock) { _block = block; _previousColor = _colors[0]; _currentColor = _previousColor; Block.CurrentColor = _currentColor.ToVector3(); _activeBlocks.Clear(); _activeBlocks.Add(new StartBlock(startBlock, Vector3.Zero, _world, _view, _projection)); while (_activeBlocks.Last().GetPositionZ() > -16*MHelper.Sqrt2) { CreateNextBlock(); } }
/// <summary>Create a texture which has C0 in the upper left corner, /// C1 in the upper right corner, C2 in the lower left corner, /// and C3 in the lower right corner, with a smooth shading /// between all points.</summary> public static Texture2D ShadedCornerColor( GraphicsDevice graphicsDevice, Vector2 size, Color c0, Color c1, Color c2, Color c3) { HoloDebug.Assert(size.X > 0); HoloDebug.Assert(size.Y > 0); Vector3 v0 = c0.ToVector3(); Vector3 v1 = c1.ToVector3(); Vector3 v2 = c2.ToVector3(); Vector3 v3 = c3.ToVector3(); // The maximum sum of all distances is 2 + (2 ^ 0.5) (any corner). float sqrt2 = (float)Math.Sqrt(2); // RGBA32 format Color[] data = new Color[(int)size.X * (int)size.Y]; for (int j = 0; j < size.Y; j++) { for (int i = 0; i < size.X; i++) { float fi = (float)i / (float)(size.X - 1); float fj = (float)j / (float)(size.Y - 1); Vector2 currentPoint = new Vector2(fi, fj); float dist0 = Math.Max(0, 1 - Vector2.Distance(new Vector2(0, 0), currentPoint)); float dist1 = Math.Max(0, 1 - Vector2.Distance(new Vector2(1, 0), currentPoint)); float dist2 = Math.Max(0, 1 - Vector2.Distance(new Vector2(0, 1), currentPoint)); float dist3 = Math.Max(0, 1 - Vector2.Distance(new Vector2(1, 1), currentPoint)); Vector3 vectorSum = (v0 * dist0) + (v1 * dist1) + (v2 * dist2) + (v3 * dist3); Vector4 vectorSum1 = new Vector4(vectorSum, 1.0f); Color color = new Color(vectorSum1); data[i + (j * (int)size.X)] = color; } } Texture2D ret = new Texture2D(graphicsDevice, (int)size.X, (int)size.Y, mipMap: true, format: SurfaceFormat.Color); ret.SetData(data); return ret; }
public static void Draw(Matrix world, Matrix view, Matrix projection, Color newcolor) { // Set BasicEffect parameters. basicEffect.World = world; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.DiffuseColor = newcolor.ToVector3(); basicEffect.VertexColorEnabled = true; //basicEffect.Alpha = color.A / 255.0f; //basicEffect.EmissiveColor = newcolor.ToVector3(); GraphicsDevice device = basicEffect.GraphicsDevice; device.DepthStencilState = DepthStencilState.Default; device.BlendState = BlendState.AlphaBlend; // Draw the model, using BasicEffect. Draw(basicEffect); }
public HSVColor(Color color) : this() { Vector3 rgb = color.ToVector3(); A = color.A / 255f; if (A == 0) { rgb = Vector3.Zero; } else { rgb /= A; } float max = Math.Max(rgb.X, Math.Max(rgb.Y, rgb.Z)); float min = Math.Min(rgb.X, Math.Min(rgb.Y, rgb.Z)); V = max; if (max == 0) { H = 0; S = 0; return; } S = (max - min) / max; if (S == 0) { H = 0; return; } if (max == rgb.X) { H = 60f * (rgb.Y - rgb.Z) / (max - min); } else if (max == rgb.Y) { H = 60f * (rgb.Z - rgb.X) / (max - min) + 120f; } else { H = 60f * (rgb.X - rgb.Y) / (max - min) + 240f; } }
/// <summary> /// Renders a Ray for debugging purposes. /// </summary> /// <param name="ray">The ray to render.</param> /// <param name="length">The distance along the ray to render.</param> /// <param name="graphicsDevice">The graphics device to use when rendering.</param> /// <param name="view">The current view matrix.</param> /// <param name="projection">The current projection matrix.</param> /// <param name="color">The color to use drawing the ray.</param> public static void Render(Ray ray, float length, GraphicsDevice graphicsDevice, Matrix view, Matrix projection, Color color) { if (effect == null) { effect = new BasicEffect(graphicsDevice); effect.VertexColorEnabled = false; effect.LightingEnabled = false; } verts[0] = new VertexPositionColor(ray.Position, Color.White); verts[1] = new VertexPositionColor(ray.Position + (ray.Direction * length), Color.White); effect.DiffuseColor = color.ToVector3(); effect.Alpha = (float)color.A / 255f; effect.World = Matrix.Identity; effect.View = view; effect.Projection = projection; //note you may wish to comment these next 2 lines out and set the RasterizerState elswehere in code //rather than here for every ray draw call. RasterizerState rs = graphicsDevice.RasterizerState; graphicsDevice.RasterizerState = RasterizerState.CullNone; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, verts, 0, 1); effect.World = Matrix.Invert(Matrix.CreateLookAt( verts[1].Position, verts[0].Position, (ray.Direction != Vector3.Up) ? Vector3.Up : Vector3.Left)); graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, arrowVerts, 0, 5, arrowIndexs, 0, 4); } //note you may wish to comment the next line out and set the RasterizerState elswehere in code //rather than here for every ray draw call. graphicsDevice.RasterizerState = rs; }
public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int height, Color color) { string key = color.ToString () + width + "x" + height; if (textureCache.ContainsKey (key)) { return textureCache [key]; } else { // create a texture with the specified size Texture2D texture = new Texture2D (graphicsDevice, width, height); // fill it with the specified colors Color[] colors = new Color[width * height]; for (int i = 0; i < colors.Length; i++) { colors [i] = new Color (color.ToVector3 ()); } texture.SetData (colors); textureCache [key] = texture; return texture; } }
/// <summary> /// Creates a texture of the specified color. /// </summary> /// <param name="graphicsDevice">The graphics device to use.</param> /// <param name="width">The width of the texture.</param> /// <param name="height">The height of the texture.</param> /// <param name="color">The color to set the texture to.</param> /// <returns>The newly created texture.</returns> public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int height, Color color) { // create the rectangle texture without colors Texture2D texture = new Texture2D( graphicsDevice, width, height, false, //mipmap SurfaceFormat.Color); // Create a color array for the pixels Color[] colors = new Color[width * height]; for (int i = 0; i < colors.Length; i++) { colors[i] = new Color(color.ToVector3()); } // Set the color data for the texture texture.SetData(colors); return texture; }