void Start()
 {
     rigidbody2D = GetComponent<Rigidbody2D>();
     collider2D = GetComponent<Collider2D>();
     animator = GetComponent<Animator>();
     raycasting = GetComponent<Raycasting>();
 }
示例#2
0
        private void InitializeRenderers()
        {
            Renderers = new Dictionary <string, Renderer>();

            Renderer raytracing = new Raytracing(
                canvas:    Canvas,
                scene:     CurrentScene,
                cameraPos: CameraPos,
                maxDepth:  10
                );

            Renderers.Add("Raytracing", raytracing);

            Renderer raycasting = new Raycasting(
                canvas:    Canvas,
                scene:     CurrentScene,
                cameraPos: CameraPos
                );

            Renderers.Add("Raycasting", raycasting);

            Renderer zbuffer = new ZBuffer(
                canvas: Canvas,
                scene:  CurrentScene
                );

            Renderers.Add("ZBuffer", zbuffer);

            RendererComboBox.DataSource    = new BindingSource(Renderers, null);
            RendererComboBox.DisplayMember = "Key";
            RendererComboBox.ValueMember   = "Value";
        }
 public override void OnInspectorGUI()
 {
     raycasting = (Raycasting)target;
     foreach (var ray in raycasting.RaycastHits)
     {
         //Handles.DrawLine(ray.from, ray.to);
     }
 }
示例#4
0
    // Start is called before the first frame update
    void Start()
    {
        grabbing = false;

        playable = true;

        sc_grabmesh = go_grabmesh.GetComponent <Raycasting>();
    }
 // Checks if all edges of the rectangle are in the bounding polygon
 public bool isInPolygon(Vector2[] boundingPolygon)
 {
     for (int i = 0; i < vertices.Length; i++)
     {
         if (!Raycasting.insidePolygon(vertices [i].pos.x, vertices [i].pos.z, boundingPolygon))
         {
             return(false);
         }
     }
     return(true);
 }
    public override List <PointInfo> completePath(PointInfo curPointInfo, PointInfo goalPointInfo, World world, bool collisionCheck = true)
    {
        List <PointInfo> path = new List <PointInfo> ();

        while (Vector3.Distance(goalPointInfo.pos, curPointInfo.pos) != 0)
        {
            curPointInfo = moveTowards(curPointInfo, goalPointInfo.pos);
            if (collisionCheck && Raycasting.insideObstacle(curPointInfo.pos.x, curPointInfo.pos.z, world.obstacles))
            {
                return(null);
            }
            path.Add(curPointInfo);
        }
        return(path);
    }
示例#7
0
    void OnSceneGUI()
    {
        Raycasting fow = (Raycasting)target;

        Handles.color = Color.white;
        Handles.DrawWireArc(fow.transform.position, Vector3.up, Vector3.forward, 360, fow.viewRadius);
        Vector3 viewAngleA = fow.DirFromAngle(-fow.viewAngle / 2, false);
        Vector3 viewAngleB = fow.DirFromAngle(fow.viewAngle / 2, false);

        Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.viewRadius);
        Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.viewRadius);

        Handles.color = Color.red;
        foreach (Transform visibleTarget in fow.visibleTargets)
        {
            Handles.DrawLine(fow.transform.position, visibleTarget.position);
        }
    }
