Exemplo n.º 1
0
void R3Rectangle::
Draw(const R3DrawFlags draw_flags) const
{
    // Check if box is empty
    if (IsEmpty()) return;

    /* Get texture coordinates */
    static R2Point texcoords[4] = {
	R2Point(0.0, 0.0),
	R2Point(1.0, 0.0),
	R2Point(1.0, 1.0),
	R2Point(0.0, 1.0)
    };

    /* Get box corner points */
    R3Point corners[4];
    corners[0] = Corner(RN_NN_QUADRANT);
    corners[1] = Corner(RN_PN_QUADRANT);
    corners[2] = Corner(RN_PP_QUADRANT);
    corners[3] = Corner(RN_NP_QUADRANT);

    // Draw surface
    if (draw_flags[R3_SURFACES_DRAW_FLAG]) {
        if (draw_flags[R3_SURFACE_NORMALS_DRAW_FLAG]) 
            R3LoadNormal(Normal());

        R3BeginPolygon();
        for (int j = 0; j < 4; j++) {
            if (draw_flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG])
                R3LoadTextureCoords(texcoords[j]);
	    R3LoadPoint(corners[j]);
        }
        R3EndPolygon();
    }

    // Draw edges
    if (draw_flags[R3_EDGES_DRAW_FLAG]) {
	R3BeginLoop();
	for (int i = 0; i < 4; i++)
	    R3LoadPoint(corners[i]);
	R3EndLoop();
    }    
}
Exemplo n.º 2
0
void R3Circle::
Draw(const R3DrawFlags draw_flags) const
{
    // Push matrix (Zaxis -> ScaledNormal + OffsetToCenter)
    R4Matrix matrix = R4identity_matrix;
    matrix.Translate(center.Vector());
    matrix.Rotate(R3posz_vector, Normal());
    matrix.Push();

    // Draw surface
    if (draw_flags[R3_SURFACES_DRAW_FLAG]) {
	// Load normal
	if (draw_flags[R3_SURFACE_NORMALS_DRAW_FLAG]) 
	    R3LoadNormal(R3posz_vector);

	// Draw circle in XY plane
	R3BeginPolygon();
	for (int i = 0; i < R3circle_npoints; i++) {
	    if (draw_flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG]) 
		R3LoadTextureCoords(R3circle_texcoords[i]);
	    R3LoadPoint(R3circle_points[i] * radius);
	}
	R3EndPolygon();
    }

    // Draw edges
    if (draw_flags[R3_EDGES_DRAW_FLAG]) {
	R3BeginLoop();
	for (int i = 0; i < R3circle_npoints; i++) 
	    R3LoadPoint(R3circle_points[i] * radius);
	R3EndLoop();
    }

    // Pop matrix
    matrix.Pop();
}
Exemplo n.º 3
0
void R3OrientedBox::
Draw(const R3DrawFlags draw_flags) const
{
    // Check if box is empty
    if (IsEmpty()) return;

    static R2Point texcoords[4] = {
	R2Point(0.0, 0.0),
	R2Point(1.0, 0.0),
	R2Point(1.0, 1.0),
	R2Point(0.0, 1.0)
    };
    static int surface_paths[6][4] = {
	{ 3, 0, 1, 2 },
	{ 4, 7, 6, 5 },
	{ 0, 4, 5, 1 },
	{ 7, 3, 2, 6 },
	{ 3, 7, 4, 0 },
        { 1, 5, 6, 2 }
    };
    static int outline_path[16] = {
	0, 1, 2, 3,
	0, 4, 5, 6,
	7, 4, 5, 1,
	2, 6, 7, 3
    };

    /* Get box corner points */
    R3Point corners[8];
    corners[0] = Corner(RN_NNN_OCTANT);
    corners[1] = Corner(RN_NNP_OCTANT);
    corners[2] = Corner(RN_NPP_OCTANT);
    corners[3] = Corner(RN_NPN_OCTANT);
    corners[4] = Corner(RN_PNN_OCTANT);
    corners[5] = Corner(RN_PNP_OCTANT);
    corners[6] = Corner(RN_PPP_OCTANT);
    corners[7] = Corner(RN_PPN_OCTANT);

    // Draw surface
    if (draw_flags[R3_SURFACES_DRAW_FLAG]) {
	for (int i = 0; i < 6; i++) {
	    R3BeginPolygon();
	    if (draw_flags[R3_SURFACE_NORMALS_DRAW_FLAG]) {
                RNScalar sign = (i < 3) ? 1.0 : -1.0;
                R3LoadNormal(sign * Axis(i%3));
            }
	    for (int j = 0; j < 4; j++) {
		if (draw_flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG]) 
		    R3LoadTextureCoords(texcoords[j]);
		R3LoadPoint(corners[surface_paths[i][j]]);
	    }
	    R3EndPolygon();
	}
    }

    // Draw edges
    if (draw_flags[R3_EDGES_DRAW_FLAG]) {
	R3BeginLine();
	for (int i = 0; i < 16; i++)
	    R3LoadPoint(corners[outline_path[i]]);
	R3EndLine();
    }    
}
Exemplo n.º 4
0
void R3Triangle::
Draw(const R3DrawFlags draw_flags) const
{
    // Ammend draw flags
    R3DrawFlags flags(Flags() & draw_flags);
    RNDimension dim = 0, dim1 = 0, dim2 = 0;

    // Unroll flags/loops for efficiency 
    switch (flags) {
    case R3_SURFACES_DRAW_FLAG | R3_SURFACE_NORMALS_DRAW_FLAG:
      // Flat shading
      R3BeginPolygon();
      R3LoadNormal(Normal());
      R3LoadPoint(v[0]->Position());
      R3LoadPoint(v[1]->Position());
      R3LoadPoint(v[2]->Position());
      R3EndPolygon();
      break;

    case R3_SURFACES_DRAW_FLAG | R3_SURFACE_NORMALS_DRAW_FLAG | R3_VERTEX_NORMALS_DRAW_FLAG:
      // Gouraud shading
      R3BeginPolygon();
      R3LoadNormal(v[0]->Normal());
      R3LoadPoint(v[0]->Position());
      R3LoadNormal(v[1]->Normal());
      R3LoadPoint(v[1]->Position());
      R3LoadNormal(v[2]->Normal());
      R3LoadPoint(v[2]->Position());
      R3EndPolygon();
      break;

    case R3_SURFACES_DRAW_FLAG | R3_SURFACE_NORMALS_DRAW_FLAG | 
         R3_SURFACE_TEXTURE_DRAW_FLAG | R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG: 
      // Flat shading with texture coordinates
      R3BeginPolygon();
      R3LoadNormal(Normal());
      R3LoadTextureCoords(v[0]->TextureCoords());
      R3LoadPoint(v[0]->Position());
      R3LoadTextureCoords(v[1]->TextureCoords());
      R3LoadPoint(v[1]->Position());
      R3LoadTextureCoords(v[2]->TextureCoords());
      R3LoadPoint(v[2]->Position());
      R3EndPolygon();
      break;

    case R3_SURFACES_DRAW_FLAG | R3_SURFACE_NORMALS_DRAW_FLAG | 
         R3_SURFACE_TEXTURE_DRAW_FLAG: 
      // Flat shading with texture coordinate generation
      dim = Normal().MaxDimension();
      dim1 = (dim + 1) % 3;
      dim2 = (dim + 2) % 3;
      R3BeginPolygon();
      R3LoadNormal(Normal());
      R3LoadTextureCoords(v[0]->Position()[dim1], v[0]->Position()[dim2]);
      R3LoadPoint(v[0]->Position());
      R3LoadTextureCoords(v[1]->Position()[dim1], v[1]->Position()[dim2]);
      R3LoadPoint(v[1]->Position());
      R3LoadTextureCoords(v[2]->Position()[dim1], v[2]->Position()[dim2]);
      R3LoadPoint(v[2]->Position());
      R3EndPolygon();
      break;

    case R3_SURFACES_DRAW_FLAG | R3_SURFACE_NORMALS_DRAW_FLAG | R3_VERTEX_NORMALS_DRAW_FLAG | 
         R3_SURFACE_TEXTURE_DRAW_FLAG | R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG: 
      // Gouraud shading with texture coordinates
      R3BeginPolygon();
      R3LoadTextureCoords(v[0]->TextureCoords());
      R3LoadNormal(v[0]->Normal());
      R3LoadPoint(v[0]->Position());
      R3LoadTextureCoords(v[1]->TextureCoords());
      R3LoadNormal(v[1]->Normal());
      R3LoadPoint(v[1]->Position());
      R3LoadTextureCoords(v[2]->TextureCoords());
      R3LoadNormal(v[2]->Normal());
      R3LoadPoint(v[2]->Position());
      R3EndPolygon();
      break;

    case R3_SURFACES_DRAW_FLAG | R3_SURFACE_NORMALS_DRAW_FLAG | R3_VERTEX_NORMALS_DRAW_FLAG | 
         R3_SURFACE_TEXTURE_DRAW_FLAG: 
      // Gouraud shading with texture coordinate generation
      dim = Normal().MaxDimension();
      dim1 = (dim + 1) % 3;
      dim2 = (dim + 2) % 3;
      R3BeginPolygon();
      R3LoadTextureCoords(v[0]->Position()[dim1], v[0]->Position()[dim2]);
      R3LoadNormal(v[0]->Normal());
      R3LoadPoint(v[0]->Position());
      R3LoadTextureCoords(v[1]->Position()[dim1], v[1]->Position()[dim2]);
      R3LoadNormal(v[1]->Normal());
      R3LoadPoint(v[1]->Position());
      R3LoadTextureCoords(v[2]->Position()[dim1], v[2]->Position()[dim2]);
      R3LoadNormal(v[2]->Normal());
      R3LoadPoint(v[2]->Position());
      R3EndPolygon();
      break;

    default:
        // Draw surface
        if (flags[R3_SURFACES_DRAW_FLAG]) {
	    // Begin polygon
	    R3BeginPolygon();

	    // Load polygon normal
	    if ((flags[R3_SURFACE_NORMALS_DRAW_FLAG]) &&
		(!flags[R3_VERTEX_NORMALS_DRAW_FLAG]))
	        R3LoadNormal(Normal());

	    // Compute stuff for texture coordinates
	    if ((draw_flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG]) &&
		(!flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG])) {
	        dim = Normal().MaxDimension();
		dim1 = (dim + 1) % 3;
		dim2 = (dim + 2) % 3;
	    }

	    // Load triangle vertices
	    for (int i = 0; i < 3; i++) {
		// Load vertex normal
		if (flags[R3_VERTEX_NORMALS_DRAW_FLAG])
		    R3LoadNormal(v[i]->normal);

		// Load vertex texture coordinates 
		if (draw_flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG]) {
		    if (flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG]) R3LoadTextureCoords(v[i]->TextureCoords());
		    else R3LoadTextureCoords(v[i]->Position()[dim1], v[i]->Position()[dim2]);
		}

		// Load vertex
		R3LoadPoint(v[i]->Position());
	    }

	    // End polygon 
	    R3EndPolygon();
	}
	
	// Draw edges
	if (flags[R3_EDGES_DRAW_FLAG]) {
	    R3BeginLoop();
            R3LoadPoint(v[0]->Position());
            R3LoadPoint(v[1]->Position());
            R3LoadPoint(v[2]->Position());
	    R3EndLoop();
	}
	break;
    }
}