a) Translate (move) the whole object ( the star, the circle and the point that m
ID: 3742223 • Letter: A
Question
a) Translate (move) the whole object ( the star, the circle and the point that moves around) along the x axis using the -> and <- keys on the keyboard
b) Rotate the whole object around the z axis using the shift -> and shift <- keys on the keyboard.
c) Move the Camera by keeping the object still ( using glLookaAt and pointing the camera to the center of the object all the time) around the x axis of the object ( the star, the circle and the point that moves around) using the up and down keys on the keyboard.
d) Zoom in and Zoom out the object by decreasing the distance between the object and the camera using the computer mouse scroll wheel. (Needs to be in perspective projection)
Explanation / Answer
Program for a) =>
void DrawArc(float cx, float cy, float r, float start_angle, float arc_angle, int num_segments)
{
float theta = arc_angle / float(num_segments - 1);//theta is now calculated from the arc angle instead, the - 1 bit comes from the fact that the arc is open
float tangetial_factor = tanf(theta);
float radial_factor = cosf(theta);
float x = r * cosf(start_angle);//we now start at the start angle
float y = r * sinf(start_angle);
glBegin(GL_LINE_STRIP);//since the arc is not a closed curve, this is a strip now
for(int ii = 0; ii < num_segments; ii++)
{
glVertex2f(x + cx, y + cy);
float tx = -y;
float ty = x;
x += tx * tangetial_factor;
y += ty * tangetial_factor;
x *= radial_factor;
y *= radial_factor;
}
glEnd();
}
b) 2D star
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/freeglut.h>
void init (void)
{
glClearColor(0.0,0.0,0.0,00);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,200.0,0.0,200.0);
}
void LineSegment(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2i(20,120);
glVertex2i(180,120);
glVertex2i(45,20);
glVertex2i(100,190);
glVertex2i(155,20);
glEnd();
glFlush();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(50,100);
glutCreateWindow("STAR");
init();
glutDisplayFunc(LineSegment);
glutMainLoop();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.