public override void Tick(float deltaTime) { base.Tick(deltaTime); // Sky if (m_vrSky != null) { // Background m_vrSky.Model.SetTevkColorOverride(0, WLinearColor.FromHexString("0x1E3C5AFF")); // Floor m_vrSky.Model.SetTevColorOverride(0, WLinearColor.FromHexString("0xC8FFFFFF")); } // Horizon Color if (m_vrKasumiMae != null) { m_vrKasumiMae.Model.SetTevColorOverride(0, WLinearColor.FromHexString("0x325a82FF")); } // False Sea Color if (m_vrUsoUmi != null) { m_vrUsoUmi.Model.SetTevkColorOverride(0, WLinearColor.FromHexString("0x0A0A3CFF")); } // Cloud Color if (m_vrBackCloud != null) { m_vrBackCloud.Model.SetTevColorOverride(0, WLinearColor.FromHexString("0x8278966E")); } }
public void Render(Matrix4 viewMatrix, Matrix4 projMatrix) { if (m_isDirty) { // We've changed what we want to draw since we last rendered, so we'll re-calculate the mesh and upload. Vector3[] lineVerts = new Vector3[m_batchedLines.Count * 2]; WLinearColor[] lineColors = new WLinearColor[m_batchedLines.Count * 2]; for (int i = 0; i < m_batchedLines.Count; i++) { WBatchedLine batchedLine = m_batchedLines[i]; lineVerts[(i * 2) + 0] = batchedLine.Start; lineVerts[(i * 2) + 1] = batchedLine.End; lineColors[(i * 2) + 0] = batchedLine.Color; lineColors[(i * 2) + 1] = batchedLine.Color; } // Upload Verts GL.BindBuffer(BufferTarget.ArrayBuffer, m_vbo); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(12 * lineVerts.Length), lineVerts, BufferUsageHint.DynamicDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, m_vertColors); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(16 * lineColors.Length), lineColors, BufferUsageHint.DynamicDraw); m_isDirty = false; } // Draw the mesh. GL.FrontFace(FrontFaceDirection.Cw); GL.Enable(EnableCap.CullFace); GL.Disable(EnableCap.Blend); GL.DepthMask(true); //GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); Matrix4 modelMatrix = Matrix4.Identity; m_primitiveShader.Bind(); GL.UniformMatrix4(m_primitiveShader.UniformModelMtx, false, ref modelMatrix); GL.UniformMatrix4(m_primitiveShader.UniformViewMtx, false, ref viewMatrix); GL.UniformMatrix4(m_primitiveShader.UniformProjMtx, false, ref projMatrix); // Position GL.BindBuffer(BufferTarget.ArrayBuffer, m_vbo); GL.EnableVertexAttribArray((int)ShaderAttributeIds.Position); GL.VertexAttribPointer((int)ShaderAttributeIds.Position, 3, VertexAttribPointerType.Float, false, 12, 0); // Color GL.BindBuffer(BufferTarget.ArrayBuffer, m_vertColors); GL.EnableVertexAttribArray((int)ShaderAttributeIds.Color0); GL.VertexAttribPointer((int)ShaderAttributeIds.Color0, 4, VertexAttribPointerType.Float, true, 16, 0); // Draw! GL.DrawArrays(PrimitiveType.Lines, 0, m_batchedLines.Count * 2); GL.DisableVertexAttribArray((int)ShaderAttributeIds.Position); GL.DisableVertexAttribArray((int)ShaderAttributeIds.Color0); }
public static WLinearColor FromHexString(string hexString) { if (string.IsNullOrEmpty(hexString)) { throw new ArgumentException("Empty/Null hex string!", "hexString"); } if (hexString.StartsWith("0x")) { hexString = hexString.Substring(2); } uint WLinearColorVal; bool bSuccess = uint.TryParse(hexString, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out WLinearColorVal); if (!bSuccess) { throw new ArgumentException("Not a valid hex number!", "hexString"); } WLinearColor outputWLinearColor = new WLinearColor(); byte[] bytes = BitConverter.GetBytes(WLinearColorVal); // This is in ABGR for (int i = 0; i < 4; i++) { outputWLinearColor[3 - i] = bytes[i] / 255f; } // This code is untested, comment this out once you've tested it. return(outputWLinearColor); }
public WBatchedQuad(Vector3 position, Vector3 scale, WLinearColor color, bool billboard, float lifetime) { Position = position; Scale = scale; Color = color; IsBillboard = billboard; RemainingLifetime = lifetime; }
public WBatchedLine(Vector3 start, Vector3 end, WLinearColor color, float thickness, float lifetime) { Start = start; End = end; Color = color; Thickness = thickness; RemainingLifetime = lifetime; }
public void DrawQuad(string texture_name, Vector3 position, Vector3 scale, WLinearColor color, float lifetime) { List <WBatchedQuad> tex_list = GetTextureList(texture_name); tex_list.Add(new WBatchedQuad(position, scale, color, false, lifetime)); m_renderStateDirty = true; }
public void DrawBox(Vector3 min, Vector3 max, WLinearColor color, float thickness, float lifetime) { Vector3 center = (max + min) / 2; Vector3 extents = (max - min) / 2; DrawBox(center, extents, Quaternion.Identity, color, lifetime, thickness); m_isDirty = true; }
public void DrawBox(Vector3 center, Vector3 box, Quaternion rotation, WLinearColor color, float lifetime, float thickness) { List <WBatchedLine> lines = new List <WBatchedLine>(); Vector3 start = Vector3.Transform(new Vector3(box.X, box.Y, box.Z), rotation); Vector3 end = Vector3.Transform(new Vector3(box.X, -box.Y, box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(box.X, -box.Y, box.Z), rotation); end = Vector3.Transform(new Vector3(-box.X, -box.Y, box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(-box.X, -box.Y, box.Z), rotation); end = Vector3.Transform(new Vector3(-box.X, box.Y, box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(-box.X, box.Y, box.Z), rotation); end = Vector3.Transform(new Vector3(box.X, box.Y, box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(box.X, box.Y, -box.Z), rotation); end = Vector3.Transform(new Vector3(box.X, -box.Y, -box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(box.X, -box.Y, -box.Z), rotation); end = Vector3.Transform(new Vector3(-box.X, -box.Y, -box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(-box.X, -box.Y, -box.Z), rotation); end = Vector3.Transform(new Vector3(-box.X, box.Y, -box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(-box.X, box.Y, -box.Z), rotation); end = Vector3.Transform(new Vector3(box.X, box.Y, -box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(box.X, box.Y, box.Z), rotation); end = Vector3.Transform(new Vector3(box.X, box.Y, -box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(box.X, -box.Y, box.Z), rotation); end = Vector3.Transform(new Vector3(box.X, -box.Y, -box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(-box.X, -box.Y, box.Z), rotation); end = Vector3.Transform(new Vector3(-box.X, -box.Y, -box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); start = Vector3.Transform(new Vector3(-box.X, box.Y, box.Z), rotation); end = Vector3.Transform(new Vector3(-box.X, box.Y, -box.Z), rotation); lines.Add(new WBatchedLine(center + start, center + end, color, thickness, lifetime)); m_batchedLines.AddRange(lines); m_isDirty = true; }
public override bool Equals(object obj) { if (!(obj is WLinearColor)) { return(false); } WLinearColor other = (WLinearColor)obj; return(this == other); }
public LightingSkyboxColors(EnvironmentLightingSkyboxColors data) { HorizonCloud = data.HorizonCloudColor; CenterCloud = data.CenterCloudColor; Sky = data.SkyColor; FalseSea = data.FalseSeaColor; Horizon = data.HorizonColor; Unknown1 = data.Unknown1; Unknown2 = data.Unknown2; Unknown3 = data.Unknown3; Unknown4 = data.Unknown4; }
override public void Draw(WSceneView view) { base.Draw(view); if (NextNode != null) { WLinearColor color = WLinearColor.Black; if (IsPathSelected) { color = WLinearColor.Green; } m_world.DebugDrawLine(Transform.Position, NextNode.Transform.Position, color, 5f, 0f); } }
public void DrawSphere(Vector3 center, float radius, int segments, WLinearColor color, float lifetime, float thickness) { segments = Math.Max(segments, 4); Vector3 v1, v2, v3, v4; float angleSeg = (float)(2f * Math.PI / (float)segments); float sinY1 = 0f, cosY1 = 1f, sinY2 = 0f, cosY2 = 0f; int numSegmentsY = segments; float latitude = angleSeg; float longitude = 0f; List <WBatchedLine> lines = new List <WBatchedLine>(numSegmentsY * segments * 2); do { sinY2 = (float)Math.Sin(latitude); cosY2 = (float)Math.Cos(latitude); v1 = new Vector3(sinY1, 0f, cosY1) * radius + center; v3 = new Vector3(sinY2, 0f, cosY2) * radius + center; longitude = angleSeg; int numSegmentsX = segments; do { float sinX = (float)Math.Sin(longitude); float cosX = (float)Math.Cos(longitude); v2 = new Vector3((cosX * sinY1), (sinX * sinY1), cosY1) * radius + center; v4 = new Vector3((cosX * sinY2), (sinX * sinY2), cosY2) * radius + center; lines.Add(new WBatchedLine(v1, v2, color, thickness, lifetime)); lines.Add(new WBatchedLine(v1, v3, color, thickness, lifetime)); v1 = v2; v3 = v4; longitude += angleSeg; numSegmentsX--; } while (numSegmentsX > 0); sinY1 = sinY2; cosY1 = cosY2; latitude += angleSeg; numSegmentsY--; } while (numSegmentsY > 0); m_batchedLines.AddRange(lines); m_isDirty = true; }
public static LightingSkyboxColors Lerp(LightingSkyboxColors a, LightingSkyboxColors b, float t) { LightingSkyboxColors interpSkybox = new LightingSkyboxColors(); interpSkybox.Unknown1 = WLinearColor.Lerp(a.Unknown1, b.Unknown1, t); interpSkybox.Unknown2 = WLinearColor.Lerp(a.Unknown2, b.Unknown2, t); interpSkybox.Unknown3 = WLinearColor.Lerp(a.Unknown3, b.Unknown3, t); interpSkybox.Unknown4 = WLinearColor.Lerp(a.Unknown4, b.Unknown4, t); interpSkybox.HorizonCloud = WLinearColor.Lerp(a.HorizonCloud, b.HorizonCloud, t); interpSkybox.CenterCloud = WLinearColor.Lerp(a.CenterCloud, b.CenterCloud, t); interpSkybox.Sky = WLinearColor.Lerp(a.Sky, b.Sky, t); interpSkybox.FalseSea = WLinearColor.Lerp(a.FalseSea, b.FalseSea, t); interpSkybox.Horizon = WLinearColor.Lerp(a.Horizon, b.Horizon, t); return(interpSkybox); }
public static EnvironmentLightingSkyboxPalette Lerp(EnvironmentLightingSkyboxPalette palette_a, EnvironmentLightingSkyboxPalette palette_b, float t) { if (palette_a == null || palette_b == null) { return(new EnvironmentLightingSkyboxPalette()); } EnvironmentLightingSkyboxPalette interpSkybox = new EnvironmentLightingSkyboxPalette(); interpSkybox.Unknown1 = WLinearColor.Lerp(palette_a.Unknown1, palette_b.Unknown1, t); interpSkybox.Unknown2 = WLinearColor.Lerp(palette_a.Unknown2, palette_b.Unknown2, t); interpSkybox.Unknown3 = WLinearColor.Lerp(palette_a.Unknown3, palette_b.Unknown3, t); interpSkybox.Unknown4 = WLinearColor.Lerp(palette_a.Unknown4, palette_b.Unknown4, t); interpSkybox.HorizonCloudColor = WLinearColor.Lerp(palette_a.HorizonCloudColor, palette_b.HorizonCloudColor, t); interpSkybox.CenterCloudColor = WLinearColor.Lerp(palette_a.CenterCloudColor, palette_b.CenterCloudColor, t); interpSkybox.SkyColor = WLinearColor.Lerp(palette_a.SkyColor, palette_b.SkyColor, t); interpSkybox.FalseSeaColor = WLinearColor.Lerp(palette_a.FalseSeaColor, palette_b.FalseSeaColor, t); interpSkybox.HorizonColor = WLinearColor.Lerp(palette_a.HorizonColor, palette_b.HorizonColor, t); return(interpSkybox); }
public LightingPalette Lerp(float t, bool presetA = true) { LightingPalette[] palette = presetA ? TimePresetA : TimePresetB; // Generate a new LightingPalette which is the interpolated values of things. t = WMath.Clamp(t, 0, 1); float scaledT = t * (palette.Length - 1); int lowerIndex = (int)scaledT; int upperIndex = (int)(scaledT + 1f); float newT = scaledT - (int)scaledT; //Console.WriteLine("t: {0} scaledT: {1} lIndex: {2} uIndex: {3} newT: {4}", t, scaledT, lowerIndex, upperIndex, newT); if (upperIndex == palette.Length) { upperIndex = lowerIndex; } LightingPalette interpPalette = new LightingPalette(); interpPalette.Shadow = WLinearColor.Lerp(palette[lowerIndex].Shadow, palette[upperIndex].Shadow, newT); interpPalette.ActorAmbient = WLinearColor.Lerp(palette[lowerIndex].ActorAmbient, palette[upperIndex].ActorAmbient, newT); interpPalette.RoomLight = WLinearColor.Lerp(palette[lowerIndex].RoomLight, palette[upperIndex].RoomLight, newT); interpPalette.RoomAmbient = WLinearColor.Lerp(palette[lowerIndex].RoomAmbient, palette[upperIndex].RoomAmbient, newT); interpPalette.WaveColor = WLinearColor.Lerp(palette[lowerIndex].WaveColor, palette[upperIndex].WaveColor, newT); interpPalette.OceanColor = WLinearColor.Lerp(palette[lowerIndex].OceanColor, palette[upperIndex].OceanColor, newT); interpPalette.UnknownWhite1 = WLinearColor.Lerp(palette[lowerIndex].UnknownWhite1, palette[upperIndex].UnknownWhite1, newT); interpPalette.UnknownWhite2 = WLinearColor.Lerp(palette[lowerIndex].UnknownWhite2, palette[upperIndex].UnknownWhite2, newT); interpPalette.Doorway = WLinearColor.Lerp(palette[lowerIndex].Doorway, palette[upperIndex].Doorway, newT); interpPalette.UnknownColor3 = WLinearColor.Lerp(palette[lowerIndex].UnknownColor3, palette[upperIndex].UnknownColor3, newT); interpPalette.Skybox = LightingSkyboxColors.Lerp(palette[lowerIndex].Skybox, palette[upperIndex].Skybox, newT); interpPalette.Fog = WLinearColor.Lerp(palette[lowerIndex].Fog, palette[upperIndex].Fog, newT); interpPalette.FogNearPlane = WMath.Lerp(palette[lowerIndex].FogNearPlane, palette[upperIndex].FogNearPlane, newT); interpPalette.FogFarPlane = WMath.Lerp(palette[lowerIndex].FogFarPlane, palette[upperIndex].FogFarPlane, newT); return(interpPalette); }
public EnvironmentLightingPalette Lerp(float t, bool presetA = true) { // Generate a new LightingPalette which is the interpolated values of things. t = WMath.Clamp(t, 0, 1); float scaledT = t * (6 - 1); int lowerIndex = (int)scaledT; int upperIndex = (int)(scaledT + 1f); float newT = scaledT - (int)scaledT; EnvironmentLightingPalette palette_a = null; EnvironmentLightingPalette palette_b = null; if (upperIndex == 6) { upperIndex = lowerIndex; } switch ((TimeOfDay)lowerIndex) { case TimeOfDay.Dawn: palette_a = Dawn; break; case TimeOfDay.Morning: palette_a = Morning; break; case TimeOfDay.Noon: palette_a = Noon; break; case TimeOfDay.Afternoon: palette_a = Afternoon; break; case TimeOfDay.Dusk: palette_a = Dusk; break; case TimeOfDay.Night: palette_a = Night; break; } switch ((TimeOfDay)upperIndex) { case TimeOfDay.Dawn: palette_b = Dawn; break; case TimeOfDay.Morning: palette_b = Morning; break; case TimeOfDay.Noon: palette_b = Noon; break; case TimeOfDay.Afternoon: palette_b = Afternoon; break; case TimeOfDay.Dusk: palette_b = Dusk; break; case TimeOfDay.Night: palette_b = Night; break; } //Console.WriteLine("t: {0} scaledT: {1} lIndex: {2} uIndex: {3} newT: {4}", t, scaledT, lowerIndex, upperIndex, newT); EnvironmentLightingPalette interpPalette = new EnvironmentLightingPalette(); interpPalette.ShadowColor = WLinearColor.Lerp(palette_a.ShadowColor, palette_b.ShadowColor, newT); interpPalette.ActorAmbientColor = WLinearColor.Lerp(palette_a.ActorAmbientColor, palette_b.ActorAmbientColor, newT); interpPalette.RoomLightColor = WLinearColor.Lerp(palette_a.RoomLightColor, palette_b.RoomLightColor, newT); interpPalette.RoomAmbientColor = WLinearColor.Lerp(palette_a.RoomAmbientColor, palette_b.RoomAmbientColor, newT); interpPalette.WaveColor = WLinearColor.Lerp(palette_a.WaveColor, palette_b.WaveColor, newT); interpPalette.OceanColor = WLinearColor.Lerp(palette_a.OceanColor, palette_b.OceanColor, newT); interpPalette.UnknownWhite1 = WLinearColor.Lerp(palette_a.UnknownWhite1, palette_b.UnknownWhite1, newT); interpPalette.UnknownWhite2 = WLinearColor.Lerp(palette_a.UnknownWhite2, palette_b.UnknownWhite2, newT); interpPalette.DoorBackfill = WLinearColor.Lerp(palette_a.DoorBackfill, palette_b.DoorBackfill, newT); interpPalette.Unknown3 = WLinearColor.Lerp(palette_a.Unknown3, palette_b.Unknown3, newT); interpPalette.SkyboxPalette = EnvironmentLightingSkyboxPalette.Lerp(palette_a.SkyboxPalette, palette_b.SkyboxPalette, newT); interpPalette.FogColor = WLinearColor.Lerp(palette_a.FogColor, palette_b.FogColor, newT); interpPalette.FogNearPlane = WMath.Lerp(palette_a.FogNearPlane, palette_b.FogNearPlane, newT); interpPalette.FogFarPlane = WMath.Lerp(palette_a.FogFarPlane, palette_b.FogFarPlane, newT); return(interpPalette); }
public void Draw(WSceneView view) { foreach (string s in m_batchedQuads.Keys) { Bitmap texture = m_Textures[s]; List <WBatchedQuad> quads = m_batchedQuads[s]; if (m_renderStateDirty) { // We've changed what we want to draw since we last rendered, so we'll re-calculate the mesh and upload. Vector3[] quadVerts = new Vector3[quads.Count * 4]; Vector2[] quadUVs = new Vector2[quads.Count * 4]; WLinearColor[] quadColors = new WLinearColor[quads.Count * 4]; for (int i = 0; i < quads.Count; i++) { WBatchedQuad batchedQuad = quads[i]; // Top left quadVerts[(i * 4) + 0] = batchedQuad.IsBillboard ? CalculateBillboardVertex(view, batchedQuad.Position, new Vector3(-0.5f * batchedQuad.Scale.X, 0.5f * batchedQuad.Scale.Y, 0.0f)) : CalculateQuadVertex(batchedQuad.Position, new Vector3(-0.5f * batchedQuad.Scale.X, 0.5f * batchedQuad.Scale.Y, 0.0f)); // Top right quadVerts[(i * 4) + 1] = batchedQuad.IsBillboard ? CalculateBillboardVertex(view, batchedQuad.Position, new Vector3(0.5f * batchedQuad.Scale.X, 0.5f * batchedQuad.Scale.Y, 0.0f)) : CalculateQuadVertex(batchedQuad.Position, new Vector3(0.5f * batchedQuad.Scale.X, 0.5f * batchedQuad.Scale.Y, 0.0f)); // Bottom left quadVerts[(i * 4) + 3] = batchedQuad.IsBillboard ? CalculateBillboardVertex(view, batchedQuad.Position, new Vector3(-0.5f * batchedQuad.Scale.X, -0.5f * batchedQuad.Scale.Y, 0.0f)) : CalculateQuadVertex(batchedQuad.Position, new Vector3(-0.5f * batchedQuad.Scale.X, -0.5f * batchedQuad.Scale.Y, 0.0f)); // Bottom right quadVerts[(i * 4) + 2] = batchedQuad.IsBillboard ? CalculateBillboardVertex(view, batchedQuad.Position, new Vector3(0.5f * batchedQuad.Scale.X, -0.5f * batchedQuad.Scale.Y, 0.0f)) : CalculateQuadVertex(batchedQuad.Position, new Vector3(0.5f * batchedQuad.Scale.X, -0.5f * batchedQuad.Scale.Y, 0.0f)); quadColors[(i * 4) + 0] = batchedQuad.Color; quadColors[(i * 4) + 1] = batchedQuad.Color; quadColors[(i * 4) + 2] = batchedQuad.Color; quadColors[(i * 4) + 3] = batchedQuad.Color; quadUVs[(i * 4) + 0] = new Vector2(0, 0); quadUVs[(i * 4) + 1] = new Vector2(1, 0); quadUVs[(i * 4) + 2] = new Vector2(1, 1); quadUVs[(i * 4) + 3] = new Vector2(0, 1); } // Upload Verts GL.BindBuffer(BufferTarget.ArrayBuffer, m_vbo); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(12 * quadVerts.Length), quadVerts, BufferUsageHint.DynamicDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, m_uvs); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(8 * quadUVs.Length), quadUVs, BufferUsageHint.DynamicDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, m_vertColors); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(16 * quadColors.Length), quadColors, BufferUsageHint.DynamicDraw); GL.BindTexture(TextureTarget.Texture2D, m_Tex); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); System.Drawing.Imaging.BitmapData tex_data = texture.LockBits(new System.Drawing.Rectangle(0, 0, texture.Width, texture.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.Width, texture.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, tex_data.Scan0); texture.UnlockBits(tex_data); //m_renderStateDirty = false; } // Draw the mesh. GL.FrontFace(FrontFaceDirection.Ccw); GL.Disable(EnableCap.CullFace); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Blend); GL.DepthMask(true); GL.Enable(EnableCap.AlphaTest); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); Matrix4 modelMatrix = Matrix4.Identity; Matrix4 viewMatrix = view.ViewMatrix; Matrix4 projMatrix = view.ProjMatrix; m_primitiveShader.Bind(); GL.UniformMatrix4(m_primitiveShader.UniformModelMtx, false, ref modelMatrix); GL.UniformMatrix4(m_primitiveShader.UniformViewMtx, false, ref viewMatrix); GL.UniformMatrix4(m_primitiveShader.UniformProjMtx, false, ref projMatrix); // Position GL.BindBuffer(BufferTarget.ArrayBuffer, m_vbo); GL.EnableVertexAttribArray((int)ShaderAttributeIds.Position); GL.VertexAttribPointer((int)ShaderAttributeIds.Position, 3, VertexAttribPointerType.Float, false, 12, 0); // UVs GL.BindBuffer(BufferTarget.ArrayBuffer, m_uvs); GL.EnableVertexAttribArray((int)ShaderAttributeIds.Tex0); GL.VertexAttribPointer((int)ShaderAttributeIds.Tex0, 2, VertexAttribPointerType.Float, false, 8, 0); // Color GL.BindBuffer(BufferTarget.ArrayBuffer, m_vertColors); GL.EnableVertexAttribArray((int)ShaderAttributeIds.Color0); GL.VertexAttribPointer((int)ShaderAttributeIds.Color0, 4, VertexAttribPointerType.Float, true, 16, 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, m_Tex); // Draw! GL.DrawArrays(PrimitiveType.Quads, 0, quads.Count * 4); GL.FrontFace(FrontFaceDirection.Cw); GL.Enable(EnableCap.CullFace); GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.AlphaTest); GL.DepthMask(false); GL.DisableVertexAttribArray((int)ShaderAttributeIds.Position); GL.DisableVertexAttribArray((int)ShaderAttributeIds.Tex0); GL.DisableVertexAttribArray((int)ShaderAttributeIds.Color0); GL.BindTexture(TextureTarget.Texture2D, -1); } }
public static WLinearColor FromHexString(string hexString) { if (string.IsNullOrEmpty(hexString)) throw new ArgumentException("Empty/Null hex string!", "hexString"); if (hexString.StartsWith("0x")) hexString = hexString.Substring(2); uint WLinearColorVal; bool bSuccess = uint.TryParse(hexString, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out WLinearColorVal); if (!bSuccess) throw new ArgumentException("Not a valid hex number!", "hexString"); WLinearColor outputWLinearColor = new WLinearColor(); byte[] bytes = BitConverter.GetBytes(WLinearColorVal); // This is in ABGR for (int i = 0; i < 4; i++) outputWLinearColor[3-i] = bytes[i] / 255f; // This code is untested, comment this out once you've tested it. return outputWLinearColor; }
public void DrawLine(Vector3 start, Vector3 end, WLinearColor color, float thickness, float lifetime) { m_batchedLines.Add(new WBatchedLine(start, end, color, thickness, lifetime)); m_isDirty = true; }
private void WriteActorToChunk(WActorNode actor, MapActorDescriptor template, EndianBinaryWriter writer) { // Just convert their rotation to Euler Angles now instead of doing it in parts later. Vector3 eulerRot = actor.Transform.Rotation.ToEulerAngles(); foreach (var field in template.Fields) { IPropertyValue propValue = actor.Properties.Find(x => x.Name == field.FieldName); if (field.FieldName == "Position") { propValue = new TVector3PropertyValue(actor.Transform.Position, "Position"); } else if (field.FieldName == "X Rotation") { short xRotShort = WMath.RotationFloatToShort(eulerRot.X); propValue = new TShortPropertyValue(xRotShort, "X Rotation"); } else if (field.FieldName == "Y Rotation") { short yRotShort = WMath.RotationFloatToShort(eulerRot.Y); propValue = new TShortPropertyValue(yRotShort, "Y Rotation"); } else if (field.FieldName == "Z Rotation") { short zRotShort = WMath.RotationFloatToShort(eulerRot.Z); propValue = new TShortPropertyValue(zRotShort, "Z Rotation"); } else if (field.FieldName == "X Scale") { float xScale = actor.Transform.LocalScale.X; propValue = new TBytePropertyValue((byte)(xScale * 10), "X Scale"); } else if (field.FieldName == "Y Scale") { float yScale = actor.Transform.LocalScale.Y; propValue = new TBytePropertyValue((byte)(yScale * 10), "Y Scale"); } else if (field.FieldName == "Z Scale") { float zScale = actor.Transform.LocalScale.Z; propValue = new TBytePropertyValue((byte)(zScale * 10), "Z Scale"); } switch (field.FieldType) { case PropertyValueType.Byte: writer.Write((byte)propValue.GetValue()); break; case PropertyValueType.Bool: writer.Write((bool)propValue.GetValue()); break; case PropertyValueType.Short: writer.Write((short)propValue.GetValue()); break; case PropertyValueType.Int: writer.Write((int)propValue.GetValue()); break; case PropertyValueType.Float: writer.Write((float)propValue.GetValue()); break; case PropertyValueType.String: writer.Write(System.Text.Encoding.ASCII.GetBytes((string)propValue.GetValue())); break; case PropertyValueType.FixedLengthString: string fixedLenStr = (string)propValue.GetValue(); for (int i = 0; i < field.Length; i++) { writer.Write(i < fixedLenStr.Length ? (byte)fixedLenStr[i] : (byte)0); } //writer.WriteFixedString((string)propValue.GetValue(), (int)field.Length); break; break; case PropertyValueType.Vector2: Vector2 vec2Val = (Vector2)propValue.GetValue(); writer.Write(vec2Val.X); writer.Write(vec2Val.Y); break; case PropertyValueType.Vector3: Vector3 vec3Val = (Vector3)propValue.GetValue(); writer.Write(vec3Val.X); writer.Write(vec3Val.Y); writer.Write(vec3Val.Z); break; case PropertyValueType.XRotation: case PropertyValueType.YRotation: case PropertyValueType.ZRotation: writer.Write((short)propValue.GetValue()); break; case PropertyValueType.Color24: WLinearColor color24 = (WLinearColor)propValue.GetValue(); writer.Write((byte)color24.R); writer.Write((byte)color24.G); writer.Write((byte)color24.B); break; case PropertyValueType.Color32: WLinearColor color32 = (WLinearColor)propValue.GetValue(); writer.Write((byte)color32.R); writer.Write((byte)color32.G); writer.Write((byte)color32.B); writer.Write((byte)color32.A); break; default: Console.WriteLine("Unsupported PropertyValueType: {0}", field.FieldType); break; } } }
public static WLinearColor Lerp(WLinearColor a, WLinearColor b, float t) { t = WMath.Clamp(t, 0, 1); return new WLinearColor((1 - t) * a.R + t * b.R, (1 - t) * a.G + t * b.G, (1 - t) * a.B + t * b.B, (1 - t) * a.A + t * b.A); }
public void DebugDrawLine(Vector3 start, Vector3 end, WLinearColor color, float thickness, float lifetime) { m_persistentLines.DrawLine(start, end, color, thickness, lifetime); }
public void DebugDrawBox(Vector3 center, Vector3 extents, Quaternion rotation, WLinearColor color, float thickness, float lifetime) { m_persistentLines.DrawBox(center, extents, rotation, color, lifetime, thickness); }
public void DebugDrawBox(Vector3 min, Vector3 max, WLinearColor color, float thickness, float lifetime) { m_persistentLines.DrawBox(min, max, color, thickness, lifetime); }
public void DebugDrawBillboard(string texture_name, Vector3 position, Vector3 scale, WLinearColor color, float lifetime) { m_persistentQuads.DrawBillboard(texture_name, position, scale, color, lifetime); }
public static WLinearColor Lerp(WLinearColor a, WLinearColor b, float t) { t = WMath.Clamp(t, 0, 1); return(new WLinearColor((1 - t) * a.R + t * b.R, (1 - t) * a.G + t * b.G, (1 - t) * a.B + t * b.B, (1 - t) * a.A + t * b.A)); }