public void Render(IBaseRender render) { List <LightSource> lights = new List <LightSource>(); foreach (LightSource light in Component.AllComponentsOfType(typeof(LightSource))) { if (light.Enabled) { lights.Add(light); } } if (lights.Count < 8) { render.ResetAllLights(); foreach (LightSource light in lights) { render.AddLight(light); } foreach (Render comp in Component.AllComponentsOfType(typeof(Render))) { if (comp.Enabled) { comp.Draw(render); } } } else { foreach (Render comp in Component.AllComponentsOfType(typeof(Render))) { if (comp.Enabled) { render.ResetAllLights(); lucesOrdenar = new List <LuzOrdenable>(lights.Count); Vector3 centroLuces = comp.Entity.Transformation.GlobalTranslation; foreach (LightSource light in lights) { lucesOrdenar.Add(new LuzOrdenable(light, (light.Entity.Transformation.GlobalTranslation - centroLuces).LengthSquared)); } lucesOrdenar.Sort(OrdenarLucesPorDistancia); for (int k = 0; k < 8; k++) { render.AddLight(lucesOrdenar[k].light); } comp.Draw(render); } } } }
public override void OnRenderFrame(OpenTK.RenderFrameEventArgs e) { foreach (Camara camara in Component.AllComponentsOfType(typeof(Camara))) { if (camara.Enabled) { Matrix4 matCamara = Matrix4.Invert(camara.Transformation.GlobalMatrix); render.SetCamara(matCamara); break; } } render.BeginDraw(); render.ResetAllLights(); scene.Render(render); render.EndDraw(); SwapBuffers(); }
private void RenderHelpers(bool selection) { if (selection == false) { render.ResetAllLights(); } //Dibujo la grilla if (selection == false && drawGrid) { render.Draw(meshGrid, Matrix4.Identity, RenderMode.Lines); } //Dibujo los objetos de edición if (scene.EditMode) { foreach (LightSource light in Component.AllComponentsOfType(typeof(LightSource))) { if (selection) { GL.LoadName(light.Id); } light.DrawHelper(render); } } if (selectedEntity != null) { //Dibujo las flechas Matrix4 mat = selectedEntity.Transformation.GlobalMatrix; Vector3 scaleObject = selectedEntity.Transformation.GlobalScale; float helperSize = 1.0f; mat = Matrix4.Scale(helperSize / scaleObject.X, helperSize / scaleObject.Y, helperSize / scaleObject.Z) * mat; render.ClearZBuffer(); mat = Matrix4.Translation(0, 1.0f, 0) * mat; if (selection) { GL.LoadName(-2); //Y } render.Draw(meshArrow, mat, RenderMode.Normal, new Color4(0, 1, 0, 0)); render.Draw(meshArrow, mat, RenderMode.Lines, new Color4(0, 0, 0, 0)); mat = Matrix4.Translation(0, -1.0f, -1.0f) * mat; mat = Matrix4.Rotate(Quaternion.FromAxisAngle(Vector3.UnitX, Functions.DegreesToRadians(-90))) * mat; if (selection) { GL.LoadName(-3); //Z } render.Draw(meshArrow, mat, RenderMode.Normal, new Color4(0, 0, 1, 0)); render.Draw(meshArrow, mat, RenderMode.Lines, new Color4(0, 0, 0, 0)); mat = Matrix4.Translation(1.0f, -1.0f, 0.0f) * mat; mat = Matrix4.Rotate(Quaternion.FromAxisAngle(Vector3.UnitZ, Functions.DegreesToRadians(-90))) * mat; if (selection) { GL.LoadName(-1); //X } render.Draw(meshArrow, mat, RenderMode.Normal, new Color4(1, 0, 0, 0)); render.Draw(meshArrow, mat, RenderMode.Lines, new Color4(0, 0, 0, 0)); if (selection == false) { //Dibujo los elementos colisionables que contenga el objeto seleccionado foreach (Collisionable col in selectedEntity.FindChildComponents(typeof(Collisionable))) { col.DrawHelper(render); } } } }