Ejemplo n.º 1
0
        public static void test()
        {
            stdTest("Create Plane with a, b, c, d", new Plane(0, 1, 0, 0));
            stdTest("Create Plane with Normal and point", new Plane(new Vector3f(0, 1, 0), new Vector3f(0, 0, 0)));
            stdTest("Create Plane with Normal and another point", new Plane(new Vector3f(0, 1, 0), new Vector3f(30, 0, 20)));
            stdTest("Create Plane with 3 vectors", new Plane(new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 0.0f, -1.0f)));

            Check.AssertEquals(new Plane(0, 0, 0, 0), new Plane(0, 0, 0, 0));

            Vector3f v = new Vector3f(1.0f, 1.0f, 1.0f).Normalize();
            Plane p = new Plane(v.x, v.y, v.z, 0);
            Check.AssertEquals(p.ToString(), p.distanceTo(new Vector3f(0.0f, 0.0f, 0.0f)), 0.0f);
            p = new Plane(v.x, v.y, v.z, 2);
            Check.AssertEquals(p.ToString(), p.distanceTo(new Vector3f(0.0f, 0.0f, 0.0f)).ToString(), 2.0f.ToString());
            p = new Plane(v.x, v.y, v.z, -2);
            Check.AssertEquals(p.ToString(), p.distanceTo(new Vector3f(0.0f, 0.0f, 0.0f)).ToString(), (-2.0f).ToString());

            p = new Plane(new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f( 10.0f, -10.0f, 10.0f), new Vector3f(5.0f, 10.0f, 10.0f));

            Check.AssertEquals(p.distanceTo(new Vector3f(0.0f, 0.0f, 0.0f)), 0.0f);
            Check.AssertEquals(p.distanceTo(new Vector3f(5.0f, 10.0f, 10.0f)), 0.0f);
            Check.AssertEquals(p.distanceTo(new Vector3f(10.0f, -10.0f, 10.0f)), 0.0f);
            Check.AssertEquals(p.distanceTo(new Vector3f(0.0f, 0.0f, 5.0f)) >= 0 , true);
        }
Ejemplo n.º 2
0
 public Line(Vector3f pointAOnLine, Vector3f pointBOnLine, Vector3f pointNotOnLine)
 {
     p0 = new Plane(pointAOnLine, pointBOnLine, pointNotOnLine);
     Vector3f temp = pointAOnLine - pointBOnLine;
     p1 = new Plane(temp.Cross(p1.getNormal()), pointAOnLine);
 }
Ejemplo n.º 3
0
        public void calculateFrustum()
        {
            Vector3f p = camera.getPosition().copy();
            //Point3f ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr;
            Vector3f Z = camera.getFrontVector().copy();
            Vector3f X = camera.getRightVector().copy();
            Vector3f Y = camera.getUpVector().copy();

            // compute the centers of the near and far planes
            nc = p + Z * camera.Near;
            fc = p + Z * camera.Far;

            // compute the 4 corners of the frustum on the near plane
            ntl = nc + Y * nearHeight - X * nearWidth;
            ntr = nc + Y * nearHeight + X * nearWidth;
            nbl = nc - Y * nearHeight - X * nearWidth;
            nbr = nc - Y * nearHeight + X * nearWidth;

            // compute the 4 corners of the frustum on the far plane
            ftl = fc + Y * farHeight - X * farWidth;
            ftr = fc + Y * farHeight + X * farWidth;
            fbl = fc - Y * farHeight - X * farWidth;
            fbr = fc - Y * farHeight + X * farWidth;

            this.right  = new Plane(p, ftr, fbr);
            this.left   = new Plane(p, fbl, ftl);

            this.top    = new Plane(p, ftl, ftr);
            this.bottom = new Plane(p, fbr, fbl);

            this.far    = new Plane(ftr, ftl, fbr);
            this.near   = new Plane(ntl, ntr, nbl);

            // compute the six planes
            // the function set3Points assumes that the points
            // are given in counter clockwise order
            /*pl[TOP].set3Points(ntr,ntl,ftl);
            pl[BOTTOM].set3Points(nbl,nbr,fbr);
            pl[LEFT].set3Points(ntl,nbl,fbl);
            pl[RIGHT].set3Points(nbr,ntr,fbr);
            pl[NEARP].set3Points(ntl,ntr,nbr);
            pl[FARP].set3Points(ftr,ftl,fbl);*/
        }
Ejemplo n.º 4
0
 private static void stdTest(string s, Plane p)
 {
     Check.AssertEquals(s, p.distanceTo(new Vector3f(0.0f, 2.0f, 0.0f)), 2.0f);
     Check.AssertEquals(s, p.distanceTo(new Vector3f(0.0f, 0.0f, 0.0f)), 0.0f);
     Check.AssertEquals(s, p.distanceTo(new Vector3f(0.0f, -2.0f, 15.0f)), -2.0f);
 }