示例#8
0
    private bool canSee(World.VisibilityVertex v1, World.VisibilityVertex v2)
    {
        var visible = true;

        if (v1.obstacleVertex && v2.obstacleVertex && v1.obstacleIndex == v2.obstacleIndex &&
            Raycasting.insidePolygon((v1.vertex.x + v2.vertex.x) / 2, (v1.vertex.y + v2.vertex.y) / 2, world.obstacles [v1.obstacleIndex]))
        {
            return(false);
        }
        else
        {
            for (var k = 0; k < world.obstacleEdges.Count; k++)
            {
                if (Raycasting.segmentsIntersect(v1.vertex, v2.vertex, world.obstacleEdges [k].vertex1, world.obstacleEdges [k].vertex2))
                {
                    return(false);
                }
            }
        }

        return(true);
    }
    void Awake()
    {
        // Controller only ever needs to be setup once
        Raycasting ray = GetComponent <Raycasting>();

        if (ray.controllerLeft != null && ray.controllerRight != null)
        {
            return;
        }

        GameObject leftController = null, rightController = null;

#if SteamVR_Legacy
        SteamVR_ControllerManager CameraRigObject = FindObjectOfType <SteamVR_ControllerManager>();
        if ((CameraRigObject = FindObjectOfType <SteamVR_ControllerManager>()) != null)
        {
            leftController      = CameraRigObject.left;
            rightController     = CameraRigObject.right;
            ray.controllerRight = rightController;
            ray.controllerLeft  = leftController;
        }
#elif SteamVR_2
        SteamVR_Behaviour_Pose[] controllers      = FindObjectsOfType <SteamVR_Behaviour_Pose>();
        if (controllers.Length > 1)
        {
            leftController  = controllers[0].inputSource.ToString() == "LeftHand" ? controllers[0].gameObject : controllers[1].inputSource.ToString() == "LeftHand" ? controllers[1].gameObject : null;
            rightController = controllers[0].inputSource.ToString() == "RightHand" ? controllers[0].gameObject : controllers[1].inputSource.ToString() == "RightHand" ? controllers[1].gameObject : null;
        }
        else
        {
            leftController  = controllers[0].inputSource.ToString() == "LeftHand" ? controllers[0].gameObject : null;
            rightController = controllers[0].inputSource.ToString() == "RightHand" ? controllers[0].gameObject : null;
        }
        ray.controllerRight = rightController;
        ray.controllerLeft  = leftController;
#endif
    }
示例#10
0
 // Leaf Constructor
 public CSGNode(float3x3 Q, float3 P, float R) : this(CSGOperation.None)
 {
     Geometry = Raycasting.Quadric(Q, P, R);
 }
示例#11
0
 private void Awake()
 {
     current      = this;
     playerCamera = Camera.main;
 }
示例#12
0
    //public

    public static void initVisibilityGraph(World world, IEnumerable <Vector2> additionalPoints = null)
    {
        var vertices  = new List <World.VisibilityVertex> ();
        var obstEdges = new List <Segment> ();

        for (var i = 0; i < world.obstacles.Count; i++)
        {
            var obstacle   = world.obstacles[i];
            var prevVertex = obstacle [obstacle.Length - 1];
            foreach (var obstVertex in obstacle)
            {
                obstEdges.Add(new Segment(prevVertex, obstVertex));
                vertices.Add(new World.VisibilityVertex(obstVertex, true, i));
                prevVertex = obstVertex;
            }
        }

        if (additionalPoints != null)
        {
            foreach (var point in additionalPoints)
            {
                vertices.Add(new World.VisibilityVertex(point, false));
            }
        }

        var visibilityGraph = new float[vertices.Count][];

        for (var i = 0; i < vertices.Count; i++)
        {
            var v1 = vertices [i];
            visibilityGraph [i] = new float[vertices.Count];
            for (var j = 0; j < vertices.Count; j++)
            {
                if (i == j)
                {
                    visibilityGraph [i] [j] = 0;
                    continue;
                }

                var v2 = vertices [j];

                var visible = true;

                // Check if the two vertices are of the same polygon and their middle point is inside the polygon
                // (this case is not handled by the intersection checking below)
                if (v1.obstacleVertex && v2.obstacleVertex && v1.obstacleIndex == v2.obstacleIndex &&
                    Raycasting.insidePolygon((v1.vertex.x + v2.vertex.x) / 2, (v1.vertex.y + v2.vertex.y) / 2, world.obstacles [v1.obstacleIndex]))
                {
                    visible = false;
                }
                else
                {
                    for (var k = 0; k < obstEdges.Count; k++)
                    {
                        if (Raycasting.segmentsIntersect(v1.vertex, v2.vertex, obstEdges [k].vertex1, obstEdges [k].vertex2))
                        {
                            visible = false;
                            break;
                        }
                    }
                }

                if (visible)
                {
                    visibilityGraph [i] [j] = Vector2.Distance(v1.vertex, v2.vertex);
                }
                else
                {
                    visibilityGraph [i] [j] = float.MaxValue;
                }
            }
        }

        world.visibilityGraph = visibilityGraph;
        world.graphVertices   = vertices;
        world.obstacleEdges   = obstEdges;
    }
