コード例 #1
0
        public void DeformAxis(Axis axis)
        {
            Deformer deformer = m_editor.Selection.activeGameObject.GetComponent <Deformer>();

            if (deformer == null)
            {
                m_editor.Undo.BeginRecord();
                m_editor.Undo.AddComponent(m_editor.Selection.activeGameObject.GetComponent <ExposeToEditor>(), typeof(Deformer));
                m_editor.Undo.CreateRecord(redo =>
                {
                    EnableSplineRenderers(Mode == MeshDeformerToolMode.ControlPoint);
                    return(false);
                }, undo => false);
                m_editor.Undo.EndRecord();
            }
            else
            {
                BaseSplineState oldState     = deformer.GetState();
                PickResult      oldSelection = m_picker.Selection != null ? new PickResult(m_picker.Selection) : null;
                deformer.Axis = axis;
                BaseSplineState newState     = deformer.GetState();
                PickResult      newSelection = m_picker.Selection != null ? new PickResult(m_picker.Selection) : null;
                RecordState(deformer.gameObject, oldState, newState, m_picker, oldSelection, newSelection);
            }

            EnableSplineRenderers(false);
        }
コード例 #2
0
        public void SelectControlPoint(Camera camera, Vector2 point)
        {
            if (m_selectionComponentState == null)
            {
                return;
            }

            if (m_selectionComponentState.Component.IsPositionHandleEnabled)
            {
                m_editor.Undo.BeginRecord();
                PickResult oldSelection = m_picker.Selection != null ? new PickResult(m_picker.Selection) : null;
                m_picker.Pick(camera, point);
                PickResult newSelection = m_picker.Selection != null ? new PickResult(m_picker.Selection) : null;
                m_editor.Undo.CreateRecord(record =>
                {
                    m_picker.Selection = newSelection;
                    return(true);
                },
                                           record =>
                {
                    m_picker.Selection = oldSelection;
                    return(true);
                });
                m_editor.Undo.EndRecord();
            }
        }
コード例 #3
0
        public bool DragControlPoint(bool extend)
        {
            PositionHandle positionHandle = m_editor.Tools.ActiveTool as PositionHandle;

            if (m_picker.IsControlPointSelected && positionHandle != null && positionHandle.IsDragging)
            {
                if (extend)
                {
                    ControlPointPicker picker       = m_editor.Selection.activeGameObject.GetComponent <ControlPointPicker>();
                    BaseSpline         spline       = picker.Selection.GetSpline();
                    BaseSplineState    oldState     = spline.GetState();
                    PickResult         oldSelection = picker.Selection != null ? new PickResult(picker.Selection) : null;
                    m_picker.Drag(true);
                    spline = picker.Selection.GetSpline();
                    BaseSplineState newState     = spline.GetState();
                    PickResult      newSelection = picker.Selection != null ? new PickResult(picker.Selection) : null;
                    RecordState(spline.gameObject, oldState, newState, picker, oldSelection, newSelection);
                }
                else
                {
                    m_picker.Drag(false);
                }
                return(true);
            }
            return(false);
        }
コード例 #4
0
        public override PickResult Pick(PickContext context)
        {
            Subchannel?   leastUsedSubchannel = null;
            int?          leastUsedCount      = null;
            AtomicCounter?leastUsedCounter    = null;

            foreach (var subchannel in _subchannels)
            {
                if (!subchannel.Attributes.TryGetValue(CounterKey, out var counter))
                {
                    throw new InvalidOperationException("All subchannels should have a counter.");
                }

                var currentCount = counter.Value;
                if (leastUsedSubchannel == null || leastUsedCount > currentCount)
                {
                    leastUsedSubchannel = subchannel;
                    leastUsedCount      = currentCount;
                    leastUsedCounter    = counter;
                }
            }

            Debug.Assert(leastUsedSubchannel != null);
            Debug.Assert(leastUsedCounter != null);

            leastUsedCounter.Increment();

            return(PickResult.ForSubchannel(leastUsedSubchannel, c =>
            {
                leastUsedCounter.Decrement();
            }));
        }
コード例 #5
0
        public PickResult SubmitPick(int userID, int playerID)
        {
            PickResult result = PickResult.Success;
            PlayerObj  player = null;

            lock (_DraftLock)
            {
                player = FindPlayer(playerID);
                if (player == null)
                {
                    result = PickResult.InvalidPlayer;
                }
                else if (!Settings.PositionMaxes.ContainsKey(player.Position))
                {
                    result = PickResult.InvalidPosition;
                }
                else
                {
                    List <PlayerObj> draftedPlayers = GetUsersDraftedPlayers(userID);
                    int posCount = draftedPlayers.Sum(x => x.Position == player.Position ? 1 : 0);
                    if (posCount >= Settings.PositionMaxes[player.Position])
                    {
                        result = PickResult.PositionMax;
                    }
                    else
                    {
                        PlayerObj pickedPlayer = FindPickedPlayer(playerID);
                        if (pickedPlayer != null)
                        {
                            result = PickResult.AlreadyPicked;
                        }
                        else
                        {
                            DraftMoveObj match = FindUserOnClock(userID);
                            if (match == null)
                            {
                                result = PickResult.NotTurn;
                            }
                            else
                            {
                                DraftMove move = new DraftMove()
                                {
                                    Pick     = match.Pick,
                                    Round    = match.Round,
                                    SeasonID = Settings.DraftSeasonID,
                                    PlayerID = playerID,
                                    Time     = DateTime.Now,
                                    MoveType = (int)DraftMoveType.Pick,
                                    UserID   = userID
                                };
                                db.DraftMoves.InsertOnSubmit(move);
                                db.SubmitChanges();
                            }
                        }
                    }
                }
            }

            return(result);
        }
