示例#1
0
文件: PlaneSet.cpp 项目: jefferis/rgl
void PlaneSet::updateTriangles(const AABox& sceneBBox)
{
  int perms[3][3] = { {0,0,1}, {1,2,2}, {2,1,0} };
  double bbox[2][3] = { {sceneBBox.vmin.x, sceneBBox.vmin.y, sceneBBox.vmin.z},
                       {sceneBBox.vmax.x, sceneBBox.vmax.y, sceneBBox.vmax.z} };
  double x[12][3];
  for (int elem = 0; elem < nPlanes; elem++) {
    Vertex Av = normal.getRecycled(elem);
    double A[3] = { Av.x, Av.y, Av.z };
    double d = offset.getRecycled(elem);
    int nhits = 0;
    int face1[12], face2[12]; /* to identify which faces of the cube we're on */
    
    for (int i=0; i<3; i++)
      for (int j=0; j<2; j++)
        for (int k=0; k<2; k++) {
          int u=perms[0][i], v=perms[1][i], w=perms[2][i];
          if (A[w] != 0.0) {
            double intersect = -(d + A[u]*bbox[j][u] + A[v]*bbox[k][v])/A[w];
  	  if (bbox[0][w] < intersect && intersect < bbox[1][w]) {
  	    x[nhits][u] = bbox[j][u];
  	    x[nhits][v] = bbox[k][v];
  	    x[nhits][w] = intersect;
  	    face1[nhits] = j + 2*u;
  	    face2[nhits] = k + 2*v;
  	    nhits++;
  	  }
  	}
      }
    
    if (nhits > 3) {
      /* Re-order the intersections so the triangles work */
      for (int i=0; i<nhits-2; i++) {
        int which=0; /* initialize to suppress warning */
        for (int j=i+1; j<nhits; j++) {
          if (face1[i] == face1[j] || face1[i] == face2[j] 
           || face2[i] == face1[j] || face2[i] == face2[j] ) {
            which = j;
            break;
          }
        }
        if (which > i+1) {
          for (int j=0; j<3; j++) 
            swap(x[i+1][j], x[which][j]);
          swap(face1[i+1], face1[which]);
          swap(face2[i+1], face2[which]);
        }
      }
    }
    
    if (nhits >= 3) { 
      /* Put in order so that the normal points out the FRONT of the faces */
      Vec3 v0(x[0][0] - x[1][0] , x[0][1] - x[1][1], x[0][2] - x[1][2]),
           v2(x[2][0] - x[1][0] , x[2][1] - x[1][1], x[2][2] - x[1][2]),
           vx = v0.cross(v2);
      
      bool reverse = vx*Av > 0;
      
      for (int i=0; i<nhits-2; i++) {
        setVertex(12*elem + 3*i, x[0]); 
        for (int j=1; j<3; j++) {
          if (reverse)
            setVertex(12*elem + 3*i + 3-j, x[i+j]);
          else
            setVertex(12*elem + 3*i + j, x[i+j]);
        }
      }
    } else 
      nhits = 2; /* all missing */
      
    double missing[3] = {NA_REAL, NA_REAL, NA_REAL};
    for (int i=nhits-2; i<4; i++) 
      for (int j=0; j<3; j++) 
        setVertex(12*elem + 3*i + j, missing);
  }
}
示例#2
0
void CCFlipX3D::update(float time)
{
    float angle = (float)M_PI * time; // 180 degrees
    float mz = sinf(angle);
    angle = angle / 2.0f; // x calculates degrees from 0 to 90
    float mx = cosf(angle);

    ccVertex3F v0, v1, v, diff;

    v0 = originalVertex(ccp(1, 1));
    v1 = originalVertex(ccp(0, 0));

    float    x0 = v0.x;
    float    x1 = v1.x;
    float x;
    CCPoint    a, b, c, d;

    if ( x0 > x1 )
    {
        // Normal Grid
        a = ccp(0,0);
        b = ccp(0,1);
        c = ccp(1,0);
        d = ccp(1,1);
        x = x0;
    }
    else
    {
        // Reversed Grid
        c = ccp(0,0);
        d = ccp(0,1);
        a = ccp(1,0);
        b = ccp(1,1);
        x = x1;
    }
    
    diff.x = ( x - x * mx );
    diff.z = fabsf( floorf( (x * mz) / 4.0f ) );

    // bottom-left
    v = originalVertex(a);
    v.x = diff.x;
    v.z += diff.z;
    setVertex(a, v);
    
    // upper-left
    v = originalVertex(b);
    v.x = diff.x;
    v.z += diff.z;
    setVertex(b, v);
    
    // bottom-right
    v = originalVertex(c);
    v.x -= diff.x;
    v.z -= diff.z;
    setVertex(c, v);
    
    // upper-right
    v = originalVertex(d);
    v.x -= diff.x;
    v.z -= diff.z;
    setVertex(d, v);
}
示例#3
0
void CCFlipY3D::update(float time)
{
    float angle = (float)M_PI * time; // 180 degrees
    float mz = sinf( angle );
    angle = angle / 2.0f;     // x calculates degrees from 0 to 90
    float my = cosf(angle);
    
    ccVertex3F    v0, v1, v, diff;
    
    v0 = originalVertex(ccp(1, 1));
    v1 = originalVertex(ccp(0, 0));
    
    float    y0 = v0.y;
    float    y1 = v1.y;
    float y;
    CCPoint    a, b, c, d;
    
    if (y0 > y1)
    {
        // Normal Grid
        a = ccp(0,0);
        b = ccp(0,1);
        c = ccp(1,0);
        d = ccp(1,1);
        y = y0;
    }
    else
    {
        // Reversed Grid
        b = ccp(0,0);
        a = ccp(0,1);
        d = ccp(1,0);
        c = ccp(1,1);
        y = y1;
    }
    
    diff.y = y - y * my;
    diff.z = fabsf(floorf((y * mz) / 4.0f));
    
    // bottom-left
    v = originalVertex(a);
    v.y = diff.y;
    v.z += diff.z;
    setVertex(a, v);
    
    // upper-left
    v = originalVertex(b);
    v.y -= diff.y;
    v.z -= diff.z;
    setVertex(b, v);
    
    // bottom-right
    v = originalVertex(c);
    v.y = diff.y;
    v.z += diff.z;
    setVertex(c, v);
    
    // upper-right
    v = originalVertex(d);
    v.y -= diff.y;
    v.z -= diff.z;
    setVertex(d, v);
}
void FlipY3D::update(float time)
{
    float angle = (float)M_PI * time; // 180 degrees
    float mz = sinf( angle );
    angle = angle / 2.0f;     // x calculates degrees from 0 to 90
    float my = cosf(angle);

    Vec3    v0, v1, v, diff;

    v0 = getOriginalVertex(Vec2(1.0f, 1.0f));
    v1 = getOriginalVertex(Vec2());

    float    y0 = v0.y;
    float    y1 = v1.y;
    float y;
    Vec2    a, b, c, d;

    if (y0 > y1)
    {
        // Normal Grid
        a.setZero();
        b.set(0.0f, 1.0f);
        c.set(1.0f, 0.0f);
        d.set(1.0f, 1.0f);
        y = y0;
    }
    else
    {
        // Reversed Grid
        b.setZero();
        a.set(0.0f, 1.0f);
        d.set(1.0f, 0.0f);
        c.set(1.0f, 1.0f);
        y = y1;
    }

    diff.y = y - y * my;
    diff.z = fabsf(floorf((y * mz) / 4.0f));

    // bottom-left
    v = getOriginalVertex(a);
    v.y = diff.y;
    v.z += diff.z;
    setVertex(a, v);

    // upper-left
    v = getOriginalVertex(b);
    v.y -= diff.y;
    v.z -= diff.z;
    setVertex(b, v);

    // bottom-right
    v = getOriginalVertex(c);
    v.y = diff.y;
    v.z += diff.z;
    setVertex(c, v);

    // upper-right
    v = getOriginalVertex(d);
    v.y -= diff.y;
    v.z -= diff.z;
    setVertex(d, v);
}
示例#5
0
void poOpenGLState::popVertexState() {
	setVertex(vertexStack.top());
	vertexStack.pop();
}
void CubeProjectedPolygon::merge(const CubeProjectedPolygon& that) {

    // RIGHT/NEAR
    // LEFT/NEAR
    if (
        (getProjectionType() == that.getProjectionType()) &&
        (
             getProjectionType() == (PROJECTION_RIGHT | PROJECTION_NEAR) ||
             getProjectionType() == (PROJECTION_LEFT  | PROJECTION_NEAR)
        )
       ) {
        if (getVertex(1) == that.getVertex(0) && getVertex(4) == that.getVertex(5)) {
            //setVertex(0, this.getVertex(0)); // no change
            setVertex(1, that.getVertex(1));
            setVertex(2, that.getVertex(2));
            setVertex(3, that.getVertex(3));
            setVertex(4, that.getVertex(4));
            //setVertex(5, this.getVertex(5)); // no change
            return; // done
        }
        if (getVertex(0) == that.getVertex(1) && getVertex(5) == that.getVertex(4)) {
            setVertex(0, that.getVertex(0));
            //setVertex(1, this.getVertex(1)); // no change
            //setVertex(2, this.getVertex(2)); // no change
            //setVertex(3, this.getVertex(3)); // no change
            //setVertex(4, that.getVertex(4)); // no change
            setVertex(5, that.getVertex(5));
            return; // done
        }
        if (getVertex(2) == that.getVertex(1) && getVertex(3) == that.getVertex(4)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, this.getVertex(1)); // no change
            setVertex(2, that.getVertex(2));
            setVertex(3, that.getVertex(3));
            //setVertex(4, this.getVertex(4)); // no change
            //setVertex(5, that.getVertex(5)); // no change
            return; // done
        }
        if (getVertex(1) == that.getVertex(2) && getVertex(4) == that.getVertex(3)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            //setVertex(2, this.getVertex(2)); // no change
            //setVertex(3, that.getVertex(3)); // no change
            setVertex(4, that.getVertex(4));
            setVertex(5, that.getVertex(5));
            return; // done
        }
    }

    // NEAR/BOTTOM
    if (
        (getProjectionType() == that.getProjectionType()) &&
        (
             getProjectionType() == (PROJECTION_NEAR | PROJECTION_BOTTOM)
        )
       ) {
        if (getVertex(0) == that.getVertex(5) && getVertex(3) == that.getVertex(4)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            setVertex(2, that.getVertex(2));
            setVertex(3, that.getVertex(3));
            //setVertex(4, this.getVertex(4)); // no change
            //setVertex(5, that.getVertex(5)); // no change
            return; // done
        }
        if (getVertex(5) == that.getVertex(0) && getVertex(4) == that.getVertex(3)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, that.getVertex(1)); // no change
            //setVertex(2, this.getVertex(2)); // no change
            //setVertex(3, that.getVertex(3)); // no change
            setVertex(4, that.getVertex(4));
            setVertex(5, that.getVertex(5));
            return; // done
        }
        if (getVertex(1) == that.getVertex(0) && getVertex(2) == that.getVertex(3)) {
            //setVertex(0, this.getVertex(0)); // no change
            setVertex(1, that.getVertex(1));
            setVertex(2, that.getVertex(2));
            //setVertex(3, that.getVertex(3)); // no change
            //setVertex(4, this.getVertex(4)); // no change
            //setVertex(5, that.getVertex(5)); // no change
            return; // done
        }
        if (getVertex(0) == that.getVertex(1) && getVertex(3) == that.getVertex(2)) {
            setVertex(0, that.getVertex(0));
            //setVertex(1, this.getVertex(1)); // no change
            //setVertex(2, that.getVertex(2)); // no change
            setVertex(3, that.getVertex(3));
            setVertex(4, that.getVertex(4));
            setVertex(5, that.getVertex(5));
            return; // done
        }
    }

    // NEAR/TOP
    if (
        (getProjectionType() == that.getProjectionType()) &&
        (
             getProjectionType() == (PROJECTION_NEAR | PROJECTION_TOP)
        )
       ) {
        if (getVertex(0) == that.getVertex(5) && getVertex(1) == that.getVertex(2)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            //setVertex(2, this.getVertex(2)); // no change
            //setVertex(3, that.getVertex(3)); // no change
            //setVertex(4, this.getVertex(4)); // no change
            //setVertex(5, that.getVertex(5)); // no change
            return; // done
        }
        if (getVertex(5) == that.getVertex(0) && getVertex(2) == that.getVertex(1)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, that.getVertex(1)); // no change
            setVertex(2, that.getVertex(2));
            setVertex(3, that.getVertex(3));
            setVertex(4, that.getVertex(4));
            setVertex(5, that.getVertex(5));
            return; // done
        }
        if (getVertex(4) == that.getVertex(5) && getVertex(3) == that.getVertex(2)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, that.getVertex(1)); // no change
            //setVertex(2, that.getVertex(2)); // no change
            setVertex(3, that.getVertex(3));
            setVertex(4, that.getVertex(4));
            //setVertex(5, that.getVertex(5)); // no change
            return; // done
        }
        if (getVertex(5) == that.getVertex(4) && getVertex(2) == that.getVertex(3)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            setVertex(2, that.getVertex(2));
            //setVertex(3, this.getVertex(3)); // no change
            //setVertex(4, that.getVertex(3)); // no change
            setVertex(5, that.getVertex(5));
            return; // done
        }
    }


    // RIGHT/NEAR & NEAR/RIGHT/TOP
    // LEFT/NEAR  & NEAR/LEFT/TOP
    if (
            ((getProjectionType()     == (PROJECTION_RIGHT | PROJECTION_NEAR | PROJECTION_TOP)) &&
            (that.getProjectionType() == (PROJECTION_RIGHT | PROJECTION_NEAR)))
            ||
            ((getProjectionType()     == (PROJECTION_LEFT  | PROJECTION_NEAR | PROJECTION_TOP)) &&
            (that.getProjectionType() == (PROJECTION_LEFT  | PROJECTION_NEAR)))
        )
    {
        if (getVertex(5) == that.getVertex(0) && getVertex(3) == that.getVertex(2)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, this.getVertex(1)); // no change
            //setVertex(2, this.getVertex(2)); // no change
            setVertex(3, that.getVertex(3));
            setVertex(4, that.getVertex(4));
            setVertex(5, that.getVertex(5));
            setProjectionType((PROJECTION_RIGHT | PROJECTION_NEAR));
            return; // done
        }
    }

    // RIGHT/NEAR & NEAR/RIGHT/TOP
    // LEFT/NEAR  & NEAR/LEFT/TOP
    if (
            ((that.getProjectionType() == (PROJECTION_RIGHT | PROJECTION_NEAR | PROJECTION_TOP)) &&
            (getProjectionType()       == (PROJECTION_RIGHT | PROJECTION_NEAR)))
            ||
            ((that.getProjectionType() == (PROJECTION_LEFT  | PROJECTION_NEAR | PROJECTION_TOP)) &&
            (getProjectionType()       == (PROJECTION_LEFT  | PROJECTION_NEAR)))

        )
    {
        if (getVertex(0) == that.getVertex(5) && getVertex(2) == that.getVertex(3)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            setVertex(2, that.getVertex(2));
            //setVertex(3, this.getVertex(3)); // no change
            //setVertex(4, this.getVertex(4)); // no change
            //setVertex(5, this.getVertex(5)); // no change
            //setProjectionType((PROJECTION_RIGHT | PROJECTION_NEAR)); // no change
            return; // done
        }
    }

    // RIGHT/NEAR & NEAR/RIGHT/BOTTOM
    // NEAR/LEFT & NEAR/LEFT/BOTTOM
    if (
            ((that.getProjectionType() == (PROJECTION_RIGHT | PROJECTION_NEAR | PROJECTION_BOTTOM)) &&
            (getProjectionType()       == (PROJECTION_RIGHT | PROJECTION_NEAR)))
            ||
            ((that.getProjectionType() == (PROJECTION_LEFT | PROJECTION_NEAR | PROJECTION_BOTTOM)) &&
            (getProjectionType()       == (PROJECTION_LEFT | PROJECTION_NEAR)))

        )
    {
        if (getVertex(5) == that.getVertex(0) && getVertex(3) == that.getVertex(2)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, this.getVertex(1)); // no change
            //setVertex(2, this.getVertex(2)); // no change
            setVertex(3, that.getVertex(3));
            setVertex(4, that.getVertex(4));
            setVertex(5, that.getVertex(5));
            //setProjectionType((PROJECTION_RIGHT | PROJECTION_NEAR)); // no change
            return; // done
        }
    }
    // RIGHT/NEAR & NEAR/RIGHT/BOTTOM
    // NEAR/LEFT & NEAR/LEFT/BOTTOM
    if (
            ((getProjectionType()     == (PROJECTION_RIGHT | PROJECTION_NEAR | PROJECTION_BOTTOM)) &&
            (that.getProjectionType() == (PROJECTION_RIGHT | PROJECTION_NEAR)))
            ||
            ((getProjectionType()     == (PROJECTION_LEFT | PROJECTION_NEAR | PROJECTION_BOTTOM)) &&
            (that.getProjectionType() == (PROJECTION_LEFT | PROJECTION_NEAR)))
        )
    {
        if (getVertex(0) == that.getVertex(5) && getVertex(2) == that.getVertex(3)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            setVertex(2, that.getVertex(2));
            //setVertex(3, this.getVertex(3)); // no change
            //setVertex(4, this.getVertex(4)); // no change
            //setVertex(5, this.getVertex(5)); // no change
            setProjectionType((PROJECTION_RIGHT | PROJECTION_NEAR));
            return; // done
        }
    }


    // NEAR/TOP & NEAR
    if (
            (getProjectionType()      == (PROJECTION_NEAR                   )) &&
            (that.getProjectionType() == (PROJECTION_NEAR  | PROJECTION_TOP ))
        )
    {
        if (getVertex(0) == that.getVertex(5) && getVertex(1) == that.getVertex(2)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            //setVertex(2, this.getVertex(2)); // no change
            //setVertex(3, this.getVertex(3)); // no change
            //setVertexCount(4); // no change
            //setProjectionType((PROJECTION_NEAR));  // no change
            return; // done
        }
    }

    // NEAR/TOP & NEAR
    if (
            (that.getProjectionType() == (PROJECTION_NEAR                   )) &&
            (getProjectionType()      == (PROJECTION_NEAR  | PROJECTION_TOP ))
        )
    {
        if (getVertex(5) == that.getVertex(0) && getVertex(2) == that.getVertex(1)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, this.getVertex(1)); // no change
            setVertex(2, that.getVertex(2));
            setVertex(3, that.getVertex(3));
            setVertexCount(4);
            setProjectionType((PROJECTION_NEAR));
            return; // done
        }
    }

    // NEAR/BOTTOM & NEAR
    if (
            (getProjectionType()      == (PROJECTION_NEAR                      )) &&
            (that.getProjectionType() == (PROJECTION_NEAR  | PROJECTION_BOTTOM ))
        )
    {
        if (getVertex(2) == that.getVertex(3) && getVertex(3) == that.getVertex(0)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, this.getVertex(1)); // no change
            setVertex(2, that.getVertex(4));
            setVertex(3, that.getVertex(5));
            //setVertexCount(4); // no change
            //setProjectionType((PROJECTION_NEAR));  // no change
        }
    }

    // NEAR/BOTTOM & NEAR
    if (
            (that.getProjectionType() == (PROJECTION_NEAR                      )) &&
            (getProjectionType()      == (PROJECTION_NEAR  | PROJECTION_BOTTOM ))
        )
    {
        if (getVertex(3) == that.getVertex(2) && getVertex(0) == that.getVertex(3)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            setVertex(2, getVertex(4));
            setVertex(3, getVertex(5));
            setVertexCount(4);
            setProjectionType((PROJECTION_NEAR));
            return; // done
        }
    }

    // NEAR/RIGHT & NEAR
    if (
            (getProjectionType()      == (PROJECTION_NEAR                      )) &&
            (that.getProjectionType() == (PROJECTION_NEAR  | PROJECTION_RIGHT ))
        )
    {
        if (getVertex(0) == that.getVertex(1) && getVertex(3) == that.getVertex(4)) {
            setVertex(0, that.getVertex(0));
            //setVertex(1, this.getVertex(1)); // no change
            //setVertex(2, this.getVertex(2)); // no change
            setVertex(3, that.getVertex(5));
            //setVertexCount(4); // no change
            //setProjectionType((PROJECTION_NEAR));  // no change
        }
    }

    // NEAR/RIGHT & NEAR
    if (
            (that.getProjectionType() == (PROJECTION_NEAR                      )) &&
            (getProjectionType()      == (PROJECTION_NEAR  | PROJECTION_RIGHT ))
        )
    {
        if (getVertex(1) == that.getVertex(0) && getVertex(4) == that.getVertex(3)) {
            //setVertex(0, this.getVertex(0)); // no change
            setVertex(1, that.getVertex(1));
            setVertex(2, that.getVertex(2));
            setVertex(3, getVertex(5));
            setVertexCount(4);
            setProjectionType((PROJECTION_NEAR));
            return; // done
        }
    }

    // NEAR/LEFT & NEAR
    if (
            (getProjectionType()      == (PROJECTION_NEAR                    )) &&
            (that.getProjectionType() == (PROJECTION_NEAR  | PROJECTION_LEFT ))
        )
    {
        if (getVertex(1) == that.getVertex(1) && getVertex(2) == that.getVertex(4)) {
            //setVertex(0, this.getVertex()); // no change
            setVertex(1, that.getVertex(2));
            setVertex(2, that.getVertex(3));
            //setVertex(3, this.getVertex(3)); // no change
            //setVertexCount(4); // no change
            //setProjectionType((PROJECTION_NEAR));  // no change
            return; // done
        }
    }

    // NEAR/LEFT & NEAR
    if (
            (that.getProjectionType() == (PROJECTION_NEAR                    )) &&
            (getProjectionType()      == (PROJECTION_NEAR  | PROJECTION_LEFT ))
        )
    {
        if (getVertex(1) == that.getVertex(0) && getVertex(4) == that.getVertex(3)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, getVertex(2));
            setVertex(2, getVertex(3));
            setVertex(3, that.getVertex(3));
            setVertexCount(4);
            setProjectionType((PROJECTION_NEAR));
            return; // done
        }
    }

    // NEAR/RIGHT/TOP & NEAR/TOP
    if (
            ((getProjectionType()     == (PROJECTION_TOP | PROJECTION_NEAR                     )) &&
            (that.getProjectionType() == (PROJECTION_TOP | PROJECTION_NEAR  | PROJECTION_RIGHT )))
        )
    {
        if (getVertex(0) == that.getVertex(1) && getVertex(4) == that.getVertex(3)) {
            setVertex(0, that.getVertex(0));
            //setVertex(1, this.getVertex(1)); // no change
            //setVertex(2, this.getVertex(2)); // no change
            //setVertex(3, this.getVertex(3)); // no change
            setVertex(4, that.getVertex(4));
            setVertex(5, that.getVertex(5));
            return; // done
        }
    }

    // NEAR/RIGHT/TOP & NEAR/TOP
    if (
            ((that.getProjectionType() == (PROJECTION_TOP | PROJECTION_NEAR                     )) &&
            (getProjectionType()      == (PROJECTION_TOP | PROJECTION_NEAR  | PROJECTION_RIGHT )))
        )
    {
        if (getVertex(1) == that.getVertex(0) && getVertex(3) == that.getVertex(4)) {
            //setVertex(0, this.getVertex(0)); // no change
            setVertex(1, that.getVertex(1));
            setVertex(2, that.getVertex(2));
            setVertex(3, that.getVertex(3));
            //setVertex(4, this.getVertex(4)); // no change
            //setVertex(5, this.getVertex(5)); // no change
            setProjectionType((PROJECTION_TOP | PROJECTION_NEAR));
            return; // done
        }
    }


    // NEAR/RIGHT/BOTTOM & NEAR/BOTTOM
    if (
            ((getProjectionType()     == (PROJECTION_BOTTOM | PROJECTION_NEAR                     )) &&
            (that.getProjectionType() == (PROJECTION_BOTTOM | PROJECTION_NEAR  | PROJECTION_RIGHT )))
        )
    {
        if (getVertex(1) == that.getVertex(2) && getVertex(5) == that.getVertex(4)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            //setVertex(2, this.getVertex(2)); // no change
            //setVertex(3, this.getVertex(3)); // no change
            //setVertex(4, this.getVertex(4)); // no change
            setVertex(5, that.getVertex(5));
            return; // done
        }
    }

    // NEAR/RIGHT/BOTTOM & NEAR/BOTTOM
    if (
            ((that.getProjectionType() == (PROJECTION_BOTTOM | PROJECTION_NEAR                     )) &&
            (getProjectionType()       == (PROJECTION_BOTTOM | PROJECTION_NEAR  | PROJECTION_RIGHT )))
        )
    {
        if (getVertex(2) == that.getVertex(1) && getVertex(4) == that.getVertex(5)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, this.getVertex(1)); // no change
            setVertex(2, that.getVertex(2));
            setVertex(3, that.getVertex(3));
            setVertex(4, that.getVertex(4));
            //setVertex(5, this.getVertex(5)); // no change
            setProjectionType((PROJECTION_BOTTOM | PROJECTION_NEAR));
            return; // done
        }
    }

    // NEAR/LEFT/BOTTOM & NEAR/BOTTOM
    if (
            ((getProjectionType()     == (PROJECTION_BOTTOM | PROJECTION_NEAR                     )) &&
            (that.getProjectionType() == (PROJECTION_BOTTOM | PROJECTION_NEAR  | PROJECTION_LEFT )))
        )
    {
        if (getVertex(2) == that.getVertex(0) && getVertex(4) == that.getVertex(4)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, this.getVertex(1)); // no change
            setVertex(2, that.getVertex(1));
            setVertex(3, that.getVertex(2));
            setVertex(4, that.getVertex(3));
            //setVertex(5, this.getVertex(5)); // no change
            return; // done
        }
    }

    // NEAR/LEFT/BOTTOM & NEAR/BOTTOM
    if (
            ((that.getProjectionType() == (PROJECTION_BOTTOM | PROJECTION_NEAR                     )) &&
            (getProjectionType()       == (PROJECTION_BOTTOM | PROJECTION_NEAR  | PROJECTION_LEFT )))
        )
    {
        if (getVertex(0) == that.getVertex(2) && getVertex(4) == that.getVertex(4)) {
            // we need to do this in an unusual order, because otherwise we'd overwrite our own values
            setVertex(4, getVertex(3));
            setVertex(3, getVertex(2));
            setVertex(2, getVertex(1));
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            setVertex(5, that.getVertex(5));
            setProjectionType((PROJECTION_BOTTOM | PROJECTION_NEAR));
            return; // done
        }
    }


    // RIGHT/NEAR/BOTTOM
    // RIGHT/NEAR/TOP
    // LEFT/NEAR/BOTTOM
    // LEFT/NEAR/TOP
    if (
            (getProjectionType() == that.getProjectionType()) &&
            (
                getProjectionType() == (PROJECTION_RIGHT | PROJECTION_NEAR | PROJECTION_BOTTOM ) ||
                getProjectionType() == (PROJECTION_RIGHT | PROJECTION_NEAR | PROJECTION_TOP    ) ||
                getProjectionType() == (PROJECTION_LEFT  | PROJECTION_NEAR | PROJECTION_BOTTOM ) ||
                getProjectionType() == (PROJECTION_LEFT  | PROJECTION_NEAR | PROJECTION_TOP    )
            )
       ) {
        if (getVertex(0) == that.getVertex(5) && getVertex(2) == that.getVertex(3)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            setVertex(2, that.getVertex(2));
            //setVertex(3, this.getVertex(3)); // no change
            //setVertex(4, this.getVertex(4)); // no change
            //setVertex(5, this.getVertex(5)); // no change
            return; // done
        }
        if (getVertex(5) == that.getVertex(0) && getVertex(3) == that.getVertex(2)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, this.getVertex(1)); // no change
            //setVertex(2, this.getVertex(2)); // no change
            setVertex(3, that.getVertex(3));
            setVertex(4, that.getVertex(4));
            setVertex(5, that.getVertex(5));
            return; // done
        }
        if (getVertex(2) == that.getVertex(1) && getVertex(4) == that.getVertex(5)) {
            //setVertex(0, this.getVertex(0)); // no change
            //setVertex(1, this.getVertex(1)); // no change
            setVertex(2, that.getVertex(2));
            setVertex(3, that.getVertex(3));
            setVertex(4, that.getVertex(4));
            //setVertex(5, this.getVertex(5)); // no change
            return; // done
        }
        if (getVertex(1) == that.getVertex(2) && getVertex(5) == that.getVertex(4)) {
            setVertex(0, that.getVertex(0));
            setVertex(1, that.getVertex(1));
            //setVertex(2, this.getVertex(2)); // no change
            //setVertex(3, this.getVertex(3)); // no change
            //setVertex(4, this.getVertex(4)); // no change
            setVertex(5, that.getVertex(5));
            return; // done
        }
    //   if this.([1],[3]) == that.([0],[4]) then create polygon: this.[0], that.[1], that.[2], that.[3], this.[4], this.[5]
        if (getVertex(1) == that.getVertex(0) && getVertex(3) == that.getVertex(4)) {
            //setVertex(0, this.getVertex(0)); // no change
            setVertex(1, that.getVertex(1));
            setVertex(2, that.getVertex(2));
            setVertex(3, that.getVertex(3));
            //setVertex(4, this.getVertex(4)); // no change
            //setVertex(5, this.getVertex(5)); // no change
            return; // done
        }
    //   if this.([0],[4]) == that.([1],[3]) then create polygon: that.[0], this.[1], this.[2], this.[3], that.[4], that.[5]
        if (getVertex(0) == that.getVertex(1) && getVertex(4) == that.getVertex(3)) {
            setVertex(0, that.getVertex(0));
            //setVertex(1, this.getVertex(1)); // no change
            //setVertex(2, this.getVertex(2)); // no change
            //setVertex(3, this.getVertex(3)); // no change
            setVertex(4, that.getVertex(4));
            setVertex(5, that.getVertex(5));
            return; // done
        }
    }

}
void FlipX3D::update(float time)
{
    float angle = (float)M_PI * time; // 180 degrees
    float mz = sinf(angle);
    angle = angle / 2.0f; // x calculates degrees from 0 to 90
    float mx = cosf(angle);

    Vec3 v0, v1, v, diff;

    v0 = getOriginalVertex(Vec2(1.0f, 1.0f));
    v1 = getOriginalVertex(Vec2());

    float    x0 = v0.x;
    float    x1 = v1.x;
    float    x;
    Vec2    a, b, c, d;

    if ( x0 > x1 )
    {
        // Normal Grid
        a.setZero();
        b.set(0.0f, 1.0f);
        c.set(1.0f, 0.0f);
        d.set(1.0f, 1.0f);
        x = x0;
    }
    else
    {
        // Reversed Grid
        c.setZero();
        d.set(0.0f, 1.0f);
        a.set(1.0f, 0.0f);
        b.set(1.0f, 1.0f);
        x = x1;
    }

    diff.x = ( x - x * mx );
    diff.z = fabsf( floorf( (x * mz) / 4.0f ) );

    // bottom-left
    v = getOriginalVertex(a);
    v.x = diff.x;
    v.z += diff.z;
    setVertex(a, v);

    // upper-left
    v = getOriginalVertex(b);
    v.x = diff.x;
    v.z += diff.z;
    setVertex(b, v);

    // bottom-right
    v = getOriginalVertex(c);
    v.x -= diff.x;
    v.z -= diff.z;
    setVertex(c, v);

    // upper-right
    v = getOriginalVertex(d);
    v.x -= diff.x;
    v.z -= diff.z;
    setVertex(d, v);
}
void LinePrimitives::setEndPosition(float x, float y, float z)
{
	_endPosition = { x, y, z };
	setVertex();
}
示例#9
0
// Overrides
void CFlip3DYEx::update(float time)
{
//    float angle = (float)M_PI * time; // 180 degrees
    float angle = m_from + (m_from - m_to) * time;
    float mz = sinf( angle );
    angle = angle / 2.0f;     // x calculates degrees from 0 to 90
    float my = cosf(angle);
    
    Vertex3F    v0, v1, v, diff;
    
    v0 = getOriginalVertex(Point(1, 1));
    v1 = getOriginalVertex(Point(0, 0));
    
    float    y0 = v0.y;
    float    y1 = v1.y;
    float y;
    Point    a, b, c, d;
    
    if (y0 > y1)
    {
        // Normal Grid
        a = Point(0,0);
        b = Point(0,1);
        c = Point(1,0);
        d = Point(1,1);
        y = y0;
    }
    else
    {
        // Reversed Grid
        b = Point(0,0);
        a = Point(0,1);
        d = Point(1,0);
        c = Point(1,1);
        y = y1;
    }
    
    diff.y = y - y * my;
    diff.z = fabsf(floorf((y * mz) / 4.0f));
    
    // bottom-left
    v = getOriginalVertex(a);
//    v.y = diff.y;
    v.z += 0;//diff.z;
    setVertex(a, v);
    
    // upper-left
    v = getOriginalVertex(b);
    v.y -= 2 * diff.y;
    v.z -= 2* diff.z;
    setVertex(b, v);
    
    // bottom-right
    v = getOriginalVertex(c);
//    v.y = diff.y;
    v.z += 0;//diff.z;
    setVertex(c, v);
    
    // upper-right
    v = getOriginalVertex(d);
    v.y -= 2 * diff.y;
    v.z -= 2 * diff.z;
    setVertex(d, v);

}
示例#10
0
/*
 * Update each tick
 * Time is the percentage of the way through the duration
 */
