package Bib3D;
/*
* Autor: Artjom Zabelin
* Facharbeit Informatik LK 12.2 T. Selms
*
* Der ModelLayer ist eine Commponent und zeichnet das Model.
*/
import java.awt.*;
import java.awt.font.*;
import java.io.*;
public class ModelLayer extends GraphicSurface
{
public Model3D Model;
public Matrix3D Matrix1, Matrix2;
public ModelLayer(File file) throws FileNotFoundException, IOException
{
this.Model = new Model3D(file);
this.Matrix1 = new Matrix3D();
this.Matrix2 = new Matrix3D();
this.Model.reduce();
}
public void renderInf(int w, int h, Graphics2D g2)
{
FontRenderContext FRC = g2.getFontRenderContext();
Font font1 = new Font("Verdana", Font.PLAIN, w/40);
Font font2 = new Font("Verdana", Font.PLAIN, w/45);
TextLayout tl = new TextLayout("Model-Information", font1, FRC);
TextLayout tl2 = new TextLayout("Name: " + this.Model.Name, font2, FRC);
TextLayout tl3 = new TextLayout("Vertices: " + this.Model.ModelHandler.Buffer.nVertices, font2, FRC);
TextLayout tl4 = new TextLayout("Lines: " + this.Model.ModelHandler.Buffer.nLines, font2, FRC);
tl.draw(g2, (float)(w/30), (float)(h/ (float)1.2));
tl2.draw(g2, (float)(w/30), (float)(h/ (float)1.14));
tl3.draw(g2, (float)(w/30), (float)(h/ (float)1.08));
tl4.draw(g2, (float)(w/30), (float)(h/ (float)1.03));
}
public void renderModel(int w, int h, Graphics2D g2)
{
if (this.Model.ModelHandler.Buffer.VBuffer == null ||
this.Model.ModelHandler.Buffer.VBuffer.length <= 0)
{
return;
}
this.Model.transform();
int bo = this.Model.ModelHandler.Buffer.nLines;
int lb[] = this.Model.ModelHandler.Buffer.LBuffer;
int vb[] = this.Model.ModelHandler.Buffer.TBuffer;
if (bo <= 0 || this.Model.ModelHandler.Buffer.VBuffer.length <= 0)
{
return;
}
for (int i = 0; i < bo; i++)
{
int T = lb[i];
int v1 = ((T >> 16) & 0xFFFF) * 3;
int v2 = (T & 0xFFFF) * 3;
g2.setColor(new Color(0,0,0));
g2.drawLine(vb[v1], vb[v1 + 1],
vb[v2], vb[v2 + 1]);
}
}
@Override
public void render(int w, int h, Graphics2D g2)
{
this.renderInf(w, h, g2);
g2.translate(w/2, h/2);
this.renderModel(w, h, g2);
}
}