コード例 #6
0
        public List <DraftPickStatusObj> Post(DraftPickStatusObj next)
        {
            DraftUser user = DraftAuthentication.AuthenticateRequest(Request);

            if (!next.Player.HasValue)
            {
                throw new HttpStatusException(HttpStatusCode.NotFound, "The player you entered is invalid or does not exists");
            }
            else
            {
                PickResult result = dataSource.SubmitPick(user.ID, next.Player.Value);
                if (result != PickResult.Success)
                {
                    switch (result)
                    {
                    case PickResult.AlreadyPicked:
                        throw new HttpStatusException(HttpStatusCode.MethodNotAllowed, "That player has already been chosen");

                    case PickResult.InvalidPlayer:
                        throw new HttpStatusException(HttpStatusCode.NotFound, "The player you entered is invalid or does not exist");

                    case PickResult.NotTurn:
                        throw new HttpStatusException(HttpStatusCode.Forbidden, "It's not your turn to pick");

                    case PickResult.InvalidPosition:
                        throw new HttpStatusException(HttpStatusCode.Forbidden, "Players at that position cannot be drafted");

                    case PickResult.PositionMax:
                        throw new HttpStatusException(HttpStatusCode.Forbidden, "Position Max - You cannot draft any more players at that position");
                    }
                }
            }

            return(GetDraftPicks());
        }
コード例 #7
0
        private float3 GetTriagleCenter(PickResult pr)
        {
            float3 a, b, c;

            pr.GetTriangle(out a, out b, out c);

            return((a + b + c) / 3);
        }
コード例 #8
0
        private float3 GetTriagleBarycentric(PickResult pr)
        {
            float3 a, b, c;

            pr.GetTriangle(out a, out b, out c);

            return(float3.Barycentric(a, b, c, pr.U, pr.V));
        }
コード例 #9
0
        private float3 GetNormalsCenter(PickResult pr)
        {
            float3 a, b, c;

            GetNormals(pr, out a, out b, out c);

            return((a + b + c) / 3);
        }
コード例 #10
0
        private float3 GetNormalsBarycentric(PickResult pr)
        {
            float3 a, b, c;

            GetNormals(pr, out a, out b, out c);

            return(float3.Barycentric(a, b, c, pr.U, pr.V));
        }
コード例 #11
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // 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)
                    {
                        _currentPick.Node.GetMaterial().Diffuse.Color = _oldColour;
                    }
                    if (newPick != null)
                    {
                        var mat = newPick.Node.GetMaterial();
                        _oldColour        = mat.Diffuse.Color;
                        mat.Diffuse.Color = new float3(1, 0.4f, 0.4f);
                    }
                    _currentPick = newPick;
                }
            }
            float cabinRot = _cabinTransform.Rotation.y;

            cabinRot += 0.1f * Keyboard.ADAxis;
            _cabinTransform.Rotation = new float3(0, cabinRot, 0);

            if (_currentPick != null)
            {
                _pickTransform = _currentPick.Node.GetTransform();
                float zRot = _pickTransform.Rotation.z;
                zRot += 0.1f * Keyboard.WSAxis;
                _pickTransform.Rotation = new float3(0, 0, zRot);
            }
            // 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();
        }
コード例 #12
0
ファイル: AssetsPicking.cs プロジェクト: bynikoala/HFU-WS2-CG
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            _baseTransform.Rotation = new float3(0, _baseTransform.Rotation.y + Keyboard.ADAxis * DeltaTime * 3, 0);
            canon.Rotation          = new float3(0, canon.Rotation.y + Keyboard.LeftRightAxis * DeltaTime * 3, 0);
            vr.Rotation             = new float3(vr.Rotation.x + Keyboard.WSAxis * DeltaTime * 3, 0, 0);
            hr.Rotation             = new float3(hr.Rotation.x + Keyboard.WSAxis * DeltaTime * 3, 0, 0);
            vl.Rotation             = new float3(vl.Rotation.x + Keyboard.WSAxis * DeltaTime * 3, 0, 0);
            hl.Rotation             = new float3(hl.Rotation.x + Keyboard.WSAxis * DeltaTime * 3, 0, 0);

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-0.7f) * float4x4.CreateRotationY(1.3f);

            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)
                    {
                        _currentPick.Node.GetMaterial().Diffuse.Color = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var mat = newPick.Node.GetMaterial();
                        _oldColor         = mat.Diffuse.Color;
                        mat.Diffuse.Color = 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();
        }