void PageTurn3D::update(float time)
{
    float tt = MAX(0, time - 0.25f);
    float deltaAy = (tt * tt * 500);
    float ay = -100 - deltaAy;
    
    float deltaTheta = sqrtf(time);
    float theta = deltaTheta>0.5?(float)M_PI_2*deltaTheta:(float)M_PI_2*(1-deltaTheta);
    
    float rotateByYAxis = (2-time)* M_PI;
    
    float sinTheta = sinf(theta);
    float cosTheta = cosf(theta);
    
    for (int i = 0; i <= _gridSize.width; ++i)
    {
        for (int j = 0; j <= _gridSize.height; ++j)
        {
            // Get original vertex
            Vec3 p = getOriginalVertex(Vec2(i ,j));
            
            p.x -= getGridRect().origin.x;
            float R = sqrtf((p.x * p.x) + ((p.y - ay) * (p.y - ay)));
            float r = R * sinTheta;
            float alpha = asinf( p.x / R );
            float beta = alpha / sinTheta;
            float cosBeta = cosf( beta );
            
            // If beta > PI then we've wrapped around the cone
            // Reduce the radius to stop these points interfering with others
            if (beta <= M_PI)
            {
                p.x = ( r * sinf(beta));
            }
            else
            {
                // Force X = 0 to stop wrapped
                // points
                p.x = 0;
            }

            p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta));

            // We scale z here to avoid the animation being
            // too much bigger than the screen due to perspective transform

            p.z = (r * ( 1 - cosBeta ) * cosTheta);// "100" didn't work for
            p.x = p.z * sinf(rotateByYAxis) + p.x * cosf(rotateByYAxis);
            p.z = p.z * cosf(rotateByYAxis) - p.x * sinf(rotateByYAxis);
            p.z/=7;
            //    Stop z coord from dropping beneath underlying page in a transition
            // issue #751
            if( p.z < 0.5f )
            {
                p.z = 0.5f;
            }
            
            // Set new coords
            p.x += getGridRect().origin.x;
            setVertex(Vec2(i, j), p);
            
        }
    }
}
示例#11
0
void Quadrilateral::create(Vector3 origin, float length, float width,Vector3 orientation)
{
	Vector3 V0, V1, V2, V3;
	if(orientation.x() == -1 || orientation.x() == 1){
       		 V0 = Vector3(origin.x(),origin.y()-(length/2),origin.z()-(width/2));
		 V1 = Vector3(origin.x(),origin.y()+(length/2),origin.z()-(width/2));
		 V2 = Vector3(origin.x(),origin.y()+(length/2),origin.z()+(width/2));
		 V3 = Vector3(origin.x(),origin.y()-(length/2),origin.z()+(width/2));
		 setVertex(V0);
		 setVertex(V1);
		 setVertex(V2);
		 setVertex(V3);
		 setNormale(Vector3(orientation.x(),0,0));
	}
        else {
		if(orientation.y() == -1 || orientation.y() == 1){
	       		 V0 = Vector3(origin.x()-(length/2),origin.y(),origin.z()-(width/2));
			 V1 = Vector3(origin.x()+(length/2),origin.y(),origin.z()-(width/2));
			 V2 = Vector3(origin.x()+(length/2),origin.y(),origin.z()+(width/2));
			 V3 = Vector3(origin.x()-(length/2),origin.y(),origin.z()+(width/2));
			 setVertex(V0);
		 	 setVertex(V1);
		  	 setVertex(V2);
		 	 setVertex(V3);
			 setNormale(Vector3(0,orientation.y(),0));
		}
		else {
			if(orientation.z() == -1 || orientation.z() == 1){
       		 		V0 = Vector3(origin.x()-(length/2),origin.y()-(width/2),origin.z());
		 		V1 = Vector3(origin.x()+(length/2),origin.y()-(width/2),origin.z());
		 		V2 = Vector3(origin.x()+(length/2),origin.y()+(width/2),origin.z());
		 		V3 = Vector3(origin.x()-(length/2),origin.y()+(width/2),origin.z());
		 		setVertex(V0);
		 		setVertex(V1);
		  		setVertex(V2);
		 		setVertex(V3);
		 		setNormale(Vector3(0,0,orientation.z()));
			}
		}
	}
}
示例#12
0
Quadrilateral::Quadrilateral(Vector3 V0, Vector3 V1, Vector3 V2, Vector3 V3):Face()
{
	setVertex(V0); setVertex(V1); setVertex(V2); setVertex(V3);
	calculateNormale();
}