我想创建一个与此类似的游戏http://www.sciencekids.co.nz/gamesactivities/movinggrowth.html
1-如何根据鼠标坐标移动图像?我知道如何翻译一个像多边形但不是图像的对象?
2-如何检查它是否在正确的地方并让它卡在那里我使用了gltranslate但图像没有移动,并尝试了copypixl但它不断复制鼠标点击的每个地方的图像。
#include <windows.h>
#include <GL/glut.h>
#include <gl/glaux.h>
#pragma comment(lib,"glaux.lib")
AUX_RGBImageRec *image ;
GLsizei wh = 600, ww = 800;
//-----------------------------------------------------------------------------------------------
void display(void){
image = new AUX_RGBImageRec();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
image = auxDIBImageLoad(L"boy.bmp");
glDrawPixels(image->sizeX, image->sizeY, GL_RGB,
GL_UNSIGNED_BYTE,image->data);
glFlush();
}
//-----------------------------------------------------------------------------------------------
void mouse (int btn , int state , int x , int y){
int h = wh-y ;
if(btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
/*glPushMatrix();*/
/*glTranslatef(x , h , 0);*/
glRasterPos2i(x,h);
glCopyPixels(0,0,image->sizeX, image->sizeY,GL_COLOR);
//glPopMatrix();}
if(btn == GLUT_LEFT_BUTTON && state == GLUT_UP) {
// check if it is in right place to stuck it else will retuen to original place
}
}glFlush();
}
//-----------------------------------------------------------------------------------------------
void intiate(){
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D(0,ww,0,wh);
}
//-----------------------------------------------------------------------------------------------
void main()
{
glutInitDisplayMode (GLUT_RGB);
glutInitWindowSize (ww, wh);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Inside my Body");
intiate();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}