コード例 #13
0
ファイル: RayPicking.cs プロジェクト: chuz/tesla-engine
        private void CreatePicks(PickQuery query)
        {
            if (query.Count == 0)
            {
                return;
            }
            query.Sort();

            //Lazily create the mesh that holds the pick visuals, for this example we're only doing the closest picked
            //triangle
            if (picks == null)
            {
                picks          = new Mesh("Picks");
                picks.Material = ContentManager.Load <Material>("Materials//BasicColor.tem").Clone();
                picks.Material.SetParameter("DiffuseColor", Color.Yellow);
                picks.SetRenderState(RasterizerState.CullNoneWireframe);
                picks.SetRenderState(DepthStencilState.None);
                picks.MeshData.Positions            = new DataBuffer <Vector3>(3);
                picks.MeshData.UseIndexedPrimitives = false;
                picks.MeshData.Reconstruct();
                picks.SceneHints.RenderBucketType = RenderBucketType.PostBucket;
                picks.SceneHints.PickingHint      = PickingHint.None;
                RootNode.AddChild(picks);

                pickRay          = new Line("PickRay");
                pickRay.Material = ContentManager.Load <Material>("Materials//BasicVertColor.tem").Clone();
                RootNode.AddChild(pickRay);
            }

            DataBuffer <Vector3> db = picks.MeshData.Positions;

            db.Position = 0;
            PickResult results = query.ClosestPick.Value;
            Ray        ray     = results.SourceRay;

            //Get the closest primitive intersection record, and the closest intersection triangle (a ray may pass through many
            //triangles, we want the one closest to the ray's origin). These should exist, if we have results.
            IntersectionRecord record = results.PrimitiveIntersectionRecord.Value.ClosestIntersection.Value;
            Triangle           tri    = record.Triangle.Value;

            db.Set(tri.PointA);
            db.Set(tri.PointB);
            db.Set(tri.PointC);

            //Set the pick ray so we can see it on the screen
            pickRay.SetLine(ray.Origin, ray.Origin + ray.Direction * (record.Distance + 100), Color.Orange, Color.Orange);

            //Update the pick result with the triangle data
            picks.MeshData.UpdateVertexData <Vector3>(VertexSemantic.Position, db);
        }
コード例 #14
0
        // 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();
        }
コード例 #15
0
        public void Remove()
        {
            ControlPointPicker picker       = m_editor.Selection.activeGameObject.GetComponent <ControlPointPicker>();
            BaseSpline         spline       = picker.Selection.GetSpline();
            BaseSplineState    oldState     = spline.GetState();
            PickResult         oldSelection = picker.Selection != null ? new PickResult(picker.Selection) : null;

            picker.Remove();
            PickResult newSelection = picker.Selection != null ? new PickResult(picker.Selection) : null;

            spline = picker.Selection.GetSpline();
            BaseSplineState newState = spline.GetState();

            RecordState(spline.gameObject, oldState, newState, picker, oldSelection, newSelection);
        }
コード例 #16
0
        /// <summary>
        /// Lors de la phase de picks, permet à l'IA de pick un spell actif dont l'id est donné (si c'est son
        /// tour).
        /// </summary>
        public PickResult Picks_PickActive(int spell)
        {
            System.IO.MemoryStream s      = new System.IO.MemoryStream();
            System.IO.StreamWriter output = new System.IO.StreamWriter(s, BOMLESS_UTF8);
            output.NewLine = "\n";
            output.WriteLine(((int)5).ToString());
            output.WriteLine(((int)spell).ToString());
            output.Close();
            TCPHelper.Send(s.ToArray());
            byte[] response = TCPHelper.Receive();
            s = new System.IO.MemoryStream(response);
            System.IO.StreamReader input       = new System.IO.StreamReader(s, BOMLESS_UTF8);
            PickResult             returnValue = (PickResult)Int32.Parse(input.ReadLine());

            return((PickResult)returnValue);
        }
コード例 #17
0
ファイル: Form1.cs プロジェクト: Puppetplay/BeThe2016
        // 픽을 선택한다.
        private void GetPick()
        {
            DateTime date    = new DateTime(2015, 3, 28);
            var      matches = dbMgr.SelectAll <Match>();

            dbMgr.DataContext.ExecuteCommand("TRUNCATE TABLE PickResult");
            for (Int32 i = 0; i < 70; ++i)
            {
                DateTime gameDate = date.AddDays(i);
                var      ms       = (from m in matches
                                     where m.GameId.Substring(0, 8) == gameDate.ToString("yyyyMMdd")
                                     select m);

                if (ms.Count() > 0)
                {
                    var picks = new List <Pick>();
                    // 매경기당 계산로직
                    foreach (var match in ms)
                    {
                        var ps = GetBestBatters(match);
                        picks = picks.Concat(ps).ToList();
                    }

                    picks.Sort((Pick x, Pick y) => x.Ratio.CompareTo(y.Ratio));
                    picks.Reverse();

                    picks = picks.GetRange(0, Math.Min(picks.Count(), 10));

                    List <PickResult> pickResults = new List <PickResult>();
                    foreach (var pick in picks)
                    {
                        var pickResult = new PickResult();
                        pickResult.GameDate = gameDate.ToString("yyyyMMdd");
                        pickResult.MatchId  = pick.MatchId;
                        pickResult.PlayerId = pick.PlayerId;
                        pickResults.Add(pickResult);
                    }

                    dbMgr.Save <PickResult>(pickResults);
                }
            }
        }
コード例 #18
0
        private bool CalculateTerrainIntersection(ViewControl vc, Ray3F ray, GUILayer.IntersectionTestSceneWrapper testScene, out PickResult result)
        {
            var nativeVC = vc as NativeDesignControl;

            if (nativeVC == null)
            {
                result = new PickResult(); return(false);
            }

            var pick = XLEBridgeUtils.Picking.RayPick(nativeVC.Adapter, ray, XLEBridgeUtils.Picking.Flags.Terrain);

            if (pick != null && pick.Length > 0)
            {
                result = new PickResult(pick[0].hitPt);
                return(true);
            }

            result = new PickResult();
            return(false);
        }
