// Init is called on startup. public override void Init() { #if GUI_SIMPLE _guiHandler = new GUIHandler(); _guiHandler.AttachToContext(RC); _guiFuseeLink = new GUIButton(6, 6, 157, 87); _guiFuseeLink.ButtonColor = new float4(0, 0, 0, 0); _guiFuseeLink.BorderColor = new float4(0, 0.6f, 0.2f, 1); _guiFuseeLink.BorderWidth = 0; _guiFuseeLink.OnGUIButtonDown += _guiFuseeLink_OnGUIButtonDown; _guiFuseeLink.OnGUIButtonEnter += _guiFuseeLink_OnGUIButtonEnter; _guiFuseeLink.OnGUIButtonLeave += _guiFuseeLink_OnGUIButtonLeave; _guiHandler.Add(_guiFuseeLink); _guiFuseeLogo = new GUIImage(AssetStorage.Get <ImageData>("FuseeLogo150.png"), 10, 10, -5, 150, 80); _guiHandler.Add(_guiFuseeLogo); var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); fontLato.UseKerning = true; _guiLatoBlack = new FontMap(fontLato, 18); _guiSubText = new GUIText("Simple FUSEE Example", _guiLatoBlack, 100, 100); _guiSubText.TextColor = new float4(0.05f, 0.25f, 0.15f, 0.8f); _guiHandler.Add(_guiSubText); _subtextWidth = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack); _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack); #endif // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A). RC.ClearColor = new float4(1, 1, 1, 1); // Load the rocket model _rocketScene = AssetStorage.Get <SceneContainer>("RocketModel.fus"); // Wrap a SceneRenderer around the model. _sceneRenderer = new SceneRenderer(_rocketScene); }
// Init is called on startup. public override void Init() { #if GUI_SIMPLE _guiHandler = new GUIHandler(); _guiHandler.AttachToContext(RC); _guiFuseeLink = new GUIButton(6, 6, 157, 87); _guiFuseeLink.ButtonColor = new float4(0, 0, 0, 0); _guiFuseeLink.BorderColor = new float4(0, 0.6f, 0.2f, 1); _guiFuseeLink.BorderWidth = 0; _guiFuseeLink.OnGUIButtonDown += _guiFuseeLink_OnGUIButtonDown; _guiFuseeLink.OnGUIButtonEnter += _guiFuseeLink_OnGUIButtonEnter; _guiFuseeLink.OnGUIButtonLeave += _guiFuseeLink_OnGUIButtonLeave; _guiHandler.Add(_guiFuseeLink); _guiFuseeLogo = new GUIImage(AssetStorage.Get <ImageData>("FuseeLogo150.png"), 10, 10, -5, 150, 80); _guiHandler.Add(_guiFuseeLogo); var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); fontLato.UseKerning = true; _guiLatoBlack = new FontMap(fontLato, 18); _guiSubText = new GUIText("FUSEE Example", _guiLatoBlack, 100, 100); _guiSubText.TextColor = new float4(0.05f, 0.25f, 0.15f, 0.8f); _guiHandler.Add(_guiSubText); _subtextWidth = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack); _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack); #endif // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A). RC.ClearColor = new float4(1, 1, 1, 1); // Load the rocket model _rocketScene = AssetStorage.Get <SceneContainer>("RocketModel.fus"); //Create StereoCam for S3D rendering _stereoCam = new StereoCameraRig(Stereo3DMode.Anaglyph, Width, Height, 6.5f); _stereoCam.AttachToContext(RC); //Create ScreenS3DTextures object holding the 4 textures to be used with the ScreenS3D object ScreenS3DTextures screenTex = new ScreenS3DTextures(); screenTex.Left = RC.CreateTexture(AssetStorage.Get <ImageData>("left.png")); screenTex.LeftDepth = RC.CreateTexture(AssetStorage.Get <ImageData>("depthLeft.png")); screenTex.Right = RC.CreateTexture(AssetStorage.Get <ImageData>("right.png")); screenTex.RightDepth = RC.CreateTexture(AssetStorage.Get <ImageData>("depthRight.png")); //Create ScreenS3D Object using the ScreenS3Dtextures object from above _screen = new ScreenS3D(RC, screenTex); //Set the config fort the Screen objet. This can also be doene using a whole ScreenConfig object and assiging direktly to the ScreenS3D object _screen.Config.ScaleSize = 1000; _screen.Config.ScaleDepth = 5; _screen.Config.Transform = float4x4.CreateTranslation(0, 200, 0); // Wrap a SceneRenderer around the model. _sceneRenderer = new SceneRenderer(_rocketScene); // vl = AssetStorage.Get<VideoStream>("left.mkv"); capL = new Capture("Assets/left.mkv"); capLD = new Capture("Assets/depthLeft.mkv"); capR = new Capture("Assets/right.mkv"); capRD = new Capture("Assets/depthRight.mkv"); }
// Init is called on startup. public override void Init() { //Width and Height are 0 on our Android Device if (Width <= 0) { Width = 2560; } if (Height <= 0) { Height = 1440; } #if GUI_SIMPLE _guiHandler = new GUIHandler(); _guiHandler.AttachToContext(RC); _guiFuseeLink = new GUIButton(6, 6, 157, 87); _guiFuseeLink.ButtonColor = new float4(0, 0, 0, 0); _guiFuseeLink.BorderColor = new float4(0, 0.6f, 0.2f, 1); _guiFuseeLink.BorderWidth = 0; _guiFuseeLink.OnGUIButtonDown += _guiFuseeLink_OnGUIButtonDown; _guiFuseeLink.OnGUIButtonEnter += _guiFuseeLink_OnGUIButtonEnter; _guiFuseeLink.OnGUIButtonLeave += _guiFuseeLink_OnGUIButtonLeave; _guiHandler.Add(_guiFuseeLink); _guiFuseeLogo = new GUIImage(AssetStorage.Get <ImageData>("FuseeLogo150.png"), 10, 10, -5, 150, 80); _guiHandler.Add(_guiFuseeLogo); var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); fontLato.UseKerning = true; _guiLatoBlack = new FontMap(fontLato, 18); _guiSubText = new GUIText("Simple FUSEE Cardboard Example", _guiLatoBlack, 100, 100); _guiSubText.TextColor = new float4(0.05f, 0.25f, 0.15f, 0.8f); _guiHandler.Add(_guiSubText); _subtextWidth = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack); _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack); #endif // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A). RC.ClearColor = new float4(1, 1, 1, 1); //Initialize StereoRendering if (_renderStereo) { _stereo3d = new Stereo3D(Stereo3DMode.Cardboard, Width, Height); _stereo3d.AttachToContext(RC); } // Load the scene _WuggyScene = AssetStorage.Get <SceneContainer>("WuggyLand.fus"); // Wrap a SceneRenderer around the scene. _sceneRenderer = new SceneRenderer(_WuggyScene); }
// RenderAFrame is called once a frame public override void RenderAFrame() { // _guiSubText.Text = $"dt: {DeltaTime} ms, W: {Width}, H: {Height}, PS: {_maxPinchSpeed}"; // Clear the backbuffer RC.Clear(ClearFlags.Color | ClearFlags.Depth); // Mouse and keyboard movement if (Keyboard.LeftRightAxis != 0 || Keyboard.UpDownAxis != 0) { _keys = true; } var curDamp = (float)System.Math.Exp(-Damping * DeltaTime); // Zoom & Roll if (Touch.TwoPoint) { if (!_twoTouchRepeated) { _twoTouchRepeated = true; _angleRollInit = Touch.TwoPointAngle - _angleRoll; _offsetInit = Touch.TwoPointMidPoint - _offset; _maxPinchSpeed = 0; } _zoomVel = Touch.TwoPointDistanceVel * -0.01f; _angleRoll = Touch.TwoPointAngle - _angleRollInit; _offset = Touch.TwoPointMidPoint - _offsetInit; float pinchSpeed = Touch.TwoPointDistanceVel; if (pinchSpeed > _maxPinchSpeed) { _maxPinchSpeed = pinchSpeed; // _maxPinchSpeed is used for debugging only. } } else { _twoTouchRepeated = false; _zoomVel = Mouse.WheelVel * -0.5f; _angleRoll *= curDamp * 0.8f; _offset *= curDamp * 0.8f; } // UpDown / LeftRight rotation if (Mouse.LeftButton) { _keys = false; _angleVelHorz = -RotationSpeed * Mouse.XVel * 0.000002f; _angleVelVert = -RotationSpeed * Mouse.YVel * 0.000002f; } else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Touch.TwoPoint) { _keys = false; float2 touchVel; touchVel = Touch.GetVelocity(TouchPoints.Touchpoint_0); _angleVelHorz = -RotationSpeed * touchVel.x * 0.000002f; _angleVelVert = -RotationSpeed * touchVel.y * 0.000002f; } else { if (_keys) { _angleVelHorz = -RotationSpeed * Keyboard.LeftRightAxis * 0.002f; _angleVelVert = -RotationSpeed * Keyboard.UpDownAxis * 0.002f; } else { _angleVelHorz *= curDamp; _angleVelVert *= curDamp; } } _zoom += _zoomVel; // Limit zoom if (_zoom < 80) { _zoom = 80; } if (_zoom > 2000) { _zoom = 2000; } _angleHorz += _angleVelHorz; // Wrap-around to keep _angleHorz between -PI and + PI _angleHorz = M.MinAngle(_angleHorz); _angleVert += _angleVelVert; // Limit pitch to the range between [-PI/2, + PI/2] _angleVert = M.Clamp(_angleVert, -M.PiOver2, M.PiOver2); // Wrap-around to keep _angleRoll between -PI and + PI _angleRoll = M.MinAngle(_angleRoll); // Create the camera matrix and set it as the current ModelView transformation var mtxRot = float4x4.CreateRotationZ(_angleRoll) * float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz); var mtxCam = float4x4.LookAt(0, 20, -_zoom, 0, 0, 0, 0, 1, 0); RC.ModelView = mtxCam * mtxRot * _sceneScale * _sceneCenter; var mtxOffset = float4x4.CreateTranslation(2 * _offset.x / Width, -2 * _offset.y / Height, 0); RC.Projection = mtxOffset * _projection; // Tick any animations and Render the scene loaded in Init() _sceneRenderer.Animate(); _sceneRenderer.Render(RC); _sinceLastTick += DeltaTime; if (_sinceLastTick >= 0.1f) { _sinceLastTick = 0; Ticker.Tick(); StringBuilder sb = new StringBuilder(Ticker.Size); foreach (char c in Ticker.CurrentText) { if (_guiLatoBlack.Alphabet.Contains(new string(c, 1))) { sb.Append(c); } else { sb.Append(' '); } } _guiSubText.Text = sb.ToString(); _subtextWidth = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack); _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack); _guiSubText.PosX = (int)((Width - _subtextWidth) / 2); _guiSubText.PosY = (int)((Height - _subtextHeight) * 4.0f / 5.0f); _guiHandler.Refresh(); } _guiHandler.RenderGUI(); // Swap buffers: Show the contents of the backbuffer (containing the currently rerndered frame) on the front buffer. Present(); }
// Init is called on startup. public override void Init() { // VERSION 1 - SYNCHRONER DOWNLOAD /* * ButtonDown += delegate (object sender, EventArgs args) * { * WebClient client = new WebClient(); * * string fileContents = client.DownloadString(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt")); * Ticker.CompleteText = fileContents; * }; * /* */ // VERSION 2 - Asynchronous Programming Model (APM) - wird von WebClient nicht unterstützt, daher kein Beispiel // VERSION 3 - Event Based Asynchronous Pattern (EAP) /* * ButtonDown += delegate (object sender, EventArgs args) * { * WebClient client = new WebClient(); * * client.DownloadStringCompleted += delegate(object o, DownloadStringCompletedEventArgs eventArgs) * { * Ticker.CompleteText = eventArgs.Result; * }; * client.DownloadStringAsync(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt")); * }; * /* */ // VERSION 4 - Task-based Asynchronous Pattern (TAP) /* * ButtonDown += async delegate (object sender, EventArgs args) * { * WebClient client = new WebClient(); * * String fileContents = await client.DownloadStringTaskAsync(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt")); * // Nach dem await - Code der hier steht, wird erst nach dem ENDE des Task aufgerufen * Ticker.CompleteText = fileContents; * * }; * /* */ /* */ // VERSION 5 - Task-based Asynchronous Pattern (TAP) mit getrenntem await ButtonDown += async delegate(object sender, EventArgs args) { WebClient client = new WebClient(); Task <string> task = client.DownloadStringTaskAsync(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt")); // Dinge, die direkt nach dem Starten des Task passieren sollen Ticker.CompleteText = "- - - D O W N L O A D I N G - - - T H E C O M P L E T E W O R K S O F W I L L I A M S H A K E S P E A R E "; // Vor dem await - hier passiert alles direkt nach dem Starten des Task String fileContents = await task; // Nach dem await - Code der hier steht, wird erst nach dem ENDE des Task aufgerufen Ticker.CompleteText = fileContents; }; /* */ _guiHandler = new GUIHandler(); _guiHandler.AttachToContext(RC); _guiFuseeLink = new GUIButton(6, 6, 253, 221); _guiFuseeLink.ButtonColor = new float4(0, 0, 0, 0); _guiFuseeLink.BorderColor = new float4(0.6f, 0.2f, 0.2f, 1); _guiFuseeLink.BorderWidth = 0; _guiFuseeLink.OnGUIButtonDown += _guiFuseeLink_OnGUIButtonDown; _guiFuseeLink.OnGUIButtonEnter += _guiFuseeLink_OnGUIButtonEnter; _guiFuseeLink.OnGUIButtonLeave += _guiFuseeLink_OnGUIButtonLeave; _guiHandler.Add(_guiFuseeLink); _guiFuseeLogo = new GUIImage(AssetStorage.Get <ImageData>("ClickMe.png"), 10, 10, -5, 253, 221); _guiHandler.Add(_guiFuseeLogo); var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); fontLato.UseKerning = true; _guiLatoBlack = new FontMap(fontLato, 64); _guiSubText = new GUIText(Ticker.CurrentText, _guiLatoBlack, 100, 100); _guiSubText.TextColor = new float4(0, 0, 0.15f, 0.8f); _guiHandler.Add(_guiSubText); _subtextWidth = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack); _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack); // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle) _zoom = 400; _angleRoll = 0; _angleRollInit = 0; _twoTouchRepeated = false; _offset = float2.Zero; _offsetInit = float2.Zero; // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A). RC.ClearColor = new float4(1, 1, 1, 1); // Load the standard model _scene = AssetStorage.Get <SceneContainer>("Model.fus"); AABBCalculator aabbc = new AABBCalculator(_scene); var bbox = aabbc.GetBox(); if (bbox != null) { // If the model origin is more than one third away from its bounding box, // recenter it to the bounding box. Do this check individually per dimension. // This way, small deviations will keep the model's original center, while big deviations // will make the model rotating around its geometric center. float3 bbCenter = bbox.Value.Center; float3 bbSize = bbox.Value.Size; float3 center = float3.Zero; if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3) { center.x = bbCenter.x; } if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3) { center.y = bbCenter.y; } if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3) { center.z = bbCenter.z; } _sceneCenter = float4x4.CreateTranslation(-center); // Adjust the model size float maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z)); if (maxScale != 0) { _sceneScale = float4x4.CreateScale(200.0f / maxScale); } else { _sceneScale = float4x4.Identity; } } // Wrap a SceneRenderer around the model. _sceneRenderer = new SceneRenderer(_scene); }
// Init is called on startup. public override void Init() { _guiHandler = new GUIHandler(); _guiHandler.AttachToContext(RC); _guiFuseeLink = new GUIButton(6, 6, 253, 221); _guiFuseeLink.ButtonColor = new float4(0, 0, 0, 0); _guiFuseeLink.BorderColor = new float4(0.6f, 0.2f, 0.2f, 1); _guiFuseeLink.BorderWidth = 0; _guiFuseeLink.OnGUIButtonDown += _guiFuseeLink_OnGUIButtonDown; _guiFuseeLink.OnGUIButtonEnter += _guiFuseeLink_OnGUIButtonEnter; _guiFuseeLink.OnGUIButtonLeave += _guiFuseeLink_OnGUIButtonLeave; _guiHandler.Add(_guiFuseeLink); _guiFuseeLogo = new GUIImage(AssetStorage.Get <ImageData>("ClickMe.png"), 10, 10, -5, 253, 221); _guiHandler.Add(_guiFuseeLogo); var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); fontLato.UseKerning = true; _guiLatoBlack = new FontMap(fontLato, 64); _guiSubText = new GUIText(Ticker.CurrentText, _guiLatoBlack, 100, 100); _guiSubText.TextColor = new float4(0, 0, 0.15f, 0.8f); _guiHandler.Add(_guiSubText); _subtextWidth = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack); _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack); // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle) _zoom = 400; _angleRoll = 0; _angleRollInit = 0; _twoTouchRepeated = false; _offset = float2.Zero; _offsetInit = float2.Zero; // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A). RC.ClearColor = new float4(1, 1, 1, 1); // Load the standard model _scene = AssetStorage.Get <SceneContainer>("Model.fus"); AABBCalculator aabbc = new AABBCalculator(_scene); var bbox = aabbc.GetBox(); if (bbox != null) { // If the model origin is more than one third away from its bounding box, // recenter it to the bounding box. Do this check individually per dimension. // This way, small deviations will keep the model's original center, while big deviations // will make the model rotating around its geometric center. float3 bbCenter = bbox.Value.Center; float3 bbSize = bbox.Value.Size; float3 center = float3.Zero; if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3) { center.x = bbCenter.x; } if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3) { center.y = bbCenter.y; } if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3) { center.z = bbCenter.z; } _sceneCenter = float4x4.CreateTranslation(-center); // Adjust the model size float maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z)); if (maxScale != 0) { _sceneScale = float4x4.CreateScale(200.0f / maxScale); } else { _sceneScale = float4x4.Identity; } } // Wrap a SceneRenderer around the model. _sceneRenderer = new SceneRenderer(_scene); }
// is called on startup public override void Init() { // GUI initialization _zVal = 500; _guiHandler = new GUIHandler(); _guiHandler.AttachToContext(RC); _guiFuseeLink = new GUIButton(6, 6, 157, 87); _guiFuseeLink.ButtonColor = new float4(0, 0, 0, 0); _guiFuseeLink.BorderColor = new float4(0, 0.6f, 0.2f, 1); _guiFuseeLink.BorderWidth = 0; _guiFuseeLink.OnGUIButtonDown += _guiFuseeLink_OnGUIButtonDown; _guiFuseeLink.OnGUIButtonEnter += _guiFuseeLink_OnGUIButtonEnter; _guiFuseeLink.OnGUIButtonLeave += _guiFuseeLink_OnGUIButtonLeave; _guiHandler.Add(_guiFuseeLink); _guiFuseeLogo = new GUIImage("Assets/FuseeLogo150.png", 10, 10, -5, 150, 80); _guiHandler.Add(_guiFuseeLogo); _guiLatoBlack = RC.LoadFont("Assets/Lato-Black.ttf", 14); _guiSubText = new GUIText("FUSEE 3D Scene Viewer", _guiLatoBlack, 100, 100); _guiSubText.TextColor = new float4(0.05f, 0.25f, 0.15f, 0.8f); _guiHandler.Add(_guiSubText); // Scene loading var ser = new Serializer(); using (var file = File.OpenRead(@"Assets/Model.fus")) { _scene = ser.Deserialize(file, null, typeof(SceneContainer)) as SceneContainer; } _sr = new SceneRenderer(_scene, "Assets"); AdjustModelScaleOffset(); _guiSubText.Text = "FUSEE 3D Scene"; if (_scene.Header.CreatedBy != null || _scene.Header.CreationDate != null) { _guiSubText.Text += " created"; if (_scene.Header.CreatedBy != null) { _guiSubText.Text += " by " + _scene.Header.CreatedBy; } if (_scene.Header.CreationDate != null) { _guiSubText.Text += " on " + _scene.Header.CreationDate; } } _subtextWidth = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack); _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack); _sColor = Shaders.GetDiffuseColorShader(RC); RC.SetShader(_sColor); _colorParam = _sColor.GetShaderParam("color"); RC.SetShaderParam(_colorParam, new float4(1, 1, 1, 1)); RC.ClearColor = new float4(1, 1, 1, 1); }