package jhpro.engine3d;
import java.awt.Color;
import java.io.Serializable;
/**
* A drawing object
* @author sergei
*
*/
public class FacetedObject implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
private boolean wantSolidRendering=true;
private Color fillColor=Color.blue;
private boolean wantShading=true;
private Color penColor=Color.black;
private int transperancy=200;
public FacetedObject()
{
verticies = null;
vindex = null;
v = f = e = n = 0;
currentPoint = 0;
currentEntry = 0;
penColor=Color.black;
wantShading=true;
fillColor=Color.blue;
wantSolidRendering=true;
}
FacetedObject(int v_p)
{
this(v_p, 0, 0);
}
public FacetedObject(int verts[][], int vi[][])
{
verticies = null;
vindex = null;
v = verts.length;
f = vi.length;
e = vi[0].length;
n = vi[0].length;
verticies = new double[verts.length][3];
for(int i = 0; i < verts.length; i++)
{
for(int j = 0; j < 3; j++)
verticies[i][j] = verts[i][j];
}
vindex = new int[vi.length][vi[0].length];
for(int i = 0; i < vi.length; i++)
{
for(int j = 0; j < 4; j++)
vindex[i][j] = vi[i][j];
}
}
public FacetedObject(int v_p, int f_p, int n_p)
{
this();
v = v_p;
verticies = new double[v][3];
vSamplesModal = Math.max(1, v / 5);
if(f_p > 0)
createVectorIndex(f_p, n_p);
// System.out.println("\nVerticies : " + v + " Faces : " + f + " \n");
// System.out.println("Verticies ( data sampled & rounded ) : ");
}
public void createVectorIndex(int f_p, int n_p)
{
f = f_p;
n = n_p;
vindex = new int[f][n];
fSamplesModal = Math.max(1, f / 5);
}
public void setPointData(double p[])
{
// if(currentPoint % vSamplesModal == 0)
// System.out.println(" " + (100 * currentPoint) / v + " %\t" + currentPoint + "\t( " + (int)p[0] + ", " + (int)p[1] + ", " + (int)p[2] + " )");
verticies[currentPoint][0] = p[0];
verticies[currentPoint][1] = p[1];
verticies[currentPoint++][2] = p[2];
}
public void setPointData(double x, double y, double z)
{
double v[] = {
x, y, z
};
setPointData(v);
}
public void setVectorIndex(int val)
{
int row = currentEntry / n;
int col = currentEntry++ % n;
vindex[row][col] = val;
if(row % fSamplesModal == 0 && col == 3)
{
// if(row == 0)
// System.out.println("Vertex index : " + f + " faces," + " n = " + n + "( edges per face )");
// System.out.println(" " + (100 * row) / f + " %\t" + row + "\t[ " + vindex[row][0] + ", " + vindex[row][1] + ", " + vindex[row][2] + ", " + vindex[row][3] + " ]");
}
}
/**
* Fill or not fill the object
* @param solid
*/
public void setSolidRendering(boolean solid)
{
wantSolidRendering=solid;
}
/**
* Set alpha value between 0- and 255
* @param transperancy
*/
public void setTransperancy(int transperancy) {
if (transperancy>255) transperancy=255;
this.transperancy = transperancy;
}
/**
* Get alpha value between 0 and 255
* @return
*/
public int getTransperancy() {
return transperancy;
}
/**
* Shad or not the object
* @param solid
*/
public void setShading(boolean shading)
{
wantShading=shading;
}
public boolean getShading() {
return wantShading;
}
/**
* Color of fill (when no shading)
* @param fillC
*/
public void setFillColor(Color fillC){
fillColor=fillC;
}
/**
* Pen color to draw the object
* @param solid
*/
public void setPenColor(Color fillC)
{
penColor=fillC;
}
/**
* Want solid rendering?
* @return
*/
public boolean getSolidRendering(){
return wantSolidRendering;
}
/**
* Get pen color
* @return
*/
public Color getPenColor() {
return penColor;
}
/**
* Get fill color
* @return
*/
public Color getFillColor() {
return fillColor;
}
/**
* Describe the object
*/
public void describe()
{
// System.out.println("Verticies : " + v + " Faces : " + f);
}
final int SamplesDesired = 5;
int vSamplesModal;
int fSamplesModal;
int v;
int f;
int e;
int n;
private int currentPoint;
private int currentEntry;
public double verticies[][];
public int vindex[][];
}
Ads help maintain this website.