コード例 #19
0
        // RenderAFrame is called once a frame
        // 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)Math.Atan(15.0 / 40.0));

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);

                PickResult newPick = _scenePicker.Pick(RC, pickPosClip).OrderBy(pr => pr.ClipPos.z).FirstOrDefault();

                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        var ef = _currentPick.Node.GetComponent <DefaultSurfaceEffect>();
                        ef.SurfaceInput.Albedo = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var ef = newPick.Node.GetComponent <SurfaceEffect>();
                        _oldColor = ef.SurfaceInput.Albedo;
                        ef.SurfaceInput.Albedo = (float4)ColorUint.OrangeRed;
                    }
                    _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();
        }
コード例 #20
0
        public void Append()
        {
            ControlPointPicker picker       = m_editor.Selection.activeGameObject.GetComponent <ControlPointPicker>();
            BaseSpline         spline       = picker.Selection.GetSpline();
            BaseSplineState    oldState     = spline.GetState();
            PickResult         oldSelection = picker.Selection != null ? new PickResult(picker.Selection) : null;

            if (picker.Selection.Index == 0 || picker.Selection.Index == 1)
            {
                picker.Prepend();
            }
            else
            {
                picker.Append();
            }

            spline = picker.Selection.GetSpline();
            BaseSplineState newState     = spline.GetState();
            PickResult      newSelection = picker.Selection != null ? new PickResult(picker.Selection) : null;

            RecordState(spline.gameObject, oldState, newState, picker, oldSelection, newSelection);
        }
コード例 #21
0
 private void RecordState(GameObject spline,
                          BaseSplineState oldState,
                          BaseSplineState newState,
                          ControlPointPicker picker,
                          PickResult oldSelection,
                          PickResult newSelection)
 {
     m_editor.Undo.CreateRecord(record =>
     {
         Deformer deformer = spline.GetComponent <Deformer>();
         deformer.SetState(newState);
         picker.Selection = newSelection;
         return(true);
     },
                                record =>
     {
         Deformer deformer = spline.GetComponent <Deformer>();
         deformer.SetState(oldState);
         picker.Selection = oldSelection;
         return(true);
     });
 }
コード例 #22
0
        protected override void UpdateOverride()
        {
            //base.UpdateOverride();

            UpdateFontSize();

            if (!IsDragging)
            {
                RuntimeHandleAxis axis = GetAxis(out m_currentDot);
                if (m_currentAxis != axis)
                {
                    m_currentAxis = axis;
                    RecalculateBoundsAndRebuild();
                    m_selectedPointIndex = -1;
                    m_selectedEdgeIndex  = -1;
                }

                Vector3[] vertices = m_points.sharedMesh.vertices;
                if (vertices.Length == 0)
                {
                    return;
                }

                PickResult pointPickResult = PickPoint(vertices);
                pointPickResult.Distance *= 0.1f;
                PickResult edgePickResult = PickEdge(vertices);

                if (pointPickResult.Distance < edgePickResult.Distance)
                {
                    if (m_selectedEdgeIndex != -1)
                    {
                        Color[] colors = m_lines.sharedMesh.colors;
                        Color   color  = GetColor(m_currentAxis);
                        colors[m_selectedEdgeIndex * 2]     = color;
                        colors[m_selectedEdgeIndex * 2 + 1] = color;
                        m_lines.sharedMesh.colors           = colors;

                        m_selectedEdgeIndex = -1;
                    }

                    if (pointPickResult.Index != m_selectedPointIndex)
                    {
                        Color[] colors = m_points.sharedMesh.colors;
                        if (m_selectedPointIndex >= 0)
                        {
                            colors[m_selectedPointIndex] = GetColor(m_currentAxis);
                        }

                        m_selectedPointIndex = pointPickResult.Index;

                        if (m_selectedPointIndex >= 0)
                        {
                            colors[m_selectedPointIndex] = Appearance.Colors.SelectionColor;
                        }

                        m_points.sharedMesh.colors = colors;
                    }
                }
                else if (edgePickResult.Distance < pointPickResult.Distance)
                {
                    if (m_selectedPointIndex != -1)
                    {
                        Color[] colors = m_points.sharedMesh.colors;
                        colors[m_selectedPointIndex] = GetColor(m_currentAxis);
                        m_points.sharedMesh.colors   = colors;
                        m_selectedPointIndex         = -1;
                    }

                    if (edgePickResult.Index != m_selectedEdgeIndex)
                    {
                        Color[] colors = m_lines.sharedMesh.colors;
                        if (m_selectedEdgeIndex >= 0)
                        {
                            Color color = GetColor(m_currentAxis);
                            colors[m_selectedEdgeIndex * 2]     = color;
                            colors[m_selectedEdgeIndex * 2 + 1] = color;
                        }

                        m_selectedEdgeIndex = edgePickResult.Index;

                        if (m_selectedEdgeIndex >= 0)
                        {
                            Color color = Appearance.Colors.SelectionColor;
                            colors[m_selectedEdgeIndex * 2]     = color;
                            colors[m_selectedEdgeIndex * 2 + 1] = color;
                        }
                        m_lines.sharedMesh.colors = colors;
                    }
                }
            }
        }
