示例#1
0
    public DCube getDCube(int i = -1)
    {
        DCube rcube = null;

        //not search by index
        if (i == -1)
        {
            foreach (DCube c in _pool)
            {
                if (c.used_state == false)
                {
                    rcube = c;
                    break;
                }
            }
            if (rcube == null)
            {
                rcube = newDcube();
            }
        }
        else
        {
            rcube = _pool.ElementAt(i);
            // FindIndex(i);
        }


        rcube.position = new Vector3(0, 0, 0);
        rcube.use();
        return(rcube);
    }
示例#2
0
 public void killDcube(DCube c)
 {
     if (_pool.Contains(c))
     {
         c.release();
     }
 }
示例#3
0
    DCube newDcube()
    {
        string n     = "cube_" + (_pool.Count + 1).ToString();
        DCube  rcube = new DCube(n, 0.04f, new Vector3(0, 0, 0), Color.gray);

        _pool.Add(rcube);
        return(rcube);
    }
    void rayMarch2(inter_point inter_p, float _step_size, float max_distance, int _max_steps, OBB _obb, Vector3 cam_pos)
    {
        //z-plane alignment
        bool    use_object = true;
        Vector3 p0         = inter_p.p0_world;
        Vector3 p1         = inter_p.p1_world;
        Vector3 cam        = cam_pos;
        Vector3 z_step     = new Vector3(0, 0, max_distance / _max_steps);

        if (use_object)
        {
            p0  = inter_p.p0_object;
            p1  = inter_p.p1_object;
            cam = _obb.w2o.MultiplyPoint3x4(cam);
            // print ("cam in object poistion :" + cam);
            z_step = _obb.w2o.MultiplyVector(z_step);
        }

        //the plane alignment should be calculated on cam pos as origin
        Vector3 p0_c  = p0 - cam;
        Vector3 z_dir = z_step.normalized;
        //step on p0-p1 align z
        Vector3 p_step          = p0_c * Vector3.Dot(z_step, z_dir) / Vector3.Dot(p0_c, z_dir);
        Vector3 p0_z_pro        = Vector3.Dot(p0_c, z_dir) * z_dir;
        float   scale_p0        = Vector3.Dot(p0_z_pro, z_dir);
        float   scale_z_step    = Vector3.Dot(z_step, z_dir);
        int     scale_p0_z_step = (int)(scale_p0 / scale_z_step);
        Vector3 z_plane         = scale_p0_z_step * z_step;
        Vector3 p0_new          = (int)(scale_p0_z_step) * scale_z_step / scale_p0 * p0_c + cam;

        int full_step = (int)((p1 - p0).magnitude / p_step.magnitude);

        for (int i = 0; i < full_step + 1; i++)
        {
            Vector3 pos = p0_new + i * p_step;
            Color   c   = sample3dTexture(pos);

            //debug cubes
            if (dcube_created == false)
            {
                // print("pos :" + pos );
                // print("color :" + c);
                DCube pd_t = pool.getDCube();
                pd_t.position = use_object ? _obb.o2w.MultiplyPoint3x4(pos) : pos;
                pd_t.color    = c;
            }
        }
    }
示例#5
0
 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);
 }