public void Iteration(ref EntityChunk chunk, int index) { if (chunk.TryGetComponent(index, out C_Position position)) { position.value.y += (MathUtils.Sin((float)EntygineApp.EngineTime)) * 0.01f; chunk.SetComponent(index, position); } }
public void Iteration(ref EntityChunk chunk) { if (!chunk.TryGetComponents <C_Camera>(out ComponentArray cameras) || !chunk.TryGetComponents <C_Transform>(out ComponentArray transforms)) { return; } CameraData[] cameraDatas = new CameraData[chunk.Count]; Matrix4[] cameraTransforms = new Matrix4[chunk.Count]; for (int c = 0; c < chunk.Count; c++) { C_Camera cam = cameras.Get <C_Camera>(c); if (cam.cameraData.Framebuffer == null) { Vec2i res = AppScreen.Resolution; var fb = new Framebuffer(res, "Camera FBO"); fb.AddColorBuffer(true); fb.AddDepthBuffer(true); cam.cameraData.SetFramebuffer(fb); var ffb = new Framebuffer(res, "Camera Final FBO"); ffb.AddColorBuffer(false); cam.cameraData.SetFinalFramebuffer(ffb); chunk.SetComponent(c, cam); } else if (cam.cameraData.Framebuffer.Size != AppScreen.Resolution) { cam.cameraData.Framebuffer.ChangeSize(AppScreen.Resolution); cam.cameraData.FinalFramebuffer.ChangeSize(AppScreen.Resolution); } //if(cam.cameraData.ColorTargetTexture == null) //{ // Vec2i res = AppScreen.Resolution; // cam.cameraData.SetColorTargetTexture(new Texture2D(res.x, res.y, "Camera Color FBO")); // cam.cameraData.SetDepthTargetTexture(new DepthTexture(res.x, res.y, "Camera Depth")); // chunk.SetComponent(c, cam); //} //else if (cam.cameraData.ColorTargetTexture.Size != AppScreen.Resolution) //{ // cam.cameraData.ColorTargetTexture.SetSize(AppScreen.Resolution); // cam.cameraData.DepthTargetTexture.SetSize(AppScreen.Resolution); //} cameraDatas[c] = cam.cameraData; cameraTransforms[c] = transforms.Get <C_Transform>(c).value; } RenderPipelineCore.Draw(cameraDatas, cameraTransforms); }
public void Iteration(ref EntityChunk chunk, int index) { if (!chunk.TryGetComponent(index, out C_EditorCamera editorCamera) || !chunk.TryGetComponent(index, out C_Transform transform)) { return; } editorCamera.speed += speedDelta * deltaTime; editorCamera.speed = MathHelper.Clamp(editorCamera.speed, 0, 100); editorCamera.focusDistance -= distDelta * deltaTime * 100; editorCamera.yaw += rotDelta.X * deltaTime * editorCamera.sensitivity; editorCamera.pitch += rotDelta.Y * deltaTime * editorCamera.sensitivity; Vector3 dir = new Vector3( (float)MathHelper.Cos(MathHelper.DegreesToRadians(editorCamera.yaw)) * (float)MathHelper.Cos(MathHelper.DegreesToRadians(editorCamera.pitch)) , (float)MathHelper.Sin(MathHelper.DegreesToRadians(editorCamera.pitch)) , (float)MathHelper.Sin(MathHelper.DegreesToRadians(editorCamera.yaw)) * (float)MathHelper.Cos(MathHelper.DegreesToRadians(editorCamera.pitch))); Vector3 right = Vector3.Normalize(Vector3.Cross(dir, Vector3.UnitY)); Vector3 up = Vector3.Normalize(Vector3.Cross(right, dir)); Vector3 posDeltaRelative = -right * posDelta.X + dir * posDelta.Z + Vector3.UnitY * posDelta.Y; posDeltaRelative *= deltaTime; editorCamera.focusPoint += posDeltaRelative * editorCamera.speed; transform.value = Matrix4.LookAt(editorCamera.focusPoint + dir * editorCamera.focusDistance, editorCamera.focusPoint, up); //DevGizmos.DrawPoint((Vec3f)editorCamera.focusPoint); DevGizmos.DrawLine((Vec3f)editorCamera.focusPoint, (Vec3f)editorCamera.focusPoint + Vec3f.Right); chunk.SetComponent(index, transform); chunk.SetComponent(index, editorCamera); }