コード例 #23
0
ファイル: AdvancedUI.cs プロジェクト: FabianKowatsch/Fusee
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            RC.Viewport(0, 0, Width, Height);

            #region Controls

            // Mouse and keyboard movement
            if (Input.Keyboard.LeftRightAxis != 0 || Input.Keyboard.UpDownAxis != 0)
            {
                _keys = true;
            }

            if (Input.Mouse.LeftButton)
            {
                _keys         = false;
                _angleVelHorz = -RotationSpeed * Input.Mouse.XVel * Time.DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * Input.Mouse.YVel * Time.DeltaTime * 0.0005f;
            }
            else if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                _keys = false;
                float2 touchVel = Input.Touch.GetVelocity(TouchPoints.Touchpoint_0);
                _angleVelHorz = -RotationSpeed * touchVel.x * Time.DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * touchVel.y * Time.DeltaTime * 0.0005f;
            }
            else
            {
                if (_keys)
                {
                    _angleVelHorz = -RotationSpeed * Input.Keyboard.LeftRightAxis * Time.DeltaTime;
                    _angleVelVert = -RotationSpeed * Input.Keyboard.UpDownAxis * Time.DeltaTime;
                }
                else
                {
                    float curDamp = (float)System.Math.Exp(-Damping * Time.DeltaTime);
                    _angleVelHorz *= curDamp;
                    _angleVelVert *= curDamp;
                }
            }

            _angleHorz += _angleVelHorz;
            _angleVert += _angleVelVert;

            // Create the camera matrix and set it as the current ModelView transformation
            float4x4 mtxRot = float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz);
            float4x4 mtxCam = float4x4.LookAt(0, 0, -5, 0, 0, 0, 0, 1, 0);

            float4x4 view         = mtxCam * mtxRot;
            float4x4 perspective  = float4x4.CreatePerspectiveFieldOfView(_fovy, (float)Width / Height, ZNear, ZFar);
            float4x4 orthographic = float4x4.CreateOrthographic(Width, Height, ZNear, ZFar);

            #endregion Controls

            //Annotations will be updated according to circle positions.
            //Lines will be updated according to circle and annotation positions.
            RC.View       = view;
            RC.Projection = perspective;
            SceneNode canvas = _gui.Children[0];

            foreach (SceneNode child in canvas.Children)
            {
                if (!child.Name.Contains("MarkModelContainer"))
                {
                    continue;
                }

                //1. Calculate the circles canvas position.
                for (int k = 0; k < child.Children.Count; k++)
                {
                    SceneNode container = child.Children[k];

                    SceneNode          circle  = container.Children[0];
                    UserInterfaceInput uiInput = _uiInput[k];

                    //the monkey's matrices
                    SceneNode monkey     = _scene.Children[0];
                    float4x4  model      = monkey.GetGlobalTransformation();
                    float4x4  projection = perspective;

                    float4x4 mvpMonkey = projection * view * model;

                    float3 clipPos         = float4x4.TransformPerspective(mvpMonkey, uiInput.Position); //divides by 2
                    float2 canvasPosCircle = new float2(clipPos.x, clipPos.y) * 0.5f + 0.5f;

                    canvasPosCircle.x      *= _canvasWidth;
                    canvasPosCircle.y      *= _canvasHeight;
                    uiInput.CircleCanvasPos = canvasPosCircle;

                    var pos = new float2(uiInput.CircleCanvasPos.x - (uiInput.Size.x / 2), uiInput.CircleCanvasPos.y - (uiInput.Size.y / 2)); //we want the lower left point of the rect that encloses the
                    circle.GetComponent <RectTransform>().Offsets = GuiElementPosition.CalcOffsets(AnchorPos.Middle, pos, _canvasHeight, _canvasWidth, uiInput.Size);

                    //1.1   Check if circle is visible

                    PickResult newPick = _scenePicker.Pick(RC, new float2(clipPos.x, clipPos.y)).ToList().OrderBy(pr => pr.ClipPos.z).FirstOrDefault();

                    if (newPick != null && uiInput.AffectedTriangles[0] == newPick.Triangle) //VISIBLE
                    {
                        uiInput.IsVisible = true;

                        var effect = circle.GetComponent <SurfaceEffect>();
                        effect.SetDiffuseAlphaInShaderEffect(UserInterfaceHelper.alphaVis);
                    }
                    else
                    {
                        uiInput.IsVisible = false;
                        var effect = circle.GetComponent <SurfaceEffect>();
                        effect.SetDiffuseAlphaInShaderEffect(UserInterfaceHelper.alphaInv);
                    }

                    //1.2   Calculate annotation positions without intersections.
                    if (!uiInput.CircleCanvasPos.Equals(uiInput.CircleCanvasPosCache))
                    {
                        float yPosScale = uiInput.CircleCanvasPos.y / _canvasHeight;
                        yPosScale = (yPosScale - 0.5f) * 2f;
                        uiInput.AnnotationCanvasPos.y = uiInput.CircleCanvasPos.y - (UserInterfaceHelper.AnnotationDim.y / 2) + (2 * UserInterfaceHelper.AnnotationDim.y * yPosScale);

                        if (uiInput.CircleCanvasPos.x > _canvasWidth / 2) //RIGHT
                        {
                            uiInput.AnnotationCanvasPos.x = UserInterfaceHelper.CanvasWidthInit - UserInterfaceHelper.AnnotationDim.x - UserInterfaceHelper.AnnotationDistToLeftOrRightEdge;
                        }
                        else
                        {
                            uiInput.AnnotationCanvasPos.x = UserInterfaceHelper.AnnotationDistToLeftOrRightEdge;
                        }
                    }
                    _uiInput[k] = uiInput;
                }

                // 2.   Find intersecting annotations and correct their position in _uiInput.
                //      Disable rendering of annotation if its corresponding circle is not visible.
                for (int k = 0; k < child.Children.Count; k++)
                {
                    SceneNode          container  = child.Children[k];
                    SceneNode          annotation = container.Children[1];
                    UserInterfaceInput uiInput    = _uiInput[k];

                    if (uiInput.IsVisible)
                    {
                        if (!uiInput.CircleCanvasPos.Equals(uiInput.CircleCanvasPosCache))
                        {
                            Dictionary <int, float2> intersectedAnnotations = new();
                            int iterations = 0;
                            CalculateNonIntersectingAnnotationPositions(ref uiInput, ref intersectedAnnotations, ref iterations);
                        }

                        annotation.GetComponent <NineSlicePlane>().Active = true;
                        foreach (Mesh comp in annotation.GetComponentsInChildren <Mesh>())
                        {
                            comp.Active = true;
                        }
                    }
                    else
                    {
                        annotation.GetComponent <NineSlicePlane>().Active = false;
                        foreach (Mesh comp in annotation.GetComponentsInChildren <Mesh>())
                        {
                            comp.Active = false;
                        }
                    }
                }

                // 3.   Update annotation positions on canvas and draw line
                for (int k = 0; k < child.Children.Count; k++)
                {
                    SceneNode container = child.Children[k];

                    SceneNode          line    = container.Children[2];
                    UserInterfaceInput uiInput = _uiInput[k];

                    if (uiInput.IsVisible)
                    {
                        if (!uiInput.CircleCanvasPos.Equals(uiInput.CircleCanvasPosCache))
                        {
                            UpdateAnnotationOffsets(child.Children[uiInput.Identifier].Children[1], uiInput);
                            DrawLine(child.Children[uiInput.Identifier].Children[2], uiInput);
                        }
                    }

                    DrawLine(line, uiInput);

                    uiInput.CircleCanvasPosCache = uiInput.CircleCanvasPos;
                    _uiInput[k] = uiInput;
                }
            }

            _sceneRenderer.Render(RC);
            RC.Projection = _canvasRenderMode == CanvasRenderMode.Screen ? orthographic : perspective;
            // Constantly check for interactive objects.
            if (!Input.Mouse.Desc.Contains("Android"))
            {
                _sih.CheckForInteractiveObjects(RC, Input.Mouse.Position, Width, Height);
            }

            if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Input.Touch.TwoPoint)
            {
                _sih.CheckForInteractiveObjects(RC, Input.Touch.GetPosition(TouchPoints.Touchpoint_0), Width, Height);
            }
            _guiRenderer.Render(RC);

            Present();
        }
