|
using System;
using System.Collections;
using Engine3DVP;
namespace Engine3D
{
/// <summary>
/// Summary description for Object3D.
/// </summary>
//3D objects.
internal class Object3D: IObject3D
{
private static int PNR; //Everyone
private int mNr; //Me and my numner.
private ArrayList mMesh; //Storing every polygon.
private ArrayList mMeshN; //Storing new polygon positions after rotations.
private Poinx3D mPlace; //Where the object is in screen space.
private double mPaseX; //The strenght for the movements.
private double mPaseY; //..
private double mRotX; //Rotation counter.
private double mRotXVal; //Value of rotation.
private double mRotY; //Rotation counter round the Y axis.
private double mRotYVal; //Rotation value.
private int mEnergy;
public Object3D()
{
this.mNr = PNR; //Give it a number.
PNR++; //New numer for the next one.
}
//Creating and placing, giving a rotation value.
public Object3D(Poinx3D place, double rotX, double rotY, int energy)
{
this.mEnergy = energy;
this.mNr = PNR; //Give it a number.
PNR++; //New numer for the next one.
this.mRotXVal = rotX;
this.mRotYVal = rotY;
this.mPlace = place;
}
//Get and set the new strength
public double PaseX
{
set
{
this.mPaseX = value;
}
get
{
return this.mPaseX;
}
}
public double PaseY
{
set
{
this.mPaseY = value;
}
get
{
return this.mPaseY;
}
}
//Obj energy level.
public int Energy
{
set
{
this.mEnergy = value;
}
get
{
if(this.mEnergy<0)
this.mEnergy=0;
return this.mEnergy;
}
}
public int Nr
{
get
{
return this.mNr;
}
}
//Will give the Engine3D access the degree value to the polygon nr i.
public double GetDegree(int i)
{
return ((Poly3D)this.mMeshN[i]).degree;
}
//Through this function the Engine3D can set the value.
public void SetDegree(int i, double degree)
{
Poly3D temp = (Poly3D)this.mMeshN[i];
temp.degree = degree;
this.mMeshN[i] = temp;
}
//Will rotate this object by the rotation value.
public void RotateIt()
{
this.mRotX += this.mRotXVal;
this.mRotY += this.mRotYVal;
}
//Engine3D will get the rotation counters value.
public double GetRotX()
{
return this.mRotX;
}
//..
public double GetRotY()
{
return this.mRotY;
}
//Set or get rotation value.
public void SetRotX(double val)
{
this.mRotXVal = val;
}
//Set or get rotation value.
public void SetRotY(double val)
{
this.mRotYVal = val;
}
//Return i positions polygon in the mesh
//from the original mesh.
public Poly3D GetMeshPoly(int i)
{
return (Poly3D)this.mMesh[i];
}
//And same here, but for the polygon from the new rotated mesh points.
public Poly3D GetMeshPolyN(int i)
{
return (Poly3D)this.mMeshN[i];
}
//Creating the mesh from scratch.
//And a copy for rotation values.
public void SetMeshPoints(ref ArrayList mesh)
{
this.mMesh = (ArrayList)mesh.Clone();
this.mMeshN = (ArrayList)mesh.Clone();
}
//Gives us the length of the polygon mesh
public int Len
{
get
{
return this.mMesh.Count;
}
}
//
public void SetPos(int mesh, Poly3D newp)
{
//Temporary.
Poly3D pp = (Poly3D)this.mMeshN[mesh];
//Place the polygons points in screen space.
pp.p1.X = newp.p1.X + this.mPlace.X;
pp.p1.Y = newp.p1.Y + this.mPlace.Y;
pp.p1.Z = newp.p1.Z + this.mPlace.Z;
pp.p2.X = newp.p2.X + this.mPlace.X;
pp.p2.Y = newp.p2.Y + this.mPlace.Y;
pp.p2.Z = newp.p2.Z + this.mPlace.Z;
pp.p3.X = newp.p3.X + this.mPlace.X;
pp.p3.Y = newp.p3.Y + this.mPlace.Y;
pp.p3.Z = newp.p3.Z + this.mPlace.Z;
//Give the temp to the ordinary
//It's a always do on this one!
this.mMeshN[mesh] = pp;
}
//Will retrieve the i nr polygon from the rotated point mesh.
public Poly3D GetPoly(int mesh)
{
return (Poly3D)this.mMeshN[mesh];
}
//Set or get the objects screen position.
public Poinx3D ObjPos
{
set
{
this.mPlace = value;
}
get
{
return this.mPlace;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Professional programmer, degree in Informatics and Applied Systems Science.