示例#13
0
 // Use this for initialization
 void Start()
 {
     raycasting = GetComponent <Raycasting>();
     raycasting.layerChangeObservers += SetCursorOnLayerChange;
 }
示例#14
0
    void Start()
    {
        Button btn = startButton.GetComponent <Button>();

        btn.onClick.AddListener(TaskOnClick);

        if (data.name == "P25" || data.name == "P26")
        {
            world = World.FromJson(data.text, trajectoryData.text);
        }
        else
        {
            world = World.FromJson(data.text);
        }

        initializeVelocities();
        spawnObstacle(world.boundingPolygon, "Bounding polygon", boundingPolygon);
        spawnObstacles();
        spawnActors();
        initializeMotionModel();

        if (data.name == "P22")
        {
            solveVRP(world);
        }
        else if (data.name == "P25")
        {
            Visualizer.visualizeTrajectory(world.trajectory.x, world.trajectory.y);
            GameObject tmp = new GameObject("LeaderFormationController");
            tmp.AddComponent <LeaderFormationController> ();
            tmp.GetComponent <LeaderFormationController> ().initializeController(agents, world.trajectory, world.formationPositions, agents [0].transform.localScale.y / 2, formationDecreasingGoalVelocity);
        }
        else if (data.name == "P26")
        {
            // Formation problems
            GameObject plane = GameObject.Find("Plane");
            Renderer   ren   = plane.GetComponent <Renderer> ();
            ren.material = fieldMaterial;
            //for (int i = 0; i < world.trajectory.x.Length; i++) {
            //world.trajectory.x [i] += -10.0f;
            //world.trajectory.y [i] += 35.0f;
            //}
            Visualizer.visualizeTrajectory(world.trajectory.x, world.trajectory.y);
            agentParent.AddComponent <VirtualStructure> ();
            // Add virtual center to formation positions
            Vector2[] formationPositions = new Vector2[world.formationPositions.Length + 1];
            for (int i = 0; i < formationPositions.Length - 1; i++)
            {
                formationPositions [i] = world.formationPositions [i];
            }
            formationPositions [formationPositions.Length - 1] = new Vector2(agents [agents.Length - 1].transform.position.x, agents [agents.Length - 1].transform.position.z);              //position of virtual center.
            Debug.Log(formationPositions [formationPositions.Length - 1]);
            agentParent.GetComponent <VirtualStructure> ().initializeController(agents, world.boundingPolygon, world.trajectory, formationPositions, agents [0].transform.localScale.y / 2, deltaX, deltaY,
                                                                                simulationSpeedFactor, world.vehicle.dt, formationDecreasingGoalVelocity);
        }
        else if (data.name == "P27")
        {
            float[]   minMaxes = VirtualStructure.getMinMaxes(world.boundingPolygon);
            Vector2[] points   = new Vector2[pivotSamples];

            for (int i = 0; i < pivotSamples; i++)
            {
                do
                {
                    points[i].x = (float)(rand.NextDouble() * (minMaxes [2] - minMaxes [0]) + minMaxes [0]);
                    points[i].y = (float)(rand.NextDouble() * (minMaxes [3] - minMaxes [1]) + minMaxes [1]);
                } while ((!Raycasting.insidePolygon(points[i].x, points[i].y, world.boundingPolygon)) || Raycasting.insideObstacle(points[i].x, points[i].y, world.obstacles));
            }
            List <Vector2> addPoints = new List <Vector2> (points);
            foreach (var point in world.startPositions)
            {
                addPoints.Add(point);
            }
            foreach (var point in world.enemyPositions)
            {
                addPoints.Add(point);
            }
            VisibilityGraph.initVisibilityGraph(world, addPoints);

            agentParent.AddComponent <ShooterController> ();
            List <ShootingPlanner.OneStepPlan> gamePlan = (new ShootingPlanner(world, weaponType)).getPlan();
            agentParent.GetComponent <ShooterController> ().initializeController(gamePlan, agents);
        }
    }