Question

In: Computer Science

Using OpenGL develop a C code that a) draws a point that moves clockwise slowly along...

Using OpenGL develop a C code that a) draws a point that moves clockwise slowly along a circle with a center at (0,0). You may want to draw a circle first, and a point that moves on the circle with a different color. b) draws a 2D star inside the circle.

Solutions

Expert Solution

PROGRAM:

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)

#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 Solutions

An object moves along a straight track from the point (4,−4,1) to the point (6,6,−7). The...
An object moves along a straight track from the point (4,−4,1) to the point (6,6,−7). The only force acting on it is a constant F=−5i−5j+4k newtons. Find the work done in joules if the distance is measured in meters.
A point charge with a mass of 1.81 ng and a charge of +1.22 ?C moves...
A point charge with a mass of 1.81 ng and a charge of +1.22 ?C moves in the x-y plane with a velocity of 3.00 x 104 m/s in a direction 15° above the +x-axis. At time t=0, the point charge enters a uniform magnetic field of strength 1.25 T that points in the +x-direction.Assume that the point charge remains immersed in the uniform magnetic field after time t=0. a) What is the magnitude and direction of the magnetic force...
Develop a C-code to calculate average, median and standard deviation, using 5 numbers as data you...
Develop a C-code to calculate average, median and standard deviation, using 5 numbers as data you input from the keyboard from calculations and compare program output with the hand calculations shown with formula for average, median & standard deviation.. Use suggested approach below for developing the code (other approaches are also possible): In main     define an array of size = 5, Read in 5 decimal numbers and print the chosen numbers for input; Store input as a array and work...
Develop a program using Threads in C/C++ to estimate the value of PI using the Monte...
Develop a program using Threads in C/C++ to estimate the value of PI using the Monte Carlo method use: C/C++ #include srand((unsigned)(myid)); x = ((double)rand()) / ((double)RAND_MAX); y = ((double)rand()) / ((double)RAND_MAX); Your program will allow the user to specify the number of threads (range 1 to 10) and the total number of data points (range 10 to 1,000,000) used for the Monte Carlo simulation on the command line. Note, DO NOT assume the number of data points is always...
Develop a program using Threads in C/C++ to estimate the value of PI using the Monte...
Develop a program using Threads in C/C++ to estimate the value of PI using the Monte Carlo method use: C/C++ #include srand((unsigned)(myid)); x = ((double)rand()) / ((double)RAND_MAX); y = ((double)rand()) / ((double)RAND_MAX); Your program will allow the user to specify the number of threads (range 1 to 10) and the total number of data points (range 10 to 1,000,000) used for the Monte Carlo simulation on the command line. Note, DO NOT assume the number of data points is always...
DEVELOP A C++ PROGRAM IN PROCEDURAL CODE that will recursively alphabetize a set of strings in...
DEVELOP A C++ PROGRAM IN PROCEDURAL CODE that will recursively alphabetize a set of strings in a user-specified file using the tree sort algorithm explained in the lectures while maintaining a balanced binary tree at all times. The following will test your program with an input file containing: Max Hank Jet Frisky Chata Richard Nan Sam Thomas Karen Gerri Ingrid Alan Dana When done print out the contents of the tree with inorder traversal in a tabular format similar to...
Using java, commenting should be proper, along with testing for valid and invalid inputs: Develop a...
Using java, commenting should be proper, along with testing for valid and invalid inputs: Develop a simple tool for analyzing a segment of text that determines the number of words in that segment and the average word length. The application should have a single window with a scrolling text box (JTextArea) and an area to display the statistics. The statistics area should be a panel with a titled border, containing labelled fields that display the number of words in the...
write code to manage a linked list using recursive approach. (Using this code) C++ IN Unix....
write code to manage a linked list using recursive approach. (Using this code) C++ IN Unix. // app.cpp #include <iostream> #include "linkedlist.h" using namespace std; void find(LinkedList& list, char ch) {    if (list.find(ch))        cout << "found ";    else        cout << "did not find ";    cout << ch << endl; } int main() {    LinkedList   list;    list.add('x');    list.add('y');    list.add('z');    cout << list;    find(list, 'y');    list.del('y');    cout...
Constant Current Code for Arduino Develop a Constant Current Program in C and upload it into...
Constant Current Code for Arduino Develop a Constant Current Program in C and upload it into your Arduino #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
A particle (mass = 6.7 x 10-27 kg, charge = 3.2 x 10-19 C) moves along...
A particle (mass = 6.7 x 10-27 kg, charge = 3.2 x 10-19 C) moves along the positive x axis with a speed of 4.1 x 105 m/s. It enters a region of uniform electric field parallel to its motion and comes to rest after moving 5.0 m into the field. What is the magnitude of the electric field (in N/C) ?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT