private unsafe void RebuildConeVertexBuffer(CommandList commandList, LightSpot lightSpot) { var mappedVertices = commandList.MapSubresource(vertexBuffer, 0, MapMode.WriteDiscard); var vertexPointer = mappedVertices.DataBox.DataPointer; var vertex = (VertexPositionNormalTexture *)vertexPointer; // the two ring var angleOuter = Math.Max(lightSpot.AngleInner, lightSpot.AngleOuter); for (int i = 0; i < 4 * Tesselation; i++) { var z = -lightSpot.Range; var theta = 2 * i * MathUtil.Pi / (4 * Tesselation); var radiusBeam = Math.Abs(z) * (float)Math.Tan(MathUtil.DegreesToRadians(angleOuter / 2)); vertex[i].Position = new Vector3(radiusBeam * (float)Math.Cos(theta), radiusBeam * (float)Math.Sin(theta), z); vertex[i].Normal = new Vector3(0, 0, -1); } // the origin point vertex[4 * Tesselation].Position = Vector3.Zero; vertex[4 * Tesselation].Normal = new Vector3(0, 0, -1); commandList.UnmapSubresource(mappedVertices); }
public void Build(CommandList commandList, LightSpot lightSpot) { int[] indices; if (lightSpot.ProjectiveTexture != null) // If no projection texture has been supplied, we render the regular cone: { indices = BuildRectangleIndexBuffer(); vertexBuffer = Buffer.Vertex.New(graphicsDevice, new VertexPositionNormalTexture[9], GraphicsResourceUsage.Dynamic); RebuildRectangleVertexBuffer(commandList, lightSpot); } else // If a projection texture has been supplied, we render a rectangular frustum instead: { indices = BuildConeIndexBuffer(); vertexBuffer = Buffer.Vertex.New(graphicsDevice, new VertexPositionNormalTexture[4 * Tesselation + 1], GraphicsResourceUsage.Dynamic); RebuildConeVertexBuffer(commandList, lightSpot); } MeshDraw = new MeshDraw { PrimitiveType = PrimitiveType.LineList, DrawCount = indices.Length, IndexBuffer = new IndexBufferBinding(Buffer.Index.New(graphicsDevice, indices), true, indices.Length), VertexBuffers = new[] { new VertexBufferBinding(vertexBuffer, VertexPositionNormalTexture.Layout, vertexBuffer.ElementCount) }, }; }
private void objectFromTemplate() { PhysModel curModel; switch (template.useType) { case Template.UseType.Animated: curModel = new AnimatedModel(Scene); break; default: curModel = new PhysModel(Scene); break; } curModel.Materials = template.materials; curModel.Meshes = template.meshes; curModel.Position = ghost.Position; curModel.PhysBoxes = template.pmeshes; curModel.IsStatic = template.isStatic; curModel.Name = Scene.getUniqueName(); curModel.Orientation = ghost.Orientation; if (template.hasLight && Scene.lightCount < ShaderLoader.maxNoLights) { Light mLight = new LightSpot(curModel); mLight.Color = new Vector4(template.lightColor, 1); } }
private void ResetSpot() { LightSpot.SetValue(Canvas.LeftProperty, 0.0); LightSpot.SetValue(Canvas.TopProperty, 0.0); //LightSpot.Width = LightSpot.Height = 100.0; LightSpotScaleTransform.ScaleX = 1.0; LightSpotScaleTransform.ScaleY = 1.0; LightSpot.UpdateLayout(); }
public void Rebuild(CommandList commandList, LightSpot lightSpot) { if (lightSpot.ProjectiveTexture != null) { RebuildRectangleVertexBuffer(commandList, lightSpot); } else { RebuildConeVertexBuffer(commandList, lightSpot); // TODO (?): This ignores the aspect ratio. } }
private void MoveSpot(double delta_x, double delta_y) { if (IsEditMode == false) { return; } LightSpotX += delta_x * MoveSpeed; LightSpotY += delta_y * MoveSpeed; LightSpot.SetValue(Canvas.LeftProperty, LightSpotX); LightSpot.SetValue(Canvas.TopProperty, LightSpotY); }
private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (IsEditMode == false) { return; } var point = e.GetPosition(this.SpotCanvas); LightSpotX = point.X; LightSpotY = point.Y; LightSpot.SetValue(Canvas.LeftProperty, LightSpotX); LightSpot.SetValue(Canvas.TopProperty, LightSpotY); }
void CheckLightHit() { if (playerController.colorStatus == 0) { for (int i = 0; i < gameManager.blueLight.Length; i++) { LightSpot lightSpot = gameManager.blueLight[i].GetComponentInChildren <LightSpot>(); if (lightSpot.hitPlayer == false) { playerController.PlayerDeath(); } } } else if (playerController.colorStatus == 1) { for (int i = 0; i < gameManager.redLight.Length; i++) { LightSpot lightSpot = gameManager.redLight[i].GetComponentInChildren <LightSpot>(); if (lightSpot.hitPlayer == false) { playerController.PlayerDeath(); } } } else if (playerController.colorStatus == 2) { for (int i = 0; i < gameManager.greenLight.Length; i++) { LightSpot lightSpot = gameManager.greenLight[i].GetComponentInChildren <LightSpot>(); if (lightSpot.hitPlayer == false) { playerController.PlayerDeath(); } } } }
private unsafe void RebuildRectangleVertexBuffer(CommandList commandList, LightSpot lightSpot) { var mappedVertices = commandList.MapSubresource(vertexBuffer, 0, MapMode.WriteDiscard); var vertexPointer = mappedVertices.DataBox.DataPointer; var vertex = (VertexPositionNormalTexture *)vertexPointer; Vector3 normal = new Vector3(0, 0, -1); // The origin point: vertex[0].Position = Vector3.Zero; vertex[0].Normal = normal; // The four corners at the end: float angleOuterInRadians = MathUtil.DegreesToRadians(Math.Max(lightSpot.AngleInner, lightSpot.AngleOuter)); float y = (float)Math.Tan(angleOuterInRadians / 2.0f) * lightSpot.Range; // TODO: Is this correct? //float y = (float)Math.Tan(lightSpot.AngleOuter) * lightSpot.Range * 2.0f; // TODO: Is this correct? float x = y * lightSpot.AspectRatio; // TODO: Is this correct? vertex[1].Position = new Vector3(-x, -y, -lightSpot.Range); vertex[1].Normal = normal; vertex[2].Position = new Vector3(x, -y, -lightSpot.Range); vertex[2].Normal = normal; vertex[3].Position = new Vector3(x, y, -lightSpot.Range); vertex[3].Normal = normal; vertex[4].Position = new Vector3(-x, y, -lightSpot.Range); vertex[4].Normal = normal; // Projection plane corners: float projectionPlaneDistance = Math.Min(lightSpot.ProjectionPlaneDistance, lightSpot.Range); float projectionPlaneX = x / lightSpot.Range * projectionPlaneDistance; float projectionPlaneY = y / lightSpot.Range * projectionPlaneDistance; vertex[5].Position = new Vector3(-projectionPlaneX, -projectionPlaneY, -projectionPlaneDistance); vertex[5].Normal = normal; vertex[6].Position = new Vector3(projectionPlaneX, -projectionPlaneY, -projectionPlaneDistance); vertex[6].Normal = normal; vertex[7].Position = new Vector3(projectionPlaneX, projectionPlaneY, -projectionPlaneDistance); vertex[7].Normal = normal; vertex[8].Position = new Vector3(-projectionPlaneX, projectionPlaneY, -projectionPlaneDistance); vertex[8].Normal = normal; commandList.UnmapSubresource(mappedVertices); }
/// <summary> /// Draw all shadows which entities casts amount the level /// </summary> /// <param name="lightArea"></param> /// <param name="color"></param> public virtual void DrawEntitiesShadowCasters(GameTime gameTime, SpriteBatch batcher, LightSpot lightArea, Color color) { Services.Camera.Zoom = CameraShadowEntityDepth; batcher.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Services.Camera.GetViewMatrix(Vector2.One)); foreach (var entity in Entities) { entity.DrawRelativelyToLightSpot(gameTime, batcher, lightArea, color); } batcher.End(); Services.Camera.Zoom = 1.0f; }
public override void DrawRelativelyToLightSpot(GameTime gameTime, SpriteBatch batcher, LightSpot lightArea, Color color) { batcher.Draw(Sprite, lightArea.ToRelativePosition(WPosition), AniManager.CurrentAnimation.CurrentRectangle, color, Angle, Vector2.One, ResScale, Direction, .0f); if (AniManager.CurrentAnimation != AniManager.Animations[AnimationState.JUMP]) { batcher.Draw(Sprite, lightArea.ToRelativePosition(ArmWPosition), AniManager.Animations[AnimationState.FIRE].CurrentRectangle, color, FireAngle, Vector2.One, ResScale, Direction, .0f); } }
protected void genericLoad(ref XmlTextReader reader, string type) { if (reader.Name == PhysModel.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { childname = reader.Value; } } GameObject child = new PhysModel(this); child.Name = childname; child.load(ref reader, "pmodel"); } if (reader.Name == AnimatedModel.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { childname = reader.Value; } } GameObject child = new AnimatedModel(this); child.Name = childname; child.load(ref reader, "animodel"); } if (reader.Name == MetaModel.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { childname = reader.Value; } } GameObject child = new MetaModel(this); child.Name = childname; child.load(ref reader, "metamodel"); } if (reader.Name == LightSpot.nodename) { string childname = scene.getUniqueName(); while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { childname = reader.Value; } } GameObject child = new LightSpot(this); child.Name = childname; child.load(ref reader, "lamp"); } if (reader.Name == "position" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); Position = GenericMethods.VectorFromString(reader.Value); } if (reader.Name == "direction" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); PointingDirection = GenericMethods.VectorFromString(reader.Value); } if (reader.Name == "color" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); Color = new Vector4(GenericMethods.VectorFromString(reader.Value), 1); } if (reader.Name == "rotation" && reader.NodeType != XmlNodeType.EndElement) { reader.Read(); Orientation = GenericMethods.ToOpenTKMatrix(GenericMethods.JMatrixFromString(reader.Value)); } }
/// <summary> /// Draw entity relatively to light spot, to draw shadow map for shader /// </summary> public virtual void DrawRelativelyToLightSpot(GameTime gameTime, SpriteBatch batcher, LightSpot lightArea, Color color) { }