コード例 #24
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // _baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            _rad1Transform = _scene.Children.FindNodes(node => node.Name == "Rad1")?.FirstOrDefault()?.GetTransform();
            float rad1Rotation = _rad1Transform.Rotation.y;

            rad1Rotation           += 2 * Keyboard.UpDownAxis * DeltaTime;
            _rad1Transform.Rotation = new float3(0, rad1Rotation, 0);

            _rad2Transform = _scene.Children.FindNodes(node => node.Name == "Rad2")?.FirstOrDefault()?.GetTransform();
            float rad2Rotation = _rad2Transform.Rotation.y;

            rad2Rotation           += 2 * Keyboard.UpDownAxis * DeltaTime;
            _rad2Transform.Rotation = new float3(0, rad2Rotation, 0);

            _rad3Transform = _scene.Children.FindNodes(node => node.Name == "Rad3")?.FirstOrDefault()?.GetTransform();
            float rad3Rotation = _rad3Transform.Rotation.y;

            rad3Rotation           += 2 * Keyboard.UpDownAxis * DeltaTime;
            _rad3Transform.Rotation = new float3(0, rad3Rotation, 0);

            _rad4Transform = _scene.Children.FindNodes(node => node.Name == "Rad4")?.FirstOrDefault()?.GetTransform();
            float rad4Rotation = _rad4Transform.Rotation.y;

            rad4Rotation           += 2 * Keyboard.UpDownAxis * DeltaTime;
            _rad4Transform.Rotation = new float3(0, rad4Rotation, 0);

            _griffTransform = _scene.Children.FindNodes(node => node.Name == "Griff")?.FirstOrDefault()?.GetTransform();
            float griffRotation = _griffTransform.Rotation.y;

            griffRotation += 0.1f * Keyboard.UpDownAxis;

            if (griffRotation > 1.5f)
            {
                griffRotation = 1.5f;
            }
            if (griffRotation < 0)
            {
                griffRotation = 0;
            }

            _griffTransform.Rotation = new float3(0, griffRotation, 0);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, -1, 10) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0)) * float4x4.CreateRotationY(_camAngle);

            if (Mouse.RightButton)
            {
                _camSpeed = Mouse.Velocity.x;
            }
            else
            {
                _camSpeed = _camSpeed * 0.9f;
            }

            _camAngle = _camAngle + 0.005f * _camSpeed * Time.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)
                    {
                        _currentPick.Node.GetComponent <ShaderEffectComponent>().Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        _oldColor = (float3)newPick.Node.GetComponent <ShaderEffectComponent>().Effect.GetEffectParam("DiffuseColor");
                        newPick.Node.GetComponent <ShaderEffectComponent>().Effect.SetEffectParam("DiffuseColor", new float3(_oldColor.r * 0.5f, _oldColor.g * 0.5f, _oldColor.b * 0.5f));
                    }
                    _currentPick = newPick;
                }
            }

            // 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();

                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    Diagnostics.Log(pickResults[0].Node.Name);
                }
            }

            // 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();
        }
コード例 #25
0
ファイル: AssetsPicking.cs プロジェクト: Lichtfarbenspiel/CG
        // 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();
        }
