Question
Technical Overview & Specifications The goal of this project is to enable you to understand principle of Cohen-Sutherland clipping algorithm under OpenGL in interaction way.
- Technical Overview & Specifications
The goal of this project is to enable you to understand principle of Cohen-Sutherland clipping algorithm under OpenGL in interaction way. The requirement for this design is as following:
Assignment:
1. Under the following piece of code, please create your project to perform a cuboid rotation about arbitrary axis, translation, scaling respect to a selected point (x0, y0, z0), reflection relative to x axis and shear transformation about z axis.
class wcPt3D {
public:
GLfloat x, y, z;
};
typedef GLfloat Matrix4x4[4][4];
Matrix4x4 matComposition;
const GLdouble pi = 3.14159;
void Matrix4x4SetIndentity(Matrix4x4 matIndent3x3)
{
GLint row, col;
for (row = 0; row < 4; row++)
for (col = 0; col < 4; col++)
matIndent3x3[row][col] = (row == col);
}
void Matrix4x4PreMultiply(Matrix4x4 m1, Matrix4x4 m2)
{
GLint row, col;
Matrix4x4 matTemp;
for (row = 0; row < 4; row++)
for (col = 0; col < 4; col++)
matTemp[row][col] = m1[row][0] * m2[0][col] + m1[row][1] * m2[1][col] + m1[row][2] * m2[2][col] + m1[row][3] * m2[3][col];
for (row = 0; row < 4; row++)
for (col = 0; col < 4; col++)
m2[row][col] = matTemp[row][col];
}
void translate3D(GLfloat tx, GLfloat ty, GLfloat tz)
{
Matrix4x4 matTrans3D;
Matrix4x4SetIndentity(matTrans3D);
matTrans3D[0][2] = tx;
matTrans3D[1][2] = ty;
matTrans3D[2][3] = tz;
Matrix4x4PreMultiply(matTrans3D, matComposition);
}
void rotate3D(wcPt3D p1, wcPt3D p2, GLfloat radianAngle)
{
Matrix4x4 matQuatRot;
GLfloat axisVectLength = sqrt((p2.x - p1.x)*(p2.x - p1.x) + (p2.y - p1.y)*(p2.y - p1.y) + (p2.z - p1.z)*(p2.z - p1.z));
GLfloat cosA = cosf(radianAngle);
GLfloat oneC = 1 - cosA;
GLfloat sinA = sinf(radianAngle);
GLfloat ux = (p2.x - p1.x) / axisVectLength;
GLfloat uy = (p2.y - p1.y) / axisVectLength;
GLfloat uz = (p2.z - p1.z) / axisVectLength;
translate3D(-p1.x, -p1.y, -p1.z);
Matrix4x4SetIndentity(matQuatRot);
matQuatRot[0][0] = ux * ux*oneC + cosA;
matQuatRot[0][1] = ux * uy*oneC - uz * sinA;
matQuatRot[0][2] = ux * uz*oneC + uy * sinA;
matQuatRot[1][0] = uy * ux*oneC + uz * sinA;
matQuatRot[1][1] = uy * uy*oneC + cosA;
matQuatRot[1][2] = uy * uz*oneC - ux * sinA;
matQuatRot[2][0] = uz * ux*oneC - uy * sinA;
matQuatRot[2][1] = uz * uy*oneC + ux * sinA;
matQuatRot[2][2] = uz * uz*oneC + cosA;
Matrix4x4PreMultiply(matQuatRot, matComposition);
translate3D(p1.x, p1.y, p1.z);
}
void scale3D(GLfloat sx, GLfloat sy, GLfloat sz, wcPt3D fixedPt)
{
Matrix4x4 matScale3D;
Matrix4x4SetIndentity(matScale3D);
matScale3D[0][0] = sx;
matScale3D[0][3] = (1 - sx)*fixedPt.x;
matScale3D[1][1] = sy;
matScale3D[1][3] = (1 - sy)*fixedPt.y;
matScale3D[2][2] = sz;
matScale3D[2][3] = (1 - sz)*fixedPt.z;
Matrix4x4PreMultiply(matScale3D, matComposition);
}
void transformVerts3D(GLint nVerts, wcPt3D *verts)
{
GLint k;
GLfloat temp;
for (k = 0; k < nVerts; k++)
{
temp = matComposition[0][0] * verts[k].x + matComposition[0][1] * verts[k].y + matComposition[0][2] * verts[k].z + matComposition[0][3];
verts[k].x = temp;
verts[k].y = matComposition[1][0] * verts[k].x + matComposition[1][1] * verts[k].y + matComposition[1][2] * verts[k].z + matComposition[1][3];
verts[k].z = matComposition[2][0] * verts[k].x + matComposition[2][1] * verts[k].y + matComposition[2][2] * verts[k].z + matComposition[2][3];
}
}
- Uniform requirement of experimental report formats
Strongly suggest your report include at least the following three parts:
- Project description
Illustrate the basic method, main idea of your project, or something about it.
- Implementation code details
Please give introduction of your major functions, and the implementation code
- Experimental results
Please show your experimental results, analysis your results and share your experience learned after finishing this experiment or your suggestion about this course.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started