CFanatic

Go Back   CFanatic > Advance Programming > OpenGL Programming

problem with glutKeyboardFunc(keyboard); topic posted under OpenGL Programming which is a part of Advance Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 04-17-2008, 03:25 AM
Junior Member
 
Join Date: Apr 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
dathatreya is on a distinguished road
| More
problem with glutKeyboardFunc(keyboard);

I'm using opengl with MFC for developing the 3d application.Here the problem is if I use glutKeyboardFunc(keyboard) both the objects(room and cube)are moving but I want to make move for onlly cube.Here I'm giving the code can anyone suggest how to make movement for only cube.

Code:
void MFCOpenGL:isplay(void)
{

glDrawBuffer(GL_FRONT_LEFT);
//glColor3f(1, 1, 1);
glClearColor(1,1,1,1);//set the background color to black
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);

glBegin(GL_QUADS);
glColor3d(1.0, 0.0, 0.0);
glVertex2d(0.0, 0.0);
glVertex2d(2.4, -0.35);
glVertex2d(2.45, 2.5);
glVertex2d(0.0, 2.7);
glEnd();


glBegin(GL_QUADS);
glColor3d(0.0, 0.0, 1.0);
glVertex2d(-2.5, -0.;
glVertex2d(0.0, 0.0);
glVertex2d(0.0, 2.7);
glVertex2d(-2.5, 2.0);
glEnd();


glBegin(GL_QUADS);
glColor3d(0.0, 0.0, 0.0);
glVertex2d(-2.5, -0.;
glVertex2d(-0.3, -2.0);
glVertex2d(2.4, -0.35);
glVertex2d(0.0,0.0);
glEnd();

glColor3f(0.0, 1.0, 1.0);
glutSolidCube(0.5);
glutSwapBuffers();
glutPostRedisplay();//end of insertion
}

void MFCOpenGL::Resize(int width,int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (float)width / (float)height, 0.1, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Set the viewing position and orientation
gluLookAt(
0.0, 0.0,10.0, // eye location
0.0, 0.0, 1.0, // center location
0.0, 1.0, 0.0); // up vector
}

void MFCOpenGL::keyboard(int key, int x, int y)
{
switch (key)
{
case 'a':
case 'A':
glTranslatef(-1.0, 0.0, 0.0);

break;

case 'd':
case 'D':
glTranslatef(1.0, 0.0, 0.0);
break;

case 'w':
case 'W':
glTranslatef(0.0, 0.0, 1.0);
break;

case 's':
case 'S':
glTranslatef(0.0, 0.0, -1.0);
break;
}
}

Last edited by shabbir; 04-17-2008 at 08:00 AM. Reason: Code block
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
A Microsoft keyboard for the upper crust NewsBot News 0 09-16-2006 09:38 AM



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.