// Init is called on startup. public override void Init() { // Set the clear color for the backbuffer to light green (intensities in R, G, B, A). RC.ClearColor = new float4(0.7f, 1.0f, 0.5f, 1.0f); // Create a scene with a cube // The three components: one XForm, one Material and the Mesh _cubeTransform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0) }; var cubeShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0, 0, 1), new float3(1, 1, 1), 4) }; var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10)); // Assemble the cube node containing the three components var cubeNode = new SceneNodeContainer(); cubeNode.Components = new List <SceneComponentContainer>(); cubeNode.Components.Add(_cubeTransform); cubeNode.Components.Add(cubeShader); cubeNode.Components.Add(cubeMesh); // Create the scene containing the cube as the only object _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); _scene.Children.Add(cubeNode); // Create a scene renderer holding the scene above _sceneRenderer = new SceneRenderer(_scene); }
// Init is called on startup. public override void Init() { // Set the clear color for the backbuffer to light green (intensities in R, G, B, A). RC.ClearColor = new float4(0.5f, 0.5f, 0.5f, 1.0f); //Create a scene with a cube // The three components: one XFrom, one Shade the Mesh _cubeTransform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0) }; var cubeShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0, 1, 1), new float3(1, 1, 1), 4) }; var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10)); var cubeNode = new SceneNodeContainer(); cubeNode.Components = new List <SceneComponentContainer>(); cubeNode.Components.Add(_cubeTransform); cubeNode.Components.Add(cubeShader); cubeNode.Components.Add(cubeMesh); //cube 2 _cubeTransform2 = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, -20) }; cubeShader2 = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(1, 0, 0.4f), new float3(1, 1, 1), 4) }; var cubeMesh2 = SimpleMeshes.CreateCuboid(new float3(10, 10, 10)); var cubeNode2 = new SceneNodeContainer(); cubeNode2.Components = new List <SceneComponentContainer>(); cubeNode2.Components.Add(_cubeTransform2); cubeNode2.Components.Add(cubeShader2); cubeNode2.Components.Add(cubeMesh); //scene load _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); _scene.Children.Add(cubeNode); _scene.Children.Add(cubeNode2); _sceneRenderer = new SceneRenderer(_scene); }
// RenderAFrame is called once a frame public override void RenderAFrame() { SetProjectionAndViewport(); _rightRearTransform.Rotation = new float3(M.MinAngle(TimeSinceStart), 0, 0); // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Setup the camera RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0)); if (Mouse.LeftButton) { float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1); _scenePicker.View = RC.View; _scenePicker.Projection = RC.Projection; List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList(); PickResult newPick = null; if (pickResults.Count > 0) { pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z)); newPick = pickResults[0]; } if (newPick?.Node != _currentPick?.Node) { if (_currentPick != null) { ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>(); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor); } if (newPick != null) { ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>(); _oldColor = (float4)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor"); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float4(1, 0.4f, 0.4f, 1)); } _currentPick = newPick; } } // Render the scene on the current render context _sceneRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer. Present(); }
// Init is called on startup. public override void Init() { // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A). RC.ClearColor = new float4(0.7f, 1.0f, 0.5f, 1.0f); // Create five cubes _cubes = new SceneNodeContainer[5]; for (int i = 0; i < 5; i++) { var cubeTransform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3((i - 3) * 10, 0, 0) }; var cubeShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(1, 1, 1), new float3(1, 1, 1), i) }; var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10)); var cubeNode = new SceneNodeContainer(); cubeNode.Components = new List <SceneComponentContainer>(); cubeNode.Components.Add(cubeTransform); cubeNode.Components.Add(cubeShader); cubeNode.Components.Add(cubeMesh); _cubes[i] = cubeNode; } // Create the scene containing the cubes _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); foreach (SceneNodeContainer cube in _cubes) { _scene.Children.Add(cube); } // Create a scene renderer holding the scene above _sceneRenderer = new SceneRenderer(_scene); }
// Init is called on startup. public override void Init() { // Set the clear color for the backbuffer to white (100% intensity in all color channels R, G, B, A). RC.ClearColor = new float4(0.8f, 0.9f, 0.7f, 1); _scene = AssetStorage.Get <SceneContainer>("Bagger.fus"); _WheelVLTransform = _scene.Children.FindNodes(node => node.Name == "WheelVL")?.FirstOrDefault()?.GetTransform(); _WheelVRTransform = _scene.Children.FindNodes(node => node.Name == "WheelVR")?.FirstOrDefault()?.GetTransform(); _WheelHLTransform = _scene.Children.FindNodes(node => node.Name == "WheelHL")?.FirstOrDefault()?.GetTransform(); _WheelHRTransform = _scene.Children.FindNodes(node => node.Name == "WheelHR")?.FirstOrDefault()?.GetTransform(); _ArmTransform = _scene.Children.FindNodes(node => node.Name == "Arm")?.FirstOrDefault()?.GetTransform(); _SchaufelTransform = _scene.Children.FindNodes(node => node.Name == "Schaufel")?.FirstOrDefault()?.GetTransform(); _BodyTransform = _scene.Children.FindNodes(node => node.Name == "Body")?.FirstOrDefault()?.GetTransform(); _WheelVLShader = _scene.Children.FindNodes(node => node.Name == "WheelVL")?.FirstOrDefault()?.GetComponent <ShaderEffectComponent>(); //_WheelVLShader.SetEffectParam("DiffuseColor", new float3(1, 0.4f, 0.4f)); // Create a scene renderer holding the scene above _sceneRenderer = new SceneRenderer(_scene); _scenePicker = new ScenePicker(_scene); }
public void addCube(int amount) { for (int i = 0; i < amount; i++) { _cubeTransform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3((float)random.Next(-50, 50), (float)random.Next(-50, 50), (float)random.Next(-50, 50)) }; var cubeShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3((float)1 / (i + 1), (float)1 / (i + 1), (float)1 / (i + 1)), new float3(1, 1, 1), 4) }; var cubeMesh = SimpleMeshes.CreateCuboid(new float3(random.Next(5, 20), random.Next(5, 20), random.Next(5, 20))); //assemble cube node var cubeNode = new SceneNodeContainer(); cubeNode.Components = new List <SceneComponentContainer>(); cubeNode.Components.Add(_cubeTransform); cubeNode.Components.Add(cubeShader); cubeNode.Components.Add(cubeMesh); _scene.Children.Add(cubeNode); } }
SceneContainer CreateScene() { // Initialize Transform Components that need to be changed inside "RenderAFrame" _baseTransform = new TransformComponent { Rotation = new float3(0, M.Pi / 2, 0), Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0) }; _bodyTransform = new TransformComponent { Rotation = new float3(0, 0, 0), Scale = new float3(1, 1, 1), Translation = new float3(0, 6, 0) }; _upperArmJointTransform = new TransformComponent { Rotation = new float3(M.Pi / 4, 0, 0), Scale = new float3(1, 1, 1), Translation = new float3(2, 4, 0) }; _upperArmTransform = new TransformComponent { Rotation = new float3(0, 0, 0), Scale = new float3(1, 1, 1), Translation = new float3(0, 4, 0) }; _foreArmJointTransform = new TransformComponent { Rotation = new float3(M.Pi / 4, 0, 0), Scale = new float3(1, 1, 1), Translation = new float3(-2, 4, 0) }; _foreArmTransform = new TransformComponent { Rotation = new float3(0, 0, 0), Scale = new float3(1, 1, 1), Translation = new float3(0, 4, 0) }; _prehensileRailTransform = new TransformComponent { Rotation = new float3(0, 0, 0), Scale = new float3(1, 1, 1), Translation = new float3(0, 5.5f, 0) }; _prehensileClawLeftTransform = new TransformComponent { Rotation = new float3(0, 0, 0), Scale = new float3(1, 1, 1), Translation = new float3(-2.5f, 3, 0) }; _prehensileClawRightTransform = new TransformComponent { Rotation = new float3(0, 0, 0), Scale = new float3(1, 1, 1), Translation = new float3(2.5f, 3, 0) }; // Shader Effect Components var baseShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0.7f, 0.7f, 0.7f), new float3(0.7f, 0.7f, 0.7f), 5) }; var bodyShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0.8f, 0.2f, 0.2f), new float3(0.7f, 0.7f, 0.7f), 5) }; var upperArmShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0.2f, 0.8f, 0.2f), new float3(0.7f, 0.7f, 0.7f), 5) }; var foreArmShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0.2f, 0.2f, 0.8f), new float3(0.7f, 0.7f, 0.7f), 5) }; var prehensileRailShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0.8f, 0.8f, 0.8f), new float3(0.7f, 0.7f, 0.7f), 5) }; var prehensileClawShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0.6f, 0.6f, 0.6f), new float3(0.7f, 0.7f, 0.7f), 5) }; // Mesh components var baseMesh = SimpleMeshes.CreateCuboid(new float3(10, 2, 10)); var armMesh = SimpleMeshes.CreateCuboid(new float3(2, 10, 2)); var railMesh = SimpleMeshes.CreateCuboid(new float3(6, 1, 2)); var clawMesh = SimpleMeshes.CreateCuboid(new float3(1, 5, 2)); // Setup the scene graph return(new SceneContainer { Children = new List <SceneNodeContainer> { new SceneNodeContainer { Components = new List <SceneComponentContainer> { _baseTransform, baseShader, baseMesh }, Children = new List <SceneNodeContainer> { new SceneNodeContainer { Components = new List <SceneComponentContainer> { _bodyTransform, bodyShader, armMesh }, Children = new List <SceneNodeContainer> { new SceneNodeContainer { Components = new List <SceneComponentContainer> { _upperArmJointTransform }, Children = new List <SceneNodeContainer> { new SceneNodeContainer { Components = new List <SceneComponentContainer> { _upperArmTransform, upperArmShader, armMesh }, Children = new List <SceneNodeContainer> { new SceneNodeContainer { Components = new List <SceneComponentContainer> { _foreArmJointTransform }, Children = new List <SceneNodeContainer> { new SceneNodeContainer { Components = new List <SceneComponentContainer> { _foreArmTransform, foreArmShader, armMesh }, Children = new List <SceneNodeContainer> { new SceneNodeContainer { Components = new List <SceneComponentContainer> { _prehensileRailTransform, prehensileRailShader, railMesh }, Children = new List <SceneNodeContainer> { new SceneNodeContainer { Components = new List <SceneComponentContainer> { _prehensileClawLeftTransform, prehensileClawShader, clawMesh } }, new SceneNodeContainer { Components = new List <SceneComponentContainer> { _prehensileClawRightTransform, prehensileClawShader, clawMesh } } } } } } } } } } } } } } } } } }); }
public override void Init() { // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A). RC.ClearColor = new float4(2f, 2f, 2.7f, 5); // Create scene with cubes // The three components: one XForm, one Shader and the Mesh _cubeTransform = new TransformComponent { Scale = new float3(1, 0.1f, 1), Translation = new float3(2, 0.7f, 0) }; var cubeShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(1, 4, 2), new float3(6, 4, 2), 3) }; var cubeMesh = SimpleMeshes.CreateCuboid(new float3(4, 5, 7)); var cubeMesh1 = SimpleMeshes.CreateCuboid(new float3(3, 1, 15)); var cubeMesh2 = SimpleMeshes.CreateCuboid(new float3(5, 7, 9)); _cubeTransform1 = new TransformComponent { Scale = new float3(1.2f, 2.7f, 0.1f), Translation = new float3(10, 5, 5) }; var cubeShader1 = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0.2f, 0.4f, 0.6f), new float3(1, 1, 1), 4) }; _cubeTransform2 = new TransformComponent { Scale = new float3(0.5f, 0.5f, 0.5f), Translation = new float3(30, 14, 19) }; var cubeShader2 = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(2, 1, 20), new float3(1, 1, 1), 5) }; // Assemble the cubes var cubeNode = new SceneNodeContainer(); cubeNode.Components = new List <SceneComponentContainer>(); cubeNode.Components.Add(_cubeTransform); cubeNode.Components.Add(cubeShader); cubeNode.Components.Add(cubeMesh); var cubeNode1 = new SceneNodeContainer(); cubeNode1.Components = new List <SceneComponentContainer>(); cubeNode1.Components.Add(_cubeTransform1); cubeNode1.Components.Add(cubeShader1); cubeNode1.Components.Add(cubeMesh1); var cubeNode2 = new SceneNodeContainer(); cubeNode2.Components = new List <SceneComponentContainer>(); cubeNode2.Components.Add(_cubeTransform2); cubeNode2.Components.Add(cubeShader2); cubeNode2.Components.Add(cubeMesh2); _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); _scene.Children.Add(cubeNode); _scene.Children.Add(cubeNode1); _scene.Children.Add(cubeNode2); _sceneRenderer = new SceneRenderer(_scene); }
// Init is called on startup. public override void Init() { RC.ClearColor = new float4(0.3f, 0.2f, 0.8f, 1.0f); _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); var cubeNode = new SceneNodeContainer(); _scene.Children.Add(cubeNode); var cube2Node = new SceneNodeContainer(); _scene.Children.Add(cube2Node); var cube3Node = new SceneNodeContainer(); _scene.Children.Add(cube3Node); //The three components: one XForm, one Shader and the Mesh _cubeTransform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 10), Rotation = new float3(0, 0, 0) }; var cubeShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0, 1, 0), new float3(1, 1, 1), 4) }; var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10)); cubeNode.Components = new List <SceneComponentContainer>(); cubeNode.Components.Add(_cubeTransform); cubeNode.Components.Add(cubeShader); cubeNode.Components.Add(cubeMesh); _cube2Transform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0), Rotation = new float3(0, 0, 0) }; var cube2Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0, 0, 1), new float3(1, 1, 1), 4) }; var cube2Mesh = SimpleMeshes.CreateCuboid(new float3(5, 5, 5)); cube2Node.Components = new List <SceneComponentContainer>(); cube2Node.Components.Add(_cube2Transform); cube2Node.Components.Add(cube2Shader); cube2Node.Components.Add(cube2Mesh); _cube3Transform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0), Rotation = new float3(0, 0, 0) }; var cube3Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(1, 0, 0), new float3(1, 1, 1), 4) }; var cube3Mesh = SimpleMeshes.CreateCuboid(new float3(5, 5, 5)); cube3Node.Components = new List <SceneComponentContainer>(); cube3Node.Components.Add(_cube3Transform); cube3Node.Components.Add(cube3Shader); cube3Node.Components.Add(cube3Mesh); _sceneRenderer = new SceneRenderer(_scene); }
// RenderAFrame is called once a frame public override void RenderAFrame() { //_rightRearTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0); float speed = Keyboard.UpDownAxis * 0.3f; float rotspeed = Keyboard.LeftRightAxis * 2; float yrot = _bodyTransform.Rotation.y + rotspeed * DeltaTime; float wheelrotspeed = speed * 20 * Time.DeltaTime; float wheelrotspeeddelta = rotspeed * 2 * Time.DeltaTime; float3 speed3D = new float3(speed * M.Sin(yrot), 0, speed * M.Cos(yrot)); if (Keyboard.UpDownAxis != 0.0f) { _rightRearTransform.Rotation = new float3(0, _rightRearTransform.Rotation.x + wheelrotspeed - wheelrotspeeddelta, 0); _leftRearTransform.Rotation = new float3(0, _leftRearTransform.Rotation.x + wheelrotspeed + wheelrotspeeddelta, 0); _rightFrontTransform.Rotation = new float3(0, _rightFrontTransform.Rotation.x + wheelrotspeed - wheelrotspeeddelta, 0); _leftFrontTransform.Rotation = new float3(0, _leftFrontTransform.Rotation.x + wheelrotspeed + wheelrotspeeddelta, 0); _bodyTransform.Translation = _bodyTransform.Translation + speed3D; _bodyTransform.Rotation = new float3(_bodyTransform.Rotation.x, yrot, _bodyTransform.Rotation.z); } // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Setup the camera //RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float) Atan(15.0 / 40.0)); _camAngle = _camAngle + 0.1f; RC.View = float4x4.CreateTranslation(0, 0, 30) * float4x4.CreateRotationY(5); if (Mouse.LeftButton) { float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1); _scenePicker.View = RC.View; _scenePicker.Projection = RC.Projection; List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList(); PickResult newPick = null; if (pickResults.Count > 0) { pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z)); newPick = pickResults[0]; } if (newPick?.Node != _currentPick?.Node) { if (_currentPick != null) { ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>(); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor); } if (newPick != null) { ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>(); _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor"); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(1, 0.4f, 0.4f)); } _currentPick = newPick; } } // Render the scene on the current render context _sceneRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer. Present(); }
// RenderAFrame is called once a frame public override void RenderAFrame() { // _baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0); //Rotation Drehsteuerung _DSShader = _scene.Children.FindNodes(node => node.Name == "Drehsteuerung")?.FirstOrDefault()?.GetComponent <ShaderEffectComponent>(); _oldColorDS = (float3)_DSShader.Effect.GetEffectParam("DiffuseColor"); if (_oldColorDS == _newColor) { _DS = _scene.Children.FindNodes(node => node.Name == "Drehsteuerung")?.FirstOrDefault()?.GetTransform(); float DSRot = _DS.Rotation.y; DSRot += 0.4f * Keyboard.ADAxis * Time.DeltaTime; _DS.Rotation = new float3(0, DSRot, 0); } //Rotation hintere Leiter _leiterBackShader = _scene.Children.FindNodes(node => node.Name == "LeiterHinten")?.FirstOrDefault()?.GetComponent <ShaderEffectComponent>(); _oldColorLB = (float3)_leiterBackShader.Effect.GetEffectParam("DiffuseColor"); if (_oldColorLB == _newColor) { _leiterBack = _scene.Children.FindNodes(node => node.Name == "LeiterHinten")?.FirstOrDefault()?.GetTransform(); leiterBackRot = _leiterBack.Rotation.x; leiterBackRot += 0.4f * Keyboard.WSAxis * Time.DeltaTime; if (leiterBackRot <= 0) { _leiterBack.Rotation = new float3(0, 0, 0); } else if (leiterBackRot <= 60 * M.Pi / 180) { _leiterBack.Rotation = new float3(leiterBackRot, 0, 0); } else if (leiterBackRot >= 60 * M.Pi / 180) { leiterBackRot = 60 * M.Pi / 180; _leiterBack.Rotation = new float3(leiterBackRot, 0, 0); } } //Rotation vordere Leiter _leiterFrontShader = _scene.Children.FindNodes(node => node.Name == "LeiterVorne")?.FirstOrDefault()?.GetComponent <ShaderEffectComponent>(); _oldColorLF = (float3)_leiterFrontShader.Effect.GetEffectParam("DiffuseColor"); if (_oldColorLF == _newColor) { _leiterFront = _scene.Children.FindNodes(node => node.Name == "LeiterVorne")?.FirstOrDefault()?.GetTransform(); float leiterFrontRot = _leiterFront.Rotation.x; leiterFrontRot += 0.4f * Keyboard.WSAxis * Time.DeltaTime; if (leiterBackRot == 0) { if (leiterFrontRot <= 0) { _leiterFront.Rotation = new float3(0, 0, 0); } } else if (leiterFrontRot <= -30 * M.Pi / 180) { leiterFrontRot = -30 * M.Pi / 180; _leiterFront.Rotation = new float3(leiterFrontRot, 0, 0); } else if (leiterFrontRot <= 30 * M.Pi / 180) { _leiterFront.Rotation = new float3(leiterFrontRot, 0, 0); } else if (leiterFrontRot >= 30 * M.Pi / 180) { leiterFrontRot = 30 * M.Pi / 180; _leiterFront.Rotation = new float3(leiterFrontRot, 0, 0); } } // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Setup the camera RC.View = float4x4.CreateTranslation(0, 0, 20) * float4x4.CreateRotationX(-(float)Atan(10.0 / 40.0)) * float4x4.CreateRotationY(-(float)Acos(0)); //Scene Picker if (Mouse.LeftButton) { float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1); _scenePicker.View = RC.View; _scenePicker.Projection = RC.Projection; List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList(); PickResult newPick = null; if (pickResults.Count > 0) { pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z)); newPick = pickResults[0]; } if (newPick?.Node != _currentPick?.Node) { if (_currentPick != null) { ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>(); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor); } if (newPick != null) { ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>(); _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor"); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(1, 0.19f, 0.29f)); _newColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor"); } _currentPick = newPick; } } // Render the scene on the current render context _sceneRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer. Present(); }
// RenderAFrame is called once a frame public override void RenderAFrame() { // _baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0); // _WheelVLTransform.Rotation = new float3(M.MinAngle(TimeSinceStart), 0, 0); // _SchaufelTransform.Scale = new float3(0.5f, 2f, 2f); if (Mouse.MiddleButton == true) { _camAngle = _camAngle + Mouse.Velocity.x / 500; } ; // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Setup the camera //RC.View = float4x4.CreateTranslation(0, -10, 50) * float4x4.CreateRotationY(_camAngle); RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationY(_camAngle); if (Mouse.LeftButton) { float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1); _scenePicker.View = RC.View; _scenePicker.Projection = RC.Projection; List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList(); PickResult newPick = null; if (pickResults.Count > 0) { pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z)); newPick = pickResults[0]; } if (newPick?.Node != _currentPick?.Node) { if (_currentPick != null) { ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>(); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor); } if (newPick != null) { ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>(); _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor"); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(0f, 1f, 0.1f)); } _currentPick = newPick; } } //Wheel if (_currentPick?.Node.Name == "WheelVL" || _currentPick?.Node.Name == "WheelHL" || _currentPick?.Node.Name == "WheelVR" || _currentPick?.Node.Name == "WheelHR") { float VL = _WheelVLTransform.Rotation.z; VL += 0.1f * Keyboard.LeftRightAxis; _WheelVLTransform.Rotation = new float3(0, 0, VL); float HL = _WheelHLTransform.Rotation.z; HL += 0.1f * Keyboard.LeftRightAxis; _WheelHLTransform.Rotation = new float3(0, 0, HL); float VR = _WheelVRTransform.Rotation.z; VR += 0.1f * Keyboard.LeftRightAxis; _WheelVRTransform.Rotation = new float3(0, 0, VR); float HR = _WheelHRTransform.Rotation.z; HR += 0.1f * Keyboard.LeftRightAxis; _WheelHRTransform.Rotation = new float3(0, 0, HR); } //Body if (_currentPick?.Node.Name == "Body") { float Body = _BodyTransform.Rotation.y; Body += 0.1f * Keyboard.LeftRightAxis; _BodyTransform.Rotation = new float3(0, Body, 0); } //Arm if (_currentPick?.Node.Name == "Arm") { float Arm = _ArmTransform.Rotation.z; Arm += 0.1f * Keyboard.LeftRightAxis; _ArmTransform.Rotation = new float3(0, 0, Arm); } //Schaufel if (_currentPick?.Node.Name == "Schaufel") { float Schaufel = _SchaufelTransform.Rotation.z; Schaufel += 0.1f * Keyboard.UpDownAxis; _SchaufelTransform.Rotation = new float3(0, 0, Schaufel); } // Render the scene on the current render context _sceneRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer. Present(); }
// RenderAFrame is called once a frame public override void RenderAFrame() { //_baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0); // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Setup the camera RC.View = float4x4.CreateTranslation(0, 0, 10) * float4x4.CreateRotationX(-(float)Atan(5.0 / 10.0)); if (Mouse.LeftButton) { float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1); _scenePicker.View = RC.View; _scenePicker.Projection = RC.Projection; List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList(); PickResult newPick = null; if (pickResults.Count > 0) { pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z)); newPick = pickResults[0]; } if (newPick?.Node != _currentPick?.Node) { if (_currentPick != null) { ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>(); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor); } if (newPick != null) { ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>(); _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor"); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor + (new float3(0.25f, 0.25f, 0.25f))); } _currentPick = newPick; Diagnostics.Log(_currentPick?.Node.Name); } } switch (_currentPick?.Node.Name) { case "Body": TransformComponent transBody = _currentPick.Node.GetComponent <TransformComponent>(); IEnumerable <TransformComponent> transWheels = _scene.Children.FindNodes(node => node.Name.Contains("Wheels")).Select(node => tc(node)); transBody.Rotation.y += DeltaTime * Keyboard.ADAxis; foreach (TransformComponent wheel in transWheels) { wheel.Rotation.x += DeltaTime * Keyboard.WSAxis * 8.0f; } break; case "Muzzle": case "Tower": TransformComponent transMuzzle = _scene.Children.FindNodes(node => node.Name == ("MuzzleTower")).FirstOrDefault().GetComponent <TransformComponent>(); TransformComponent transTower = _scene.Children.FindNodes(node => node.Name == ("Tower")).FirstOrDefault().GetComponent <TransformComponent>(); transMuzzle.Rotation.x = limit(transMuzzle.Rotation.x + DeltaTime * -Keyboard.WSAxis, -0.32f * M.Pi, 0.08f * M.Pi); transTower.Rotation.y += DeltaTime * Keyboard.ADAxis; break; case "Wheels1": case "Wheels2": case "Wheels3": case "Wheels4": case "Wheels5": TransformComponent transWheel = _currentPick.Node.GetComponent <TransformComponent>(); transWheel.Rotation.x += DeltaTime * Keyboard.WSAxis * 8.0f; break; } // Render the scene on the current render context _sceneRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer. Present(); }
//Build a scene graph consisting out of a canvas and other UI elements. private SceneContainer CreateNineSliceScene() { var vsTex = AssetStorage.Get <string>("texture.vert"); var psTex = AssetStorage.Get <string>("texture.frag"); var vsNineSlice = AssetStorage.Get <string>("nineSlice.vert"); var psNineSlice = AssetStorage.Get <string>("nineSliceTile.frag"); var canvasScaleFactor = _initWindowWidth / _canvasWidth; float textSize = 2; float borderScaleFactor = 1; if (_canvasRenderMode == CanvasRenderMode.SCREEN) { textSize *= canvasScaleFactor; borderScaleFactor = canvasScaleFactor; } var text = new TextNodeContainer( "Hallo !", "ButtonText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.STRETCH_ALL), new MinMaxRect { Min = new float2(1f, 0.5f), Max = new float2(-1f, -0.5f) }, _fontMap, ColorUint.Tofloat4(ColorUint.Greenery), textSize); var catTextureNode = new TextureNodeContainer( "Cat", AssetStorage.Get <string>("nineSlice.vert"), AssetStorage.Get <string>("nineSliceTile.frag"), //Set the diffuse texture you want to use. new Texture(AssetStorage.Get <ImageData>("Kitti.jpg")), //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.STRETCH_HORIZONTAL),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent. //Define Offset and therefor the size of the element. //Min: distance to this elements Min anchor. //Max: distance to this elements Max anchor. UIElementPosition.CalcOffsets(AnchorPos.STRETCH_HORIZONTAL, new float2(_initCanvasWidth / 2 - 2.5f, 0), _initCanvasHeight, _initCanvasWidth, new float2(5, 4)), //Choose in how many tiles you want to split the inner part of the texture. Use float2.one if you want it stretched. new float2(5, 5), //Tell how many percent of the texture, seen from the edges, belongs to the border. Order: left, right, top, bottom. new float4(0.11f, 0.11f, 0.06f, 0.17f), 4, 4, 4, 4, borderScaleFactor ) { Children = new ChildList() { text } }; catTextureNode.Components.Add(_btnCat); var bltTextureNode = new TextureNodeContainer( "Blt", vsTex, psTex, //Set the diffuse texture you want to use. _bltDestinationTex, //_fontMap.Image, //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.DOWN_DOWN_LEFT),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent. //Define Offset and therefor the size of the element. //Min: distance to this elements Min anchor. //Max: distance to this elements Max anchor. UIElementPosition.CalcOffsets(AnchorPos.DOWN_DOWN_LEFT, new float2(0, 0), _initCanvasHeight, _initCanvasWidth, new float2(4, 4))); var quagganTextureNode1 = new TextureNodeContainer( "Quaggan1", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(2.5f, 0), 3, 6, new float2(1, 1)), new float2(1, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var nineSliceTextureNode = new TextureNodeContainer( "testImage", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("9SliceSprites-4.png")), //In this setup the element will stay in the upper right corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_RIGHT),//Anchor is in the upper right corner.//Anchor is in the upper right corner. UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_RIGHT, new float2(_initCanvasWidth - 6, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 3)), new float2(2, 3), new float4(0.1f, 0.1f, 0.1f, 0.1f), 2.5f, 2.5f, 2.5f, 2.5f, borderScaleFactor ) { Children = new ChildList() { text, quagganTextureNode1 } }; var quagganTextureNode = new TextureNodeContainer( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, _initCanvasHeight - 1), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var quagganTextureNode2 = new TextureNodeContainer( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TOP_TOP_LEFT), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TOP_TOP_LEFT, new float2(0, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var quagganTextureNode3 = new TextureNodeContainer( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.STRETCH_VERTICAL), //Anchor is in the lower right corner. Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.STRETCH_VERTICAL, new float2(0, _initCanvasHeight - 5), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var canvas = new CanvasNodeContainer( "Canvas", _canvasRenderMode, new MinMaxRect { Min = new float2(-_canvasWidth / 2, -_canvasHeight / 2f), Max = new float2(_canvasWidth / 2, _canvasHeight / 2f) }) { Children = new ChildList() { //Simple Texture Node, contains a Blt"ed" texture. bltTextureNode, //Add nine sliced textures to canvas catTextureNode, quagganTextureNode, nineSliceTextureNode, quagganTextureNode2, quagganTextureNode3 } }; var canvasMat = new ShaderEffectComponent { Effect = ShaderCodeBuilder.MakeShaderEffectFromMatComp(new MaterialComponent { Diffuse = new MatChannelContainer { Color = new float4(1, 0, 0, 1) }, }) }; var projMethod = _canvasRenderMode == CanvasRenderMode.SCREEN ? ProjectionMethod.ORTHOGRAPHIC : ProjectionMethod.PERSPECTIVE; var projComp = new ProjectionComponent(projMethod, zNear, zFar, fov); AddResizeDelegate(delegate { projComp.Resize(Width, Height); }); canvas.Components.Insert(0, projComp); canvas.AddComponent(canvasMat); canvas.AddComponent(new Plane()); canvas.AddComponent(_btnCanvas); return(new SceneContainer { Children = new List <SceneNodeContainer> { //Add canvas. canvas } }); }
// Init is called on startup. public override void Init() { // Set the clear color for the backbuffer to custom color (100% intentsity in all color channels R, G, B, A). RC.ClearColor = new float4(0.58f, 0, 0.7f, 1); // Create a scene with 3 cubes // The three components: one XForm, one Shader and the Mesh //Würfel Nr.1 _cube1Transform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0) }; //Translation = Position im Raum var cube1Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0.3f, 0.88f, 1), new float3(1, 1, 1), 4) }; var cube1Mesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10)); //Würfel Nr.2 _cube2Transform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(20, 0, 0) }; var cube2Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(1, 0, 0.67f), new float3(1, 1, 1), 4) }; var cube2Mesh = SimpleMeshes.CreateCuboid(new float3(12, 12, 12)); //Würfel Nr.3 _cube3Transform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(-20, 5, 0) }; cube3Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0.8f, 0, 0.13f), new float3(1, 1, 1), 4) }; var cube3Mesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10)); // Assemble the cube node containing the three components var cube1Node = new SceneNodeContainer(); cube1Node.Components = new List <SceneComponentContainer>(); cube1Node.Components.Add(_cube1Transform); cube1Node.Components.Add(cube1Shader); cube1Node.Components.Add(cube1Mesh); var cube2Node = new SceneNodeContainer(); cube2Node.Components = new List <SceneComponentContainer>(); cube2Node.Components.Add(_cube2Transform); cube2Node.Components.Add(cube2Shader); cube2Node.Components.Add(cube2Mesh); var cube3Node = new SceneNodeContainer(); cube3Node.Components = new List <SceneComponentContainer>(); cube3Node.Components.Add(_cube3Transform); cube3Node.Components.Add(cube3Shader); cube3Node.Components.Add(cube3Mesh); // Create the scene containing the cube as the only object _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); _scene.Children.Add(cube1Node); _scene.Children.Add(cube2Node); _scene.Children.Add(cube3Node); // Create a scene renderer holding the scene above _sceneRenderer = new SceneRenderer(_scene); }
// RenderAFrame is called once a frame public override void RenderAFrame() { //_rechtsVorneTransform.Rotation = new float3(M.MinAngle(TimeSinceStart), 0, 0); float rechts_vorne_rotation_z = _rechtsVorneTransform.Rotation.z; rechts_vorne_rotation_z += 2 * -Keyboard.UpDownAxis * DeltaTime; float rechts_vorne_rotation_y = _rechtsVorneTransform.Rotation.y; rechts_vorne_rotation_y += Keyboard.LeftRightAxis * DeltaTime; if (rechts_vorne_rotation_y < 0.25 && rechts_vorne_rotation_y > -0.25) { _rechtsVorneTransform.Rotation = new float3(0, rechts_vorne_rotation_y, rechts_vorne_rotation_z); } else { _rechtsVorneTransform.Rotation = new float3(0, _rechtsVorneTransform.Rotation.y, rechts_vorne_rotation_z); } //Diagnostics.Log(rechts_vorne_rotation_y); float links_vorne_rotation_z = _linksVorneTransform.Rotation.z; links_vorne_rotation_z += 2 * -Keyboard.UpDownAxis * DeltaTime; float links_vorne_rotation_y = _linksVorneTransform.Rotation.y; links_vorne_rotation_y += Keyboard.LeftRightAxis * DeltaTime; if (links_vorne_rotation_y < 0.25 && links_vorne_rotation_y > -0.25) { _linksVorneTransform.Rotation = new float3(0, links_vorne_rotation_y, links_vorne_rotation_z); } else { _linksVorneTransform.Rotation = new float3(0, _linksVorneTransform.Rotation.y, links_vorne_rotation_z); } float links_hinten_rotation_z = _linksHintenTransform.Rotation.z; links_hinten_rotation_z += 2 * -Keyboard.UpDownAxis * DeltaTime; _linksHintenTransform.Rotation = new float3(0, 0, links_hinten_rotation_z); float rechts_hinten_rotation_z = _rechtsHintenTransform.Rotation.z; rechts_hinten_rotation_z += 2 * -Keyboard.UpDownAxis * DeltaTime; _rechtsHintenTransform.Rotation = new float3(0, 0, rechts_hinten_rotation_z); if (_Arm1) { float arm1_rotation_y = _Arm1Transform.Rotation.y; arm1_rotation_y += 2 * Keyboard.ADAxis * DeltaTime; _Arm1Transform.Rotation = new float3(0, arm1_rotation_y, 0); } if (_Arm2) { float arm2_rotation_z = _Arm2Transform.Rotation.z; arm2_rotation_z += 2 * Keyboard.WSAxis * DeltaTime; if (arm2_rotation_z <= 1.5 && arm2_rotation_z >= -1.5) { _Arm2Transform.Rotation = new float3(0, 0, arm2_rotation_z); } } if (_Arm3) { float arm3_rotation_z = _Arm3Transform.Rotation.z; arm3_rotation_z += 2 * Keyboard.WSAxis * DeltaTime; if (arm3_rotation_z <= 1 && arm3_rotation_z >= -1) { _Arm3Transform.Rotation = new float3(0, 0, arm3_rotation_z); } //Diagnostics.Log(arm3_rotation_z); } // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Setup the camera _camAngle += 12.0f * M.Pi / 180.0f * DeltaTime; RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationY(_camAngle); if (Mouse.LeftButton) { float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1); _scenePicker.View = RC.View; _scenePicker.Projection = RC.Projection; List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList(); PickResult newPick = null; if (pickResults.Count > 0) { pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z)); newPick = pickResults[0]; } if (newPick?.Node != _currentPick?.Node) { if (_currentPick != null) { ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>(); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor); } if (newPick != null) { ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>(); _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor"); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(1, 0.4f, 0.4f)); if (newPick.Node.Name == "Arm1") { _Arm1 = true; _Arm2 = false; _Arm3 = false; } else if (newPick.Node.Name == "Arm2") { _Arm1 = false; _Arm2 = true; _Arm3 = false; } else if (newPick.Node.Name == "Arm3") { _Arm1 = false; _Arm2 = false; _Arm3 = true; } else { _Arm1 = false; _Arm2 = false; _Arm3 = false; } } _currentPick = newPick; } } // Render the scene on the current render context _sceneRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer. Present(); }
public override void Init() { // Set the clear color for the backbuffer to light green (intensities in R, G, B, A). RC.ClearColor = new float4(0f, 1f, 2f, 1f); _cubeTransform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0) }; var cubeShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.Beige), new float3(1, 1, 1), 4) }; var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10)); // Assemble the cube node containing the three components var cubeNode = new SceneNodeContainer(); cubeNode.Components = new List <SceneComponentContainer>(); cubeNode.Components.Add(_cubeTransform); cubeNode.Components.Add(cubeShader); cubeNode.Components.Add(cubeMesh); //CUBE2_________________________________________________________________________ _cube2Transform = new TransformComponent { Scale = new float3(3, 3, 1), Translation = new float3(30, 0, 30), Rotation = new float3(0.1f, 0.5f, 0) }; _cube2Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.DarkRed), new float3(1, 1, 1), 4) }; var cubeMesh2 = SimpleMeshes.CreateCuboid(new float3(5, 5, 5)); // Assemble the cube node containing the three components var cubeNode2 = new SceneNodeContainer(); cubeNode2.Components = new List <SceneComponentContainer>(); cubeNode2.Components.Add(_cube2Transform); cubeNode2.Components.Add(_cube2Shader); cubeNode2.Components.Add(cubeMesh2); //CUBE3_______________________________________________________________________________ _cube3Transform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(15, 0, -10), Rotation = new float3(-0.1f, -0.5f, 0) }; _cube3Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.MediumSeaGreen), new float3(1, 2, 1), 4) }; var cubeMesh3 = SimpleMeshes.CreateCuboid(new float3(2, 3, 1)); // Assemble the cube node containing the three components var cubeNode3 = new SceneNodeContainer(); cubeNode3.Components = new List <SceneComponentContainer>(); cubeNode3.Components.Add(_cube3Transform); cubeNode3.Components.Add(_cube3Shader); cubeNode3.Components.Add(cubeMesh3); // Create the scene containing the cube as the only object _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); _scene.Children.Add(cubeNode); _scene.Children.Add(cubeNode2); _scene.Children.Add(cubeNode3); // Create a scene renderer holding the scene above _sceneRenderer = new SceneRenderer(_scene); }
// Init is called on startup. public override void Init() { // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A). RC.ClearColor = ColorUint.Tofloat4(ColorUint.PaleGreen); // Create a scene with a cube // The three components: one XForm, one Shader and the Mesh _cubeTransform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 0), Rotation = new float3(0.1f, 0, 0.3f) }; _cubeShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.Crimson), new float3(1, 1, 1), 4) }; var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10)); // Assemble the cube node containing the three components var cubeNode = new SceneNodeContainer(); cubeNode.Components = new List <SceneComponentContainer>(); cubeNode.Components.Add(_cubeTransform); cubeNode.Components.Add(_cubeShader); cubeNode.Components.Add(cubeMesh); // Würfel 2 _cube2Transform = new TransformComponent { Scale = new float3(5, 1, 1), Translation = new float3(30, 0, 30), Rotation = new float3(0.6f, 0.6f, 0) }; _cube2Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.Navy), new float3(1, 1, 1), 4) }; var cubeMesh2 = SimpleMeshes.CreateCuboid(new float3(5, 5, 5)); // Assemble the cube node containing the three components var cubeNode2 = new SceneNodeContainer(); cubeNode2.Components = new List <SceneComponentContainer>(); cubeNode2.Components.Add(_cube2Transform); cubeNode2.Components.Add(_cube2Shader); cubeNode2.Components.Add(cubeMesh2); //würfel 3 _cube3Transform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(18, 0, -30) }; _cube3Shader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(ColorUint.Tofloat3(ColorUint.Lime), new float3(1, 2, 1), 4) }; var cubeMesh3 = SimpleMeshes.CreateCuboid(new float3(1, 1, 1)); // Assemble the cube node containing the three components var cubeNode3 = new SceneNodeContainer(); cubeNode3.Components = new List <SceneComponentContainer>(); cubeNode3.Components.Add(_cube3Transform); cubeNode3.Components.Add(_cube3Shader); cubeNode3.Components.Add(cubeMesh3); // Create the scene containing the cube as the only object _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); _scene.Children.Add(cubeNode); _scene.Children.Add(cubeNode2); _scene.Children.Add(cubeNode3); // Create a scene renderer holding the scene above _sceneRenderer = new SceneRenderer(_scene); // RenderAFrame is called once a frame }
// Init is called on startup. public override void Init() { // Set the clear color for the backbuffer to light green (intensities in R, G, B, A) RC.ClearColor = new float4(0.2f, 0.2f, 0.2f, 1); // Hintergrundfarbe (r,g,b, Durchsichtigkeit) // Create a scene with a cube // The three components: one XForm, one Material and the Mesh _cubeTransform = new TransformComponent { Scale = new float3(1, 1, 1), // Skalierung Translation = new float3(0, 0, 0), // Position des Objektes (x,y,z) Rotation = new float3(0, -0.5f, 0.2f) // Drehung an den Achsen; in Gradmaß angeben }; var cubeShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0, 0, 1), new float3(1, 1, 1), 4) /* Erster float Wert Farbe des Würfels; Zweiter float Wert Farbe des Glanzlichtes */ }; var cubeMesh = SimpleMeshes.CreateCuboid(new float3(5, 5, 5)); // Größe des Quaders // Assemble the cube node containing the three components var cubeNode = new SceneNodeContainer(); cubeNode.Components = new List <SceneComponentContainer>(); cubeNode.Components.Add(_cubeTransform); cubeNode.Components.Add(cubeShader); cubeNode.Components.Add(cubeMesh); // Eigenschaften des Quaders _quaderTransform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 20), Rotation = new float3(0, 0, 0) }; var quaderShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(1, 1, 1), new float3(1, 1, 1), 4) }; var quaderMesh = SimpleMeshes.CreateCuboid(new float3(5, 5, 20)); var quader = new SceneNodeContainer(); quader.Components = new List <SceneComponentContainer>(); quader.Components.Add(_quaderTransform); quader.Components.Add(quaderShader); quader.Components.Add(quaderMesh); // Eigenschaften 3. Würfel _wuerfelDreiTransform = new TransformComponent { Scale = new float3(1, 1, 1), Translation = new float3(0, 0, 20), Rotation = new float3(0, 0, 0) }; _wuerfelDreiShader = new ShaderEffectComponent { Effect = SimpleMeshes.MakeShaderEffect(new float3(0.9f, 0.2f, 0.4f), new float3(1, 1, 1), 4) }; var wuerfelDreiMesh = SimpleMeshes.CreateCuboid(new float3(5, 5, 20)); var wuerfelDrei = new SceneNodeContainer(); wuerfelDrei.Components = new List <SceneComponentContainer>(); wuerfelDrei.Components.Add(_wuerfelDreiTransform); wuerfelDrei.Components.Add(_wuerfelDreiShader); wuerfelDrei.Components.Add(wuerfelDreiMesh); // Create the scene containing the cube as the only object // Hier werden alle Objekte der Szene Hinzugefügt _scene = new SceneContainer(); _scene.Children = new List <SceneNodeContainer>(); _scene.Children.Add(cubeNode); _scene.Children.Add(quader); _scene.Children.Add(wuerfelDrei); // Create a scene renderer holding the scene above _sceneRenderer = new SceneRenderer(_scene); }
// RenderAFrame is called once a frame public override void RenderAFrame() { //_baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0); //tower kontrolle // _towerTransform.Rotation = new float3(0,M.MinAngle(TimeSinceStart),0); // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Setup the camera RC.View = float4x4.CreateTranslation(0, 0, 20) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0)); if (Mouse.LeftButton) { float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1); _scenePicker.View = RC.View; _scenePicker.Projection = RC.Projection; List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList(); PickResult newPick = null; if (pickResults.Count > 0) { pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z)); newPick = pickResults[0]; } // Turm nur drehen wenn angeklickt if (pickResults.Count > 0 && pickResults[0].Node.Name == "Turm" && _currentPick != null) { canTurn = true; } else { canTurn = false; } //Räder drehen if (pickResults.Count > 0 && _currentPick != null && pickResults[0].Node.Name == "Rad-hinten-rechts") { gasGebenHR = true; } else { gasGebenHR = false; } if (pickResults.Count > 0 && _currentPick != null && pickResults[0].Node.Name == "Rad-hinten-links") { gasGebenHL = true; } else { gasGebenHL = false; } if (pickResults.Count > 0 && _currentPick != null && pickResults[0].Node.Name == "Rumpf") { allrad = true; } else { allrad = false; } if (newPick?.Node != _currentPick?.Node) { if (_currentPick != null) { ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>(); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor); } if (newPick != null) { ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>(); _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor"); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(0.5f, 0.1f, 0.4f)); } _currentPick = newPick; } } if (canTurn == true) { float towerRed = _towerTransform.Rotation.y; towerRed += 0.05f * Keyboard.ADAxis * (-1); _towerTransform.Rotation = new float3(0, towerRed, 0); } if (gasGebenHR == true) { float hintenRechts = _HRTransform.Rotation.x; hintenRechts += 0.1f * Keyboard.WSAxis * (-1); _HRTransform.Rotation = new float3(hintenRechts, 0, 0); } if (gasGebenHL == true) { float hintenLinks = _HLTransform.Rotation.x; hintenLinks += 0.1f * Keyboard.WSAxis * (-1); _HLTransform.Rotation = new float3(hintenLinks, 0, 0); } // bei Klick auf Rumpf if (allrad == true) { //Hinten rechts float hintenRechts = _HRTransform.Rotation.x; hintenRechts += 0.1f * Keyboard.WSAxis * (-1); _HRTransform.Rotation = new float3(hintenRechts, 0, 0); // Hinten links float hintenLinks = _HLTransform.Rotation.x; hintenLinks += 0.1f * Keyboard.WSAxis * (-1); _HLTransform.Rotation = new float3(hintenLinks, 0, 0); // Vorne rechts float vorneRechts = _VRTransform.Rotation.x; vorneRechts += 0.1f * Keyboard.WSAxis * (-1); _VRTransform.Rotation = new float3(vorneRechts, 0, 0); //vorne links float vorneLinks = _VLTransform.Rotation.x; vorneLinks += 0.1f * Keyboard.WSAxis * (-1); _VLTransform.Rotation = new float3(vorneLinks, 0, 0); } // Render the scene on the current render context _sceneRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer. Present(); }
// RenderAFrame is called once a frame public override void RenderAFrame() { // _baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0); // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); float speed = Keyboard.UpDownAxis * 15.0f; float rotSpeed = Keyboard.LeftRightAxis * 3.0f; float wheelRotSpeed = speed * Time.DeltaTime * 0.3f; float wheelRotSpeedDelta = rotSpeed * Time.DeltaTime * 0.3f; float yRot = _bodyTransform.Rotation.y + rotSpeed * Time.DeltaTime; float3 speed3d = new float3(speed * M.Sin(yRot), 0, speed * M.Cos(yRot)); _bodyTransform.Translation = _bodyTransform.Translation + speed3d * Time.DeltaTime; _bodyTransform.Rotation = new float3(_bodyTransform.Rotation.x, yRot, _bodyTransform.Rotation.z); _rightRearWheelTransform.Rotation = new float3(_rightFrontWheelTransform.Rotation.x + wheelRotSpeed - wheelRotSpeedDelta, 0, 0); _leftRearWheelTransform.Rotation = new float3(_leftRearWheelTransform.Rotation.x + wheelRotSpeed + wheelRotSpeedDelta, 0, 0); _rightFrontWheelTransform.Rotation = new float3(_rightFrontWheelTransform.Rotation.x +wheelRotSpeed - wheelRotSpeedDelta, 0, 0); _leftFrontWheelTransform.Rotation = new float3(_leftFrontWheelTransform.Rotation.x + wheelRotSpeed + wheelRotSpeedDelta, 0, 0); // Setup the camera RC.View = float4x4.CreateTranslation(0, -10, 50) * float4x4.CreateRotationY(_camAngle); if(Mouse.RightButton == true){ _camAngle += Mouse.Velocity.x * 0.01f * DeltaTime; } if (Mouse.LeftButton) { float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1); _scenePicker.View = RC.View; _scenePicker.Projection = RC.Projection; List<PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList(); PickResult newPick = null; if (pickResults.Count > 0) { pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z)); newPick = pickResults[0]; } if (newPick?.Node != _currentPick?.Node) { if (_currentPick != null) { ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent<ShaderEffectComponent>(); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor); } if (newPick != null) { ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent<ShaderEffectComponent>(); _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor"); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(0.5f, 1, 0.4f)); } _currentPick = newPick; } } if(_currentPick?.Node.Name == "Schaufel"){ float schaufelTransform = _schaufelTransform.Rotation.x; schaufelTransform -= 0.01f * Keyboard.WSAxis; if(schaufelTransform >= 0.8f){ schaufelTransform = 0.8f; }else if(schaufelTransform <= -1.0f){ schaufelTransform = -1.0f; } _schaufelTransform.Rotation = new float3(schaufelTransform, 0, 0); }else if(_currentPick?.Node.Name == "Oberarm"){ float oberarmTransform = _oberarmTransform.Rotation.x; oberarmTransform -= 0.01f * Keyboard.WSAxis; if(oberarmTransform >= 1.0f){ oberarmTransform = 1.0f; }else if(oberarmTransform <= -0.5f){ oberarmTransform = -0.5f; } _oberarmTransform.Rotation = new float3(oberarmTransform, 0, 0); }else if(_currentPick?.Node.Name == "Arm"){ float unterarmTransform = _unterarmTransform.Rotation.x; unterarmTransform -= 0.01f * Keyboard.WSAxis; if(unterarmTransform >= 1.5f){ unterarmTransform = 1.5f; }else if(unterarmTransform <= -0.01f){ unterarmTransform = -0.01f; } _unterarmTransform.Rotation = new float3(unterarmTransform, 0, 0); } // if(_currentPick?.Node.Name == "LeftFrontWheel" || _currentPick?.Node.Name == "RightFrontWheel" || _currentPick?.Node.Name == "LeftRearWheel" || _currentPick?.Node.Name == "RightRearWheel"){ // float leftFrontWheelTransform = _leftFrontWheelTransform.Rotation.x; // leftFrontWheelTransform -= 0.08f * Keyboard.UpDownAxis; // _leftFrontWheelTransform.Rotation = new float3(leftFrontWheelTransform, 0, 0); // float rightFrontWheelTransform = _rightFrontWheelTransform.Rotation.x; // rightFrontWheelTransform -= 0.08f * Keyboard.UpDownAxis; // _rightFrontWheelTransform.Rotation = new float3(rightFrontWheelTransform, 0, 0); // float leftRearWheelTransform = _leftRearWheelTransform.Rotation.x; // leftRearWheelTransform -= 0.08f * Keyboard.UpDownAxis; // _leftRearWheelTransform.Rotation = new float3(leftRearWheelTransform, 0, 0); // float rightRearWheelTransform = _rightRearWheelTransform.Rotation.x; // rightRearWheelTransform -= 0.08f * Keyboard.UpDownAxis; // _rightRearWheelTransform.Rotation = new float3(rightRearWheelTransform, 0, 0); // } // Render the scene on the current render context _sceneRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer. Present(); }
// RenderAFrame is called once a frame public override void RenderAFrame() { //_baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0); // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); if (Keyboard.ADAxis != 0) { _camRotation += 0.05f * Keyboard.ADAxis; } // Setup the camera RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0)) * float4x4.CreateRotationY(_camRotation); if (Mouse.LeftButton) { float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1); _scenePicker.View = RC.View; _scenePicker.Projection = RC.Projection; List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList(); if (pickResults.Count > 0) { pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z)); _newPick = pickResults[0]; } if (_newPick != _currentPick) { if (_currentPick != null) { ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>(); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor); } if (_newPick != null) { ShaderEffectComponent shaderEffectComponent = _newPick.Node.GetComponent <ShaderEffectComponent>(); _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor"); shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(1, 0.4f, 0.4f)); } _currentPick = _newPick; } } if (_newPick?.Node.Name == "Haus") { float Haus = _haus.Rotation.y; Haus += velocity * Keyboard.LeftRightAxis * DeltaTime; _haus.Rotation = new float3(0, Haus, 0); } if (_newPick?.Node.Name == "Unterarm") { float unterarm = _unterarm.Rotation.z; unterarm += velocity * Keyboard.LeftRightAxis * DeltaTime; if (unterarm > -0.4f) { unterarm = -0.4f; } else if (unterarm < -1.5f) { unterarm = -1.5f; } _unterarm.Rotation = new float3(0, 0, unterarm); } if (_currentPick?.Node.Name == "Schaufel") { float schaufel = _schaufel.Rotation.z; schaufel += velocity * Keyboard.UpDownAxis * DeltaTime; if (schaufel > -0.4f) { schaufel = -0.4f; } else if (schaufel < -1.5f) { schaufel = -1.5f; } _schaufel.Rotation = new float3(0, 0, schaufel); } if (_currentPick?.Node.Name == "ReifenLV") { float reifenLV = _reifenLV.Rotation.z; reifenLV += velocity * Keyboard.WSAxis * DeltaTime; _reifenLV.Rotation = new float3(0, 0, reifenLV); } if (_currentPick?.Node.Name == "ReifenRV") { float reifenRV = _reifenRV.Rotation.z; reifenRV += velocity * Keyboard.WSAxis * DeltaTime; _reifenRV.Rotation = new float3(0, 0, reifenRV); } if (_currentPick?.Node.Name == "ReifenLH") { float reifenLH = _reifenLH.Rotation.z; reifenLH += velocity * Keyboard.WSAxis * DeltaTime; _reifenLH.Rotation = new float3(0, 0, reifenLH); } if (_currentPick?.Node.Name == "ReifenRH") { float reifenRH = _reifenRH.Rotation.z; reifenRH += velocity * Keyboard.WSAxis * DeltaTime; _reifenRH.Rotation = new float3(0, 0, reifenRH); } // Render the scene on the current render context _sceneRenderer.Render(RC); // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer. Present(); }