コード例 #1
0
ファイル: SWRenderContext.java プロジェクト: panmari/cgUnibe
 /**
  * Draws only the vertices of the given shape in white. Normals and indices are ignored. TODO:
  * negative W are possible, fix plx?
  *
  * @param shape
  * @param t
  */
 private void drawDotty(Shape shape, Matrix4f t) {
   float[] points = null, colors = null;
   for (VertexElement ve : shape.getVertexData().getElements()) {
     switch (ve.getSemantic()) {
       case POSITION:
         points = ve.getData();
         break;
       case COLOR:
         colors = ve.getData();
         break;
       case NORMAL:
         // DO NOT WANT
         break;
       case TEXCOORD:
         // DO NOT WANT
         break;
     }
   }
   for (int i = 0; i < points.length; i += 3) {
     Point4f v = new Point4f(points[i], points[i + 1], points[i + 2], 1);
     Color3f c = new Color3f(colors[i], colors[i + 1], colors[i + 2]);
     t.transform(v);
     int x = Math.round(v.x / v.w);
     int y = Math.round(v.y / v.w);
     if (x >= 0 && y >= 0 && y < colorBuffer.getHeight() && x < colorBuffer.getWidth())
       drawPointAt(x, y, c.get().getRGB());
   }
 }
コード例 #2
0
ファイル: SWRenderContext.java プロジェクト: panmari/cgUnibe
 /**
  * Draws all triangles given in <code>indices</code> of the given shape. Ignores normals.
  *
  * @param shape that is about to be drawn
  * @param t accumulated transformation matrix for this shape
  */
 private void drawTrianglesSeparately(Shape shape, Matrix4f t) {
   VertexData vertexData = shape.getVertexData();
   Point4f[] positions = new Point4f[3];
   Color3f[] colors = new Color3f[3];
   Point2f[] texCoords = new Point2f[3];
   int k = 0; // keeps track of triangle
   int[] indices = vertexData.getIndices();
   for (int i = 0; i < indices.length; i++) {
     for (VertexElement ve : vertexData.getElements()) {
       Point4f p;
       switch (ve.getSemantic()) {
         case POSITION:
           p = getPointAt(ve.getData(), indices[i]);
           t.transform(p);
           positions[k] = p;
           k++; // increment k here, bc color and normal might be missing
           break;
         case COLOR:
           colors[k] = getColorAt(ve.getData(), indices[i]);
           ;
           break;
         case NORMAL:
           // dont care
           // normals[k] = getPointAt(ve, indices[i]);;
           break;
         case TEXCOORD:
           texCoords[k] = getTexCoordAt(ve.getData(), indices[i]);
           break;
       }
     }
     if (k == 3) {
       rasterizeTriangle(positions, colors, texCoords, shape.getMaterial());
       k = 0;
     }
   }
 }