Rotating House -- Namdev

#include "stdafx.h"
#include "stdafx.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "glut.h"
using namespace std;
GLfloat OldHme[3][9]={{100,100,300,300,150,150,250,250,200},{100,300,300,100,100,200,200,100,400},{1,1,1,1,1,1,1,1,1}},
NewHme[3][9],RotParam[3][3],m,n;
int theta=15;
int h=100,k=100;

void DrawHome(GLfloat home[3][9])
{
glBegin(GL_LINE_LOOP);
glVertex2f(home[0][0],home[1][0]);
glVertex2f(home[0][1],home[1][1]);
glVertex2f(home[0][2],home[1][2]);
glVertex2f(home[0][3],home[1][3]);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2f(home[0][4],home[1][4]);
glVertex2f(home[0][5],home[1][5]);
glVertex2f(home[0][6],home[1][6]);
glVertex2f(home[0][7],home[1][7]);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2f(home[0][1],home[1][1]);
glVertex2f(home[0][8],home[1][8]);
glVertex2f(home[0][2],home[1][2]);
glEnd();
}

void Multiply()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<9;j++)
{
NewHme[i][j]=0.0;
for(int k=0;k<3;k++)
{
NewHme[i][j]=NewHme[i][j]+RotParam[i][k]*OldHme[k][j];
}
}
}
}

void  rotate()
{
m=-h*(cos(theta)-1)+k*(sin(theta));
n=-k*(cos(theta)-1)-h*(sin(theta));
RotParam[0][0]=cos(theta);
RotParam[0][1]=-sin(theta);
RotParam[0][2]=m;
RotParam[1][0]=sin(theta);
RotParam[1][1]=cos(theta);
RotParam[1][2]=n;
RotParam[2][0]=0;
RotParam[2][1]=0;
RotParam[2][2]=1;
Multiply();
}

 void Display()
 {
glClear(GL_COLOR_BUFFER_BIT );
DrawHome(OldHme);
rotate();
DrawHome(NewHme);
glFlush();
 }
 void Myinit()
 {
glClearColor(0,0,0,0.2);
glLineWidth(1.5);
gluOrtho2D(-500,1000,-500,1000);

 }
int main(int argc, char* argv[])
{

    printf("Enter the rotation angle");
scanf("%f", &theta);
theta=theta*(3.14/180);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize(1000,1000);
glutCreateWindow("Roatating House");
//glEnable(GL_DEPTH_TEST);
glutDisplayFunc(Display);
Myinit();
glutMainLoop();
return 0;
}




Previous
Next Post »

Please Leave ur Valuable comments Here ConversionConversion EmoticonEmoticon

Facebook

HTML Comment Box is loading comments...

Our Partners

Our Partners