3D CAD Graphics Project - PDF
-
Upload
sasi-beera -
Category
Technology
-
view
1.101 -
download
3
Transcript of 3D CAD Graphics Project - PDF
GRAPHICS IN CAD
PROJECT – 2 11/23/09
SASI BEERA (#3576-3829)
ANIRUDH PASUPULETI (#3678-2070)
Introduction
In this project, the “Basic3DTools” and “HiddenLineRemoval” concepts are used as a
basis. To define and manipulate 3D objects, a series of classes are used in the code.
Careful studying and reviewing the class C3DShapes and also the C3DShapes functions
by the classes CCylShapes and CExtrudeShapes approaches the project solution. The
original code from Basic3DTools and HiddenLineRemoval is modified at will to achieve
the desired outcome.
Description and Features
The game plan of this project is to build a farm scene and eventually fill colors and
remove hidden lines when viewed from a vantage point. The trees are „chopped down‟
from the example problem and a conical structure is added to the silo. A car is present in
front of the barn, which can be moved, linearly in the forward and backward directions.
At any moment the user can get back to the initial image by simply selecting the New
button, which is provided. All the polygons are filled later, that is, appear to be solid
structures and are filled with the given colors. The hidden features of the polygons are
removed and thus show a much-improved ability to render the farm scene as the car
moves in and out of the barn and as the mouse is used to manipulate the view.
Adding the ability to change the viewing distance while viewing the scene further
develops the project. The „I‟ and „O‟ keys are used to move „in‟ or „out‟ of the scene and
also mouse control is provided to perform this operation.
Additionally, an animation is provided in the farm scene by considering the silo (with its
top) to be a rocket.
A launch button „L‟ is provided to lift off and fly the silo rocket through a simple
parabolic trajectory ending by entering and stopping in the barn. A default view position
is provided. By pressing „S‟ the silo stops traversing. Finally, „R‟ resets the position of
the silo by bringing it back to its home position.
This animation can also done by using the Drop-down menu provided on the top. Three
different buttons are provided – Launch, Stop, Reset to perform the same operations as
above.
A dialog box is provided which allows the viewer to input a specific viewing location in
terms of x, y, and z coordinate values.
This box can be found by clicking the View button provided on the top. After entering
the desired values, the user will then be placed at the specified position and will be
looking directly at the origin.
Strategy behind CConeShapes class
A similar logic used in CCylinderShapes is incorporated here in CConeShapes class. The
variables, which govern the generation of cylinders, as well as cones, are nsegs, radius
and length. These are used to sequentially define nlines, npoints, ncurves and npolygons.
A cylinder, for example, has 8 segments and a certain radius and length.
This results in 8 lines, 16 points (8 each on top and bottom curves), 2 curves (top and
bottom) and 10 polygons (8 plus 2 curves). Similarly, a cone having 8 segments and a
certain radius and length, results in 8 lines, 9 points (8 on the bottom and the apex point
on top), 1 curve (bottom) and 9 polygons (8 plus 1 curve). Hence the strategy of
CConeShapes class is so characterized.
The code for CConeShapes class is as follows:
void CConeShapes::AdjustConeShape (int nseg, double Radius, double Length)
{
m_BasePoint.Adjust3DPoint(0, 0, 0);
double Phi=0;
double fnseg = nseg;
double DPhi=(2.*3.14158)/fnseg;
int i;
for (i = 0; i<nseg; i++)
{
double xp = Radius * cos(Phi);
double yp = Radius * sin(Phi);
double zp = 0;
m_ShapePoints[i].Adjust3DPoint(xp,yp,zp);
Phi+=DPhi;
}
double xp = 0;
double yp = 0;
double zp = -Length;
m_ShapePoints[nseg].Adjust3DPoint(xp,yp,zp);
m_NumPoints = nseg+1;
m_NumPolygons = nseg+1;
m_NumPointsPerPolygon[0] = nseg;
for (i=0; i<nseg; i++){m_PolygonPointMatrix[0][i] = i;}
for (i=0; i<nseg-1; i++){
m_NumPointsPerPolygon[i+1]=3;
m_PolygonPointMatrix[i+1][2]=i;
m_PolygonPointMatrix[i+1][1]=i+1;
m_PolygonPointMatrix[i+1][0]=nseg;
}
m_NumPointsPerPolygon[nseg]=3;
m_PolygonPointMatrix[nseg][0]=nseg;
m_PolygonPointMatrix[nseg][1]=0;
m_PolygonPointMatrix[nseg][2]=nseg-1;
}
void CConeShapes::Move (double Mvx, double Mvy, double Mvz)
{C3DShapes::Move(Mvx, Mvy, Mvz);}
void CConeShapes::Dmove (double DMvx, double DMvy, double DMvz)
{C3DShapes::Dmove(DMvx, DMvy, DMvz);}
void CConeShapes::ShowConeShape(CDC* pDC,double m_zvp)
{
C3DShapes::Show3DShape (pDC,m_zvp);
}
void CConeShapes::GRotateX(double Theta, C3DPoints RPoint)
{
C3DShapes::GRotateX(Theta, RPoint);
}
void CConeShapes::GRotateY(double Theta, C3DPoints RPoint)
{
C3DShapes::GRotateY(Theta, RPoint);
}
void CConeShapes::GRotateZ(double Theta, C3DPoints RPoint)
{
C3DShapes::GRotateZ(Theta, RPoint);
}
void CConeShapes::RotateX(double Theta)
{
C3DShapes::RotateX(Theta);
}
void CConeShapes::RotateY(double Theta)
{
C3DShapes::RotateY(Theta);
}
void CConeShapes::RotateZ(double Theta)
{
C3DShapes::RotateZ(Theta);
}
};
Approach to Polygon fill routine for 3D shapes:
Here, the polygons are filled using the following code along with this additional
command:
pDC->Polygon(PolyPts,m_NumPnts);
For showing the polygons, the Show3DPolygons is defined. Initially, the structure of
each polygon is characterized by the governing variables. The NumPnts define the
number of points to be considered for constructing the polygon. Then the base point is
delineated for each polygon and also the polygons are thus created.
Listing of Show3DPolygons code:
void C3DPolygons::Show3DPolygon(CDC* pDC, C3DPoints BasePoint, double zvp)
{
double PolyVisible;
CPoint PolyPts[25];
m_PointArray[m_NumPnts] = m_PointArray[0];
for (int i = 0; i < m_NumPnts; i++)
{
double x = BasePoint.m_x + m_PointArray[i].m_x;
double y = BasePoint.m_y + m_PointArray[i].m_y;
double z = BasePoint.m_z + m_PointArray[i].m_z;
double xp1 = BasePoint.m_x + m_PointArray[i+1].m_x;
double yp1 = BasePoint.m_y + m_PointArray[i+1].m_y;
double zp1 = BasePoint.m_z + m_PointArray[i+1].m_z;
double xds = x/(1.-z/zvp);
double yds = y/(1.-z/zvp);
double xdf = xp1/(1.-zp1/zvp);
double ydf = yp1/(1.-zp1/zvp);
if (i==0)
{
double xp2 = BasePoint.m_x + m_PointArray[i+2].m_x;
double yp2 = BasePoint.m_y + m_PointArray[i+2].m_y;
double zp2 = BasePoint.m_z + m_PointArray[i+2].m_z;
double xdf2 = xp2/(1.-zp2/zvp);
double ydf2 = yp2/(1.-zp2/zvp);
double a = xdf-xds;
double b = ydf-yds;
double c = xdf2-xds;
double d = ydf2-yds;
PolyVisible = (a*d-b*c)/abs(a*d-b*c);
}
xds = xds + 320;
yds = -yds +240;
xdf = xdf + 320;
ydf = -ydf + 240;
if(PolyVisible > 0)
{
pDC->MoveTo(int(xds),int(yds));
pDC->LineTo(int(xdf),int(ydf));
PolyPts[i].x = xds;
PolyPts[i].y = yds;
}
//pDC->Polygon(PolyPts,m_NumPnts);
}
pDC->Polygon(PolyPts,m_NumPnts);
}
};
Miscellaneous discussion:
The development of Version 2 of this program is continued to better remove
hidden features. Then the objects are „shown‟ in the order of their base point z
distances.
The generated image thus shows much improved (but probably not perfect) ability
to render the farm scene as the car moves in and out of the barn and as the mouse
is used to manipulate the view.
Additionally, an animation is provided in the farm scene by considering the silo
(with its top) to be a rocket.
A launch button „L‟ is provided to lift off and fly the silo rocket through a simple
parabolic trajectory ending by entering and stopping in the barn. A default view
position is provided. By pressing „S‟ the silo stops traversing. Finally, „R‟ resets
the position of the silo by bringing it back to its home position.
A dialog box is provided which allows the viewer to input a specific viewing
location in terms of x, y, and z coordinate values.
This box can be found by clicking the View button provided on the top. After
entering the desired values, the user will then be placed at the specified position
and will be looking directly at the origin.
“Print Screens” for each item:
Figure 1: Wireframe model- Item 1
Figure 2: Item 2 of the farm-scene
Figure 3: Item 3 of the farm-scene (vantage point)
Figure 4: Item 3 (developed)
Figure 5: Item 3 (hidden features removed)
Figure 6: Item 6 (cone of the silo launched)
Figure 7: Item 6 (cone of the silo traversing the trajectory)
Figure 8: Item 6 (cone changing its angle gradually)
Figure 9: Item 6 (cone of the silo targeting the barn)
Figure 10: Item 6 (the barn is „bombed‟)
X = 1000,y= 0, z= 0;
X= 1000, y = 1000, z= 0;
X= 1000, y = -1000, z= 0;
Description of approach to displaying most distant objects last to
enhance hidden part removal:
Initially, the distances of base-points of each shape- barn, cylinder, cone, and vehicle are
stored using the variables- ZExtrudeShape1, ZCylShape, ZConeShape1, ZSimpleVehicle.
Then by applying the following logic, the process of displaying most distant objects last
to enhance hidden part removal is carried out:
if (ZExtrudeShape1>ZCylShape>ZSimpleVehicle)
{
pDC->SelectObject(&m_YellowBrush);
ViewConeShape1.ShowConeShape(pDC,zvp);
ViewSimpleVehicle.ShowExtrudeShape(pDC,zvp);
pDC->SelectObject(&m_RedBrush);
for(int icnt=0; icnt<1; icnt++){
ViewCylShapeArray[icnt].ShowCylShape(pDC,zvp);
}
In this loop, the logical idea is that the z-distances that are stored are compared so as to
eventually operate the process of displaying the barn, cylinder, cone and vehicle in
decreasing order.
The listing of OnDraw code:
void CViewFarmSceneHView::OnDraw(CDC* pDC)
{
CViewFarmSceneHDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
ViewSimpleVehicle = pDoc->SimpleVehicle;
ViewExtrudeShape1 = pDoc->ExtrudeShape1;
ViewSimpleVehicle = pDoc->SimpleVehicle;
ViewConeShape1 = pDoc->ConeShape1[0];
for(int icnt=0; icnt<13; icnt++){
ViewCylShapeArray[icnt] = pDoc->CylShapeArray[icnt];
}
C3DPoints Origin;
Origin.Adjust3DPoint(0,0,0);
ViewExtrudeShape1.GRotateY(HorizAngle, Origin);
ViewExtrudeShape1.GRotateX(VertAngle, Origin);
ViewSimpleVehicle.GRotateY(HorizAngle, Origin);
ViewSimpleVehicle.GRotateX(VertAngle, Origin);
ViewConeShape1.GRotateY(HorizAngle, Origin);
ViewConeShape1.GRotateX(VertAngle, Origin);
for(int icnt=0; icnt<1; icnt++){
ViewCylShapeArray[icnt].GRotateY(HorizAngle, Origin);
ViewCylShapeArray[icnt].GRotateX(VertAngle, Origin);
}
double ZExtrudeShape1 = ViewExtrudeShape1.m_BasePoint.m_z;
double ZCylShape = ViewCylShapeArray[0].m_BasePoint.m_z;
double ZConeShape1 = ViewConeShape1.m_BasePoint.m_z;
double ZSimpleVehicle = ViewSimpleVehicle.m_BasePoint.m_z;
if (ZExtrudeShape1<ZCylShape<ZSimpleVehicle)
{
pDC->SelectObject(&m_RedBrush);
ViewExtrudeShape1.ShowExtrudeShape(pDC,zvp);
for(int icnt=0; icnt<1; icnt++){
ViewCylShapeArray[icnt].ShowCylShape(pDC,zvp);
}
pDC->SelectObject(&m_YellowBrush);
ViewSimpleVehicle.ShowExtrudeShape(pDC,zvp);
ViewConeShape1.ShowConeShape(pDC,zvp);
}
if (ZExtrudeShape1>ZCylShape>ZSimpleVehicle)
{
pDC->SelectObject(&m_YellowBrush);
ViewConeShape1.ShowConeShape(pDC,zvp);
ViewSimpleVehicle.ShowExtrudeShape(pDC,zvp);
pDC->SelectObject(&m_RedBrush);
for(int icnt=0; icnt<1; icnt++){
ViewCylShapeArray[icnt].ShowCylShape(pDC,zvp);
}
ViewExtrudeShape1.ShowExtrudeShape(pDC,zvp);
}
}
User’s instructions:
By clicking the executable program (version 1) that will open the 3-D farm scene.
By clicking and holding the left mouse button and eventually moving it, the user
can view the scene from desired direction.
Next by hitting the Up and Down keys the car in the farm scene can be moved
away and towards the barn respectively. Clicking the New button and hitting the
„N‟ key will return to the initial image.
For the Version 2, the polygon projections are „filled‟ than drawn. It opens with
the same scene but now with the filled polygons of the barn and silo colored red
and the car and the top of the silo colored yellow.
Again clicking the New button and hitting the „N‟ key will return to the initial
image.
The development of Version 2 of this program is continued to better remove
hidden features. Then the objects are „shown‟ in the order of their base point z
distances.
The generated image thus shows much improved (but probably not perfect) ability
to render the farm scene as the car moves in and out of the barn and as the mouse
is used to manipulate the view.
Adding the ability to change the viewing distance while viewing the scene further
develops the Version 2. Using „I‟ and „O‟ keys to move „in‟ or „out‟ can do this.
A mouse control is provided as well to perform this operation. Hitting the „N‟ key
and selecting the New button will bring it back to the initial image.
Additionally, an animation is provided in the farm scene by considering the silo
(with its top) to be a rocket.
A launch button „L‟ is provided to lift off and fly the silo rocket through a simple
parabolic trajectory ending by entering and stopping in the barn. A default view
position is provided. By pressing „S‟ the silo stops traversing. Finally, „R‟ resets
the position of the silo by bringing it back to its home position.
This animation can also done by using the Drop-down menu provided on the top.
Three different buttons are provided – Launch, Stop, Reset to perform the same
operations as above.
A dialog box is provided which allows the viewer to input a specific viewing
location in terms of x, y, and z coordinate values.
This box can be found by clicking the View button provided on the top. After
entering the desired values, the user will then be placed at the specified position
and will be looking directly at the origin.