void Start() { inter = new intersector(); //test cube pool pool = new DCube_pool(); dCube_rays = new List <DCube_Ray>(); //camera rays cam = this.gameObject.GetComponent(typeof(Camera)) as Camera; // print("cam wolr position :" +cam.transform.position); w_rays = 10; h_rays = (int)((float)w_rays * cam.pixelHeight / cam.pixelWidth); cam_rays = new List <AB_RAY>(); for (int i = 0; i < h_rays; i++) { //need to create the last ray at right edge for (int j = 0; j < w_rays; j++) { //create ray at correct gap Ray myRay = cam.ViewportPointToRay(new Vector3(1.0f / (w_rays - 1) * j, 1.0f / (h_rays - 1) * i, 0)); GameObject A_object = new GameObject(); A_object.transform.position = myRay.origin; Vector3 B = (myRay.origin - cam.transform.position) * cam.farClipPlane / cam.nearClipPlane + cam.transform.position; GameObject B_object = new GameObject(); B_object.transform.position = B; // DCube fc = pool.getDCube(); // fc.position = B; // fc.setParent(cam.transform); // DCube nc = pool.getDCube(); // nc.position = myRay.origin; // nc.setParent(cam.transform); AB_RAY cam_ab_ray = new AB_RAY(A_object.transform, B_object.transform); cam_rays.Add(cam_ab_ray); } } //test the cube is a obb or aabb if (is_aabb) { aabb = new AABB(test_cube); //debug cubes for a ray dcubes = new DCube_Ray(pool); } else { obb = new OBB(test_cube); //debug cubes for a ray dcubes = new DCube_Ray(pool); } //create ray ab_ray = new AB_RAY(cam.transform, GetComponent <Transform>().Find("cam_ray_handeler")); //ray march parameters max_distance = cam.farClipPlane - cam.nearClipPlane; step_size = max_distance / max_steps; }
public DCube_Ray(DCube_pool p) { this._pool = p; this.p0 = this._pool.getDCube(); this.p1 = this._pool.getDCube(); this.x0 = this._pool.getDCube(); this.x1 = this._pool.getDCube(); this.y0 = this._pool.getDCube(); this.y1 = this._pool.getDCube(); this.z0 = this._pool.getDCube(); this.z1 = this._pool.getDCube(); this.p0.color = new Color(0f, 2000f, 2000f); this.p1.color = new Color(0f, 1f, 1f); this.x0.color = new Color(2000f, 0f, 0f); this.x1.color = new Color(1f, 0f, 0f); this.y0.color = new Color(0f, 2000f, 0f); this.y1.color = new Color(0f, 1f, 0f); this.z0.color = new Color(0f, 0f, 2000f); this.z1.color = new Color(0f, 0f, 1f); }