コード例 #26
0
        // RenderAFrame is called once a frame
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

            /*_rightWheelFrontTransform.Rotation = new float3(0, -M.MinAngle(TimeSinceStart), 0);
             * _leftWheelFrontTransform.Rotation = new float3(0, -M.MinAngle(TimeSinceStart), 0);
             * _rightWheelBackTransform.Rotation = new float3(0, -M.MinAngle(TimeSinceStart), 0);
             * _leftWheelBackTransform.Rotation = new float3(0, -M.MinAngle(TimeSinceStart), 0);*/

            _rightWheelFrontTransform.Rotation.y += Keyboard.WSAxis * DeltaTime;
            _leftWheelFrontTransform.Rotation.y  += Keyboard.WSAxis * DeltaTime;
            _rightWheelBackTransform.Rotation.y  += Keyboard.WSAxis * DeltaTime;
            _leftWheelBackTransform.Rotation.y   += Keyboard.WSAxis * DeltaTime;



            //_bodyTransform.Translation.xz += Keyboard.ADAxis * DeltaTime;
            _bodyTransform.Translation.z += Keyboard.LeftRightAxis / 10;
            _bodyTransform.Translation.x += Keyboard.WSAxis / 10;
            _bodyTransform.Rotation.y    += Keyboard.ADAxis * DeltaTime;


            //_scenePick.Pick(RC, pickPosClip)


            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float)Math.Atan(15.0 / 40.0));

            //Red Base movement
            _firstExcavatorArmTransform.Rotation.y += Keyboard.UpDownAxis * DeltaTime;

            //Green UpperArm movement
            //_secondExcavatorArmTransform.Rotation.x += Keyboard.UpDownAxis * DeltaTime;

            //Blue UpperArm movement
            //_thirdExcavatorArmTransform.Rotation.x += Keyboard.WSAxis * DeltaTime;


            //binding piece movement
            //_bindingHandTransform.Rotation.y += Keyboard.ADAxis * DeltaTime;

            //Create Moving possibility with mouse to look around
            if (Mouse.LeftButton)
            {
                _keys         = false;
                _angelVelHorz = -RotationSpeed * Mouse.XVel * DeltaTime * 0.0005f;
                _angelVelVert = -RotationSpeed * Mouse.YVel * DeltaTime * 0.0005f;
            }
            else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                _keys = false;
                var touchVel = Touch.GetVelocity(TouchPoints.Touchpoint_0);
                _angelVelHorz = -RotationSpeed * touchVel.x * DeltaTime * 0.0005f;
                _angelVelVert = -RotationSpeed * touchVel.y * DeltaTime * 0.0005f;
            }
            else
            {
                if (_keys)
                {
                    _angelVelHorz = -RotationSpeed * Keyboard.LeftRightAxis * DeltaTime;
                    _angelVelVert = -RotationSpeed * Keyboard.UpDownAxis * DeltaTime;
                }
                else
                {
                    var curDamp = (float)System.Math.Exp(-Damping * DeltaTime);
                    _angelVelHorz *= curDamp;
                    _angelVelVert *= curDamp;
                }
            }

            _angelHorz += _angelVelHorz;
            _angelVert += _angelVelVert;

            var mtxRot = float4x4.CreateRotationX(_angelVert) * float4x4.CreateRotationY(_angelHorz);
            var mtxCam = float4x4.LookAt(0, 10, -30, 0, 0, 0, 0, 1, 0);

            RC.View = mtxCam * mtxRot;

            //_firstHandTransform.Rotation.x = -_angel;
            //_secondHandTransform.Rotation.x = _angel;

            if (opening)
            {
                if (_angel < 0.5f)
                {
                    _angel += 0.5f * DeltaTime;
                }
            }
            else
            {
                if (_angel > -0.5f)
                {
                    _angel -= 0.5f * DeltaTime;
                }
            }

            if (Keyboard.GetKey(KeyCodes.Space))
            {
                if (!spacePressed)
                {
                    opening = !opening;
                }
                spacePressed = true;
            }
            else
            {
                spacePressed = false;
            }

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);

                PickResult newPick = _scenePicker.Pick(RC, pickPosClip).OrderBy(pr => pr.ClipPos.z).FirstOrDefault();
                _keys = false;


                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        var ef = _currentPick.Node.GetComponent <DefaultSurfaceEffect>();
                        ef.SurfaceInput.Albedo = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var ef = newPick.Node.GetComponent <SurfaceEffect>();
                        _oldColor = ef.SurfaceInput.Albedo;
                        ef.SurfaceInput.Albedo = (float4)ColorUint.OrangeRed;
                        Diagnostics.Debug("The picked object is " + newPick.Node.Name);
                        var eftransform = newPick.Node.GetComponent <Transform>();
                        eftransform.Rotation.y += Keyboard.UpDownAxis * DeltaTime;
                    }
                    _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();
        }
コード例 #27
0
 public override PickResult Pick(PickContext context)
 {
     _loadBalancer.PickCount++;
     return(PickResult.ForDrop(new Status(StatusCode.DataLoss, string.Empty)));
 }
