I’ve done this and as far as i know this should work i, it should print out the initials X & G , and then depending on key pressed should do its transformations.
Problem is it keeps saying the the x and y variables should be in class,identifier etc…
ne one please…
#include "stdafx.h"
#include "glut.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
class wcPt2D{
public:
GLfloat x,y;
};
wcPt2D X_lettter[4]={{50,150},{150,50},{50,50},{150,150},};
wcPt2D G_letter[10]={{300,150},{200,150},{200,150},{200,50},{200,50},{300,50},{275,75},{325,75},{300,75},{300,25},};
wcPt2D centre;
void translate( double tx, double ty)
{
int i;
for(i=0;i<4;i++)
{
X_letter[i].x+=tx;
X_letter[i].y+=ty;
}
for(i=0;i<10;i++)
{
G_letter[i].x+=tx;
G_letter[i].y+=ty;
}
}
void scale(double sx, double sy)
{
int i;
for(i=0;i<4;i++)
{
X_letter[i].x = centre.x *(1-sx) + X_letter[i].x*sx;
X_letter[i].y = centre.y *(1-sy) + X_letter[i].y*sy;
}
for(i=0;i<4;i++)
{
G_letter[i].x = centre.x *(1-sx) + X_letter[i].x*sx;
G_letter[i].y = centre.y *(1-sy) + X_letter[i].y*sy;
}
}
void rotate0(double a)
{
double aRad = ((double)(a))*(3.142/180.0);
int i;
for (i=0;i<4;i++)
{
X_letter[i].x = cos(aRad) * X_letter[i].x - sin(aRad) * X_letter[i].y;
X_letter[i].y = sin(aRad) * X_letter[i].x + cos(aRad) * X_letter[i].y;
}
for (i=0;i<4;i++)
{
G_letter[i].x = cos(aRad) * X_letter[i].x - sin(aRad) * G_letter[i].y;
G_letter[i].y = sin(aRad) * X_letter[i].x + cos(aRad) * G_letter[i].y;
}
}
void rotate (double a)
{
translate( -1.0 * centre.x, -1.0 * centre.y);
rotate0(a );
translate( centre.x, centre.y);
}
void myKeyboardFunc (unsigned char key, int x, int y)
{
switch (key) {
case 't':
translate(10,10);
glutPostRedisplay();
break;
case 's':
scale(0.9,0.9);
glutPostRedisplay();
break;
case 'r':
rotate0(10);
glutPostRedisplay();
break;
case 'R':
rotate(10);
glutPostRedisplay();
break;
case 27: //escapre key
exit(0);
break;
}
}
void draw_XG(void)
{
int i;
/*clear all pixels*/
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
glLineWidth(5.0);
glBegin(GL_LINES);
for(i=0;i<4;i++)
{
glVertex2d (X_letter[i].x, X_letter[i].y);
}
glEnd();
glColor3f (0.0, 0.0, 1.0);
glBegin(GL_LINES);
for(i=0;i<10;i++)
{
glVertex2d (G_letter[i].x, G_letter[i].y);
}
glEnd();
glFlush ();
}
void init (void)
{
/*select clearing color*/
glClearColor (0.0, 0.0, 0.0, 0.0);
/*initialise viewing values*/
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 400.0, 0.0, 400.0);
centre.x=0.0;
centre.y=0.0;
int i;
for(i=0;i<4;i++)
{
centre.x += X_letter[i].x;
centre.y += X_letter[i].y;
}
for(i=0;i<10;i++)
{
centre.x += G_letter[i].x;
centre.y += G_letter[i].y;
}
centre.x = centre.x/14;
centre.y = centre.y/14;
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(500,500);
glutCreateWindow("My Initials N.M.");
init();
glutDisplayFunc(draw_XG);
glutKeyboardFunc(myKeyboardFunc);
glutMainLoop();
return 0;
}