コード例 #28
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //   _rightRearTransform.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(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)
                    {
                        _currentPick.Node.GetMaterial().Diffuse.Color = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var mat = newPick.Node.GetMaterial();
                        _oldColor         = mat.Diffuse.Color;
                        mat.Diffuse.Color = new float3(0, 1f, 1f);
                    }
                    _currentPick = newPick;
                }
            }

            //   _gunTransform.Rotation = new float3(0,0,1.5f);
            //  _leftFrontTransform.Rotation = new float3(5,0,0);

            if (_currentPick != null)
            {
                if (_currentPick.Node.Name == "hull")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _tankTransform.Translation += new float3(-3 * Keyboard.UpDownAxis * DeltaTime, 0, 0);
                        _radvl.Rotation            += new float3(-3 * Keyboard.UpDownAxis * DeltaTime, 0, 0);
                        _radvr.Rotation            += new float3(-3 * Keyboard.UpDownAxis * DeltaTime, 0, 0);

                        _radhl.Rotation += new float3(-3 * Keyboard.UpDownAxis * DeltaTime, 0, 0);
                        _radhr.Rotation += new float3(-3 * Keyboard.UpDownAxis * DeltaTime, 0, 0);
                    }
                }
                if (_currentPick.Node.Name == "hull")
                {
                    if (Keyboard.LeftRightAxis != 0)
                    {
                        _tankTransform.Rotation += new float3(0, -3f * Keyboard.LeftRightAxis * DeltaTime, 0);
                        _radvl.Rotation         += new float3(-3f * Keyboard.LeftRightAxis * DeltaTime, 0, 0);
                        _radvr.Rotation         += new float3(-3f * Keyboard.LeftRightAxis * DeltaTime, 0, 0);

                        _radhl.Rotation += new float3(-3f * Keyboard.LeftRightAxis * DeltaTime, 0, 0);
                        _radhr.Rotation += new float3(-3f * Keyboard.LeftRightAxis * DeltaTime, 0, 0);
                    }
                }
                if (_currentPick.Node.Name == "turm")
                {
                    if (Keyboard.LeftRightAxis != 0)
                    {
                        _turretTransform.Rotation += new float3(0, 0.9f * Keyboard.LeftRightAxis * DeltaTime, 0);
                    }
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _gunTransform1.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                        _gunTransform2.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                        _gunTransform3.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                    }
                }

                if (_currentPick.Node.Name == "gun1")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _gunTransform1.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                    }
                }

                if (_currentPick.Node.Name == "gun2")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _gunTransform2.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                    }
                }
                if (_currentPick.Node.Name == "gun3")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _gunTransform3.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                    }
                }

                if (_currentPick.Node.Name == "rad_vr")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _radvr.Rotation += new float3(-0.02f * Keyboard.UpDownAxis, 0, 0);
                    }
                }
                if (_currentPick.Node.Name == "rad_vl")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _radvl.Rotation += new float3(-0.02f * Keyboard.UpDownAxis, 0, 0);
                    }
                }

                if (_currentPick.Node.Name == "rad_hl")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _radhl.Rotation += new float3(-0.02f * Keyboard.UpDownAxis, 0, 0);
                    }
                }
                if (_currentPick.Node.Name == "rad_hr")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _radhr.Rotation += new float3(-0.025f * Keyboard.UpDownAxis, 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();
        }
コード例 #29
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Mouse and keyboard movement
            if (Mouse.LeftButton)
            {
                _pick    = true;
                _pickPos = Mouse.Position;
            }
            else
            {
                _pick  = false;
                toggle = false;
            }

            _DistanceFactor = _DistanceFactor + Mouse.WheelVel * 0.001f;

            _LookAtPosition   = float3.Lerp(_LookAtPositionLerpTo, _LookAtPositionLerpFrom, _LerpTimer);
            _LookFromPosition = float3.Lerp(_LookFromPositionLerpTo, _LookFromPositionLerpFrom, _LerpTimer);

            var mtxCam = float4x4.LookAt(_LookFromPosition * _DistanceFactor, _LookAtPosition, _LookUpDefault);

            if (_pick && !toggle)
            {
                float2 pickPosClip = _pickPos * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);

                _scenePicker.View = mtxCam;

                PickResult newPick = _scenePicker.Pick(pickPosClip).ToList().OrderBy(pr => pr.ClipPos.z).FirstOrDefault();


                if (newPick != null)
                {
                    Diagnostics.Log("PositionCenter: " + GetTriagleCenter(newPick));
                    Diagnostics.Log("PositionBary: " + GetTriagleBarycentric(newPick));
                    Diagnostics.Log("NormalsCenter: " + GetNormalsCenter(newPick));
                    Diagnostics.Log("NormalBary: " + GetNormalsBarycentric(newPick));
                    _LookAtPositionLerpFrom = _LookAtPosition;
                    _LookAtPositionLerpTo   = GetTriagleBarycentric(newPick);

                    _LookFromPositionLerpFrom = _LookFromPosition;
                    _LookFromPositionLerpTo   = GetTriagleBarycentric(newPick) + GetNormalsBarycentric(newPick);

                    _LerpTimer = 1;

                    toggle = true;
                }
            }

            // Render the scene loaded in Init()
            RC.ModelView = mtxCam;
            _sceneRenderer.Render(RC);
            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();

            if (_LerpTimer > 0)
            {
                _LerpTimer -= (Time.DeltaTime / _LerpSpeed);
            }

            if (_LerpTimer < 0)
            {
                _LerpTimer = 0;
            }
        }
コード例 #30
0
 private void GetNormals(PickResult pr, out float3 a, out float3 b, out float3 c)
 {
     a = pr.Mesh.Normals[pr.Mesh.Triangles[pr.Triangle + 0]];
     b = pr.Mesh.Normals[pr.Mesh.Triangles[pr.Triangle + 1]];
     c = pr.Mesh.Normals[pr.Mesh.Triangles[pr.Triangle + 2]];
 }