BilliardsPlayView.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:63k
- // BilliardsPlayView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Billiards.h"
- #include <math.h>
- #include <gl/gl.h>
- #include <gl/glu.h>
- #include <gl/glaux.h>
- #include <gl/glut.h>
- #include "BilliardsPlayView.h"
- #include "InitOpenGL.h"
- #include "BilliardsDoc.h"
- #include "MainFrm.h"
- #include "BilliardsFormView.h"
- #include <Mmsystem.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- AUX_RGBImageRec *image1,*image2,*image3;
- unsigned char *pdata1,*pdata2,*pdata3;
- #define ImageWidth 256
- #define ImageHeight 256
- static GLuint texName[3];
- /////////////////////////////////////////////////////////////////////////////
- // CBilliardsPlayView
- IMPLEMENT_DYNCREATE(CBilliardsPlayView, CView)
- void CBilliardsPlayView::texinit(void)
- {
- // glClearColor(0.8,0.8,0.8,1.0);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_AUTO_NORMAL);
- glDepthFunc(GL_LESS);
- // glFrontFace(GL_CW);
- glShadeModel(GL_FLAT);
- image1=auxDIBImageLoadA("MOHOGANY.bmp");
- pdata1=(BYTE *)malloc(256*256*3*sizeof(BYTE));
- if (!pdata1)
- exit(0);
- glPixelStorei(GL_UNPACK_ALIGNMENT,1);
- gluScaleImage(GL_RGB,image1->sizeX,image1->sizeY,GL_UNSIGNED_BYTE,image1->data,
- ImageWidth,ImageHeight,GL_UNSIGNED_BYTE,pdata1);
-
- image2=auxDIBImageLoadA("BILLIARDSTABLE.bmp");
- pdata2=(BYTE *)malloc(256*256*3*sizeof(BYTE));
- if (!pdata2)
- exit(0);
- glPixelStorei(GL_UNPACK_ALIGNMENT,1);
- gluScaleImage(GL_RGB,image2->sizeX,image2->sizeY,GL_UNSIGNED_BYTE,image2->data,
- ImageWidth,ImageHeight,GL_UNSIGNED_BYTE,pdata2);
- image3=auxDIBImageLoadA("tableface.bmp");
- pdata3=(BYTE *)malloc(256*256*3*sizeof(BYTE));
- if (!pdata3)
- exit(0);
- glPixelStorei(GL_UNPACK_ALIGNMENT,1);
- gluScaleImage(GL_RGB,image3->sizeX,image3->sizeY,GL_UNSIGNED_BYTE,image3->data,
- ImageWidth,ImageHeight,GL_UNSIGNED_BYTE,pdata3);
-
-
- glGenTextures(3,texName);
-
- glBindTexture(GL_TEXTURE_2D,texName[0]);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,ImageWidth,ImageHeight,0,GL_RGB,GL_UNSIGNED_BYTE,pdata1);
- glBindTexture(GL_TEXTURE_2D,texName[1]);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,ImageWidth,ImageHeight,0,GL_RGB,GL_UNSIGNED_BYTE,pdata2);
- glBindTexture(GL_TEXTURE_2D,texName[2]);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,ImageWidth,ImageHeight,0,GL_RGB,GL_UNSIGNED_BYTE,pdata3);
- glEnable(GL_TEXTURE_2D);
- }
- CBilliardsPlayView::CBilliardsPlayView()
- {
- m_fViewHeight = 60.0;
- m_fViewNear = 200.0;
- m_fViewFar = 400.0;
- m_nMouseAct = MOUSE_SELECT;
- m_spinAngle = 0.0;
- m_spinAxes[0] = m_spinAxes[2] = 0.0; m_spinAxes[1] = 1.0;
- m_sEye.origin.x = m_sEye.origin.y = 0; m_sEye.origin.z = 300.0;
- m_sEye.center.x = m_sEye.center.y = 0.0; m_sEye.center.z = 0.0;
- m_sEye.up.x = m_sEye.up.z = 0.0; m_sEye.up.y = 1.0;
- m_sEye.axisX.y = m_sEye.axisX.z = 0.0; m_sEye.axisX.x = 1.0;
- m_sEye.axisY.x = m_sEye.axisY.z = 0.0; m_sEye.axisY.y = 1.0;
- m_sEye.axisZ.x = m_sEye.axisZ.y = 0.0; m_sEye.axisZ.z = -1.0;
- m_vProjectCenter[0] = 0.0f;
- m_vProjectCenter[1] = 0.0f;
- m_vProjectCenter[2] = (m_fViewNear+m_fViewFar)/2;
- int i;
- float tmpf;
- for (i=0;i<NUM_BALL;i++)
- m_bVisible[i]=TRUE;
- for (i=0;i<NUM_BALL;i++)
- m_fVelocity[i][0]=m_fVelocity[i][1]=m_fVelocity[i][2]=0.0f;
- for (i=0;i<NUM_BALL;i++)
- m_fPosition[i][1]=0.0f;
- m_fPosition[0][0] = - 2.0*TABLE_LENGTH/3.0;
- m_fPosition[0][2] = 0.0f;
- m_fPosition[1][0] = TABLE_LENGTH/2.5;
- m_fPosition[1][2] = 0.0f;
- tmpf = 2.0*BALL_RADIUS*0.8661;
- m_fPosition[2][0] = m_fPosition[1][0]+tmpf;
- m_fPosition[2][2] = BALL_RADIUS;
- m_fPosition[3][0] = m_fPosition[2][0]+tmpf;
- m_fPosition[3][2] = 2.0*BALL_RADIUS;
- m_fPosition[4][0] = m_fPosition[3][0]+tmpf;
- m_fPosition[4][2] = 3.0*BALL_RADIUS;
- m_fPosition[5][0] = m_fPosition[4][0]+tmpf;
- m_fPosition[5][2] = 4.0*BALL_RADIUS;
- m_fPosition[6][0] = m_fPosition[4][0];
- m_fPosition[6][2] = BALL_RADIUS;
- m_fPosition[7][0] = m_fPosition[5][0];
- m_fPosition[7][2] = 2.0*BALL_RADIUS;
- m_fPosition[8][0] = m_fPosition[3][0];
- m_fPosition[8][2] = 0.0f;
- m_fPosition[15][0]= m_fPosition[5][0];
- m_fPosition[15][2]= 0.0f;
- m_fPosition[9][0] = m_fPosition[2][0];
- m_fPosition[9][2] = -m_fPosition[2][2];
- m_fPosition[10][0]= m_fPosition[3][0];
- m_fPosition[10][2]= -m_fPosition[3][2];
- m_fPosition[11][0]= m_fPosition[4][0];
- m_fPosition[11][2]= -m_fPosition[4][2];
- m_fPosition[12][0]= m_fPosition[5][0];
- m_fPosition[12][2]= -m_fPosition[5][2];
- m_fPosition[13][0]= m_fPosition[6][0];
- m_fPosition[13][2]= -m_fPosition[6][2];
- m_fPosition[14][0]= m_fPosition[7][0];
- m_fPosition[14][2]= -m_fPosition[7][2];
- m_fStrength=22.5f;
- m_fDirection[0]=1.0f;
- m_fDirection[1]=0.0f;
- m_fDirection[2]=0.0f;
- m_fVelocity[0][0]=5.0f;
- m_nSelectObject = -1;
- m_bAnimate = FALSE;
- m_bCanHit = TRUE;
- }
- CBilliardsPlayView::~CBilliardsPlayView()
- {
- }
- BEGIN_MESSAGE_MAP(CBilliardsPlayView, CView)
- //{{AFX_MSG_MAP(CBilliardsPlayView)
- ON_WM_SIZE()
- ON_WM_ERASEBKGND()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_CREATE()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CBilliardsPlayView drawing
- void CBilliardsPlayView::OnDraw(CDC* pDC)
- {
- CDocument* pDoc = GetDocument();
-
- DrawScene();
- // TODO: add draw code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CBilliardsPlayView diagnostics
- #ifdef _DEBUG
- void CBilliardsPlayView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CBilliardsPlayView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CBilliardsPlayView message handlers
- void CBilliardsPlayView::Init()
- {
- CDC *pDC = GetDC();
- m_hDc = pDC->GetSafeHdc();
- SetThePixelFormat(pDC);
- m_hRc = wglCreateContext(m_hDc);
- wglMakeCurrent(m_hDc,m_hRc);
- ReleaseDC(pDC);
- GLfloat light0_posi[]={-40.0,0.0,100.0,1.0};
- GLfloat light1_posi[]={40.0,0.0,100.0,1.0};
- GLfloat light2_posi[]={0.0,100.0,0.0,1.0};
- GLfloat white_light[]={1.0,1.0,1.0,1.0};
- glClearColor(0.7,0.7,0.7,1.0);
- glShadeModel(GL_SMOOTH);
-
- glLightfv(GL_LIGHT0,GL_POSITION,light0_posi);
- glLightfv(GL_LIGHT0,GL_DIFFUSE,white_light);
- glLightfv(GL_LIGHT0,GL_SPECULAR,white_light);
- glLightfv(GL_LIGHT1,GL_POSITION,light1_posi);
- glLightfv(GL_LIGHT1,GL_DIFFUSE,white_light);
- glLightfv(GL_LIGHT1,GL_SPECULAR,white_light);
- glLightfv(GL_LIGHT2,GL_POSITION,light2_posi);
- glLightfv(GL_LIGHT2,GL_DIFFUSE,white_light);
- glLightfv(GL_LIGHT2,GL_SPECULAR,white_light);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_LIGHT1);
- glEnable(GL_LIGHT2);
- glEnable(GL_AUTO_NORMAL);
- glMatrixMode(GL_MODELVIEW);
- glRotatef(80.0,1.0,0.0,0.0);
-
- texinit();
- }
- void CBilliardsPlayView::DrawPlayground()
- {
- float tmpf,tmpf1;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- // glColor3f(1.0,1.0,1.0);
- float ambient0[4] = {0.259459f,0.251553f,0.0800367f,1.0f};
- float diffuse0[4] = {1.0f,0.969526f,0.308475f,1.0f};
- float specular0[4] = {0.728905f,0.691826f,0.153194f,1.0f};
- float shininess0 = 0.891892f;
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient0);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse0);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular0);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess0);
- // glPushMatrix();
- // glTranslatef( 0.0f, 0.0f, TABLE_WIDTH - 4.0*BAR_WIDTH);
- // auxSolidCylinder(POLE_RADIUS,POLE_HEIGHT);
- // glTranslatef( TABLE_LENGTH - 4.0*BAR_WIDTH, 0.0f, 0.0f);
- // auxSolidCylinder(POLE_RADIUS,POLE_HEIGHT);
- // glTranslatef( 0.0f, 0.0f, -2.0*(TABLE_WIDTH - 4.0*BAR_WIDTH));
- // auxSolidCylinder(POLE_RADIUS,POLE_HEIGHT);
- // glTranslatef( 4.0*BAR_WIDTH - TABLE_LENGTH, 0.0f, 0.0f);
- // auxSolidCylinder(POLE_RADIUS,POLE_HEIGHT);
- // glTranslatef( 4.0*BAR_WIDTH - TABLE_LENGTH, 0.0f, 0.0f);
- // auxSolidCylinder(POLE_RADIUS,POLE_HEIGHT);
- // glTranslatef( 0.0f, 0.0f, 2.0*(TABLE_WIDTH - 4.0*BAR_WIDTH));
- // auxSolidCylinder(POLE_RADIUS,POLE_HEIGHT);
- // glPopMatrix();
- //下桌面
- float ambient1[4] = {0.0f,0.023506f,0.014165f,1.0f};
- float diffuse1[4] = {0.0f,0.019048f,0.020158f,1.0f};
- float specular1[4] = {0.0714408f,0.20962f,0.126984f,1.0f};
- float shininess1 = 0.0108108f;
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient1);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse1);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular1);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess1);
- glPushMatrix();
- // glColor3f(0.0,1.0,0.0);
- glBegin(GL_QUAD_STRIP);
- glVertex3f(-TABLE_LENGTH-12.0f,0.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glVertex3f(-TABLE_LENGTH-12.0f,0.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glVertex3f(-TABLE_LENGTH-2.0f,0.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glVertex3f(-TABLE_LENGTH-2.0f,0.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-2.0f);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+2.0f);
- glEnd();
-
- glBegin(GL_QUADS);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-12.0f);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+12.0f);
- glVertex3f(-1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+12.0f);
- glVertex3f(-1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-12.0f);
- glEnd();
- glBegin(GL_QUADS);
- glVertex3f(1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-2.0f);
- glVertex3f(1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+2.0f);
- glVertex3f(-1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+2.0f);
- glVertex3f(-1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-2.0f);
- glEnd();
-
- glBegin(GL_QUADS);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-12.0f);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+12.0f);
- glVertex3f(1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+12.0f);
- glVertex3f(1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-12.0f);
- glEnd();
- glBegin(GL_QUAD_STRIP);
- glVertex3f(TABLE_LENGTH+12.0f,0.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glVertex3f(TABLE_LENGTH+12.0f,0.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glVertex3f(TABLE_LENGTH+2.0f,0.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glVertex3f(TABLE_LENGTH+2.0f,0.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-2.0f);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+2.0f);
- glEnd();
- float ambient2[4] = {0.7f,0.5f,0.5f,1.0f};
- float diffuse2[4] = {0.4f,0.3f,0.3f,1.0f};
- float specular2[4] = {0.0f,0.0f,0.0f,1.0f};
- float shininess2 = 0.0f;
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient2);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse2);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular2);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess2);
- glPushMatrix();
- //left
- glBegin(GL_QUADS);
- glVertex3f(-TABLE_LENGTH-12.0f,0.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glVertex3f(-TABLE_LENGTH-12.0f,0.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glVertex3f(-TABLE_LENGTH-12.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glVertex3f(-TABLE_LENGTH-12.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glEnd();
- //RIGHT
- glBegin(GL_QUADS);
- glVertex3f(TABLE_LENGTH+12.0f,0.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glVertex3f(TABLE_LENGTH+12.0f,0.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glVertex3f(TABLE_LENGTH+12.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glVertex3f(TABLE_LENGTH+12.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glEnd();
- //LEFT TOP
- glBegin(GL_QUADS);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-12.0f);
- glVertex3f(-1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-12.0f);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-12.0f);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-12.0f);
- glEnd();
- //LEFT down
- glBegin(GL_QUADS);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+12.0f);
- glVertex3f(-1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+12.0f);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+12.0f);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+12.0f);
- glEnd();
- //right TOP
- glBegin(GL_QUADS);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-12.0f);
- glVertex3f(1.5*BALL_RADIUS,0.0f,-TABLE_WIDTH-12.0f);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-12.0f);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-12.0f);
- glEnd();
- //right down
- glBegin(GL_QUADS);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+12.0f);
- glVertex3f(1.5*BALL_RADIUS,0.0f,TABLE_WIDTH+12.0f);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+12.0f);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+12.0f);
- glEnd();
- glPopMatrix();
-
- //bar texture
- glPushMatrix();
-
- glEnable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_2D,GL_TEXTURE_ENV_MODE,GL_DECAL);
- glBindTexture(GL_TEXTURE_2D,texName[0]);
- glBegin(GL_QUADS);
- glNormal3f(0.0,1.0,0.0);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH-12.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
-
- glTexCoord2f(1.0,0.0);
- glVertex3f(-TABLE_LENGTH-12.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- //glEnd();
- //glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH+12.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH+12.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glTexCoord2f(1.0,0.0);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
-
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-12.0f);
-
- glTexCoord2f(1.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-12.0f);
-
- glTexCoord2f(1.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
-
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+12.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
-
- glTexCoord2f(1.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+12.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
-
- glTexCoord2f(0.0,1.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-12.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-12.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+12.0f);
-
- glTexCoord2f(0.0,1.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
-
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
-
- glTexCoord2f(1.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+12.0f);
- glEnd();
-
- glPopMatrix();
- glDisable(GL_TEXTURE_2D);
- // face texture
- glPushMatrix();
- glEnable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_2D,GL_TEXTURE_ENV_MODE,GL_DECAL);
- glBindTexture(GL_TEXTURE_2D,texName[1]);
- glBegin(GL_POLYGON);
- glTexCoord2f(0.0,0.05);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT,TABLE_WIDTH-1.5*BALL_RADIUS);
- glTexCoord2f(0.0,0.95);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(0.05,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT,-TABLE_WIDTH-2.0f);
- glTexCoord2f(0.95,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT,-TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.95);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(1.0,0.05);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT,TABLE_WIDTH-1.5*BALL_RADIUS);
- glTexCoord2f(0.95,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT,TABLE_WIDTH+2.0f);
- glTexCoord2f(0.05,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT,TABLE_WIDTH+2.0f);
- glEnd();
- glPopMatrix();
- glDisable(GL_TEXTURE_2D);
- //edge texture
- glPushMatrix();
- glEnable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_2D,GL_TEXTURE_ENV_MODE,GL_DECAL);
- glBindTexture(GL_TEXTURE_2D,texName[2]);
- //left
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT,TABLE_WIDTH-1.5*BALL_RADIUS);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT,TABLE_WIDTH-1.5*BALL_RADIUS);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glEnd();
- //right
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT,-TABLE_WIDTH+1.5*BALL_RADIUS);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT,TABLE_WIDTH-1.5*BALL_RADIUS);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT,TABLE_WIDTH-1.5*BALL_RADIUS);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH+2.0f,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH-1.5*BALL_RADIUS);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+1.5*BALL_RADIUS+6.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(TABLE_LENGTH-2.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-1.5*BALL_RADIUS-6.0f);
- glEnd();
- //left top
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT,-TABLE_WIDTH-2.0f);
- glEnd();
-
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT,-TABLE_WIDTH-2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT,-TABLE_WIDTH-2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT,-TABLE_WIDTH-2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glEnd();
- //right top
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT,-TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glEnd();
-
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT,-TABLE_WIDTH-2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT,-TABLE_WIDTH-2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT,-TABLE_WIDTH-2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,-TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,-TABLE_WIDTH+2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,-TABLE_WIDTH+2.0f);
- glEnd();
-
- //left down
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT,TABLE_WIDTH+2.0f);
- glEnd();
-
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT,TABLE_WIDTH+2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT,TABLE_WIDTH+2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT,TABLE_WIDTH+2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(-TABLE_LENGTH+1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glEnd();
-
- //right down
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT,TABLE_WIDTH+2.0f);
- glEnd();
-
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT,TABLE_WIDTH+2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT,TABLE_WIDTH+2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT,TABLE_WIDTH+2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS,TABLE_HEIGHT+BALL_RADIUS+2.0f,TABLE_WIDTH+2.0f);
- glEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0,0.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(0.0,1.0);
- glVertex3f(TABLE_LENGTH-1.5*BALL_RADIUS-6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,1.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS-1.0f,TABLE_WIDTH-2.0f);
- glTexCoord2f(1.0,0.0);
- glVertex3f(1.5*BALL_RADIUS+6.0f,TABLE_HEIGHT+BALL_RADIUS+1.0f,TABLE_WIDTH-2.0f);
- glEnd();
- glPopMatrix();
-
- glPopMatrix();
- glFlush();
- glFinish();
- SwapBuffers(wglGetCurrentDC());
- glDisable(GL_TEXTURE_2D);
- }
- void CBilliardsPlayView::DrawBall()
- {
- /*glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glTranslatef(0.0f, TABLE_HEIGHT/2.0+BALL_RADIUS, 0.0f);
- if (m_bVisible[0])
- {
- glPushMatrix();
- glTranslatef(m_fPosition[0][0],m_fPosition[0][1],m_fPosition[0][2]);
- float ambient0[4] = {0.2f,0.2f,0.2f,1.0f};
- float diffuse0[4] = {0.9f, 0.9f, 0.9f,1.0f};
- float specular0[4] = {0.25f,0.25f,0.25f,1.0f};
- float shininess0 = 0.8f;
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient0);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse0);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular0);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess0);
- glutSolidSphere(BALL_RADIUS,20,16);
- glPopMatrix();
- }
- float ambient1[4] = {0.2f,0.08f,0.0f,1.0f};
- float diffuse1[4] = {0.8f,0.0f,0.0f,1.0f};
- float specular1[4] = {0.1f,0.3f,0.1f,1.0f};
- float shininess1 = 0.8f;
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient1);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse1);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular1);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess1);
- for (int i = 1; i<8; i++)
- if (m_bVisible[i])
- {
- glPushMatrix();
- glTranslatef(m_fPosition[i][0],m_fPosition[i][1],m_fPosition[i][2]);
- glutSolidSphere(BALL_RADIUS,20,16);
- glPopMatrix();
- }
- if (m_bVisible[8])
- {
- glPushMatrix();
- glTranslatef(m_fPosition[8][0],m_fPosition[8][1],m_fPosition[8][2]);
- float ambient2[4] = {0.0f,0.1f,0.1f,1.0f};
- float diffuse2[4] = {0.1f,0.1f,0.1f,1.0f};
- float specular2[4] = {0.2f,0.2f,0.2f,1.0f};
- float shininess2 = 0.8f;
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient2);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse2);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular2);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess2);
- glutSolidSphere(BALL_RADIUS,20,16);
- glPopMatrix();
- }
- float ambient3[4] = {0.09f,0.0f,0.1f,1.0f};
- float diffuse3[4] = {0.0f,0.0f,0.8f,1.0f};
- float specular3[4] = {0.1f,0.3f,0.1f,1.0f};
- float shininess3 = 0.8f;
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient3);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse3);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular3);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess3);
- for (i = 9; i<16; i++)
- if (m_bVisible[i])
- {
- glPushMatrix();
- glTranslatef(m_fPosition[i][0],m_fPosition[i][1],m_fPosition[i][2]);
- glutSolidSphere(BALL_RADIUS,20,16);
- glPopMatrix();
- }
- glPopMatrix();*/
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glTranslatef(0.0f, TABLE_HEIGHT+BALL_RADIUS, 0.0f);
- // GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
- // GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
- // GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
- // GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 };
- // GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
- // GLfloat no_shininess[] = { 0.0 };
- // GLfloat low_shininess[] = { 5.0 };
- // GLfloat high_shininess[] = { 100.0 };
- // GLfloat mat_emission[] = {0.3, 0.2, 0.2, 0.0};
- //
- // glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
- // glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
- // glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
- // glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
- // glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
-
- if (m_bVisible[0])
- {
- glPushMatrix();
- glTranslatef(m_fPosition[0][0],m_fPosition[0][1],m_fPosition[0][2]);
- float ambient0[4] = {0.5f,0.5f,0.5f,1.0f};
- float diffuse0[4] = {0.4f,0.4f,0.4f,1.0f};
- //float specular0[4] = {0.25f,0.25f,0.25f,1.0f};
- float specular0[] = {1.0f,1.0f,1.0f,1.0f};
- float shininess0 = 100.0f;
- //float mat_emission[] = {0.3, 0.2, 0.2, 0.0};
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient0);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse0);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular0);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess0);
- //glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
- glutSolidSphere(BALL_RADIUS,20,16);
- glPopMatrix();
- }
- float ambient1[4] = {0.2f,0.08f,0.0f,1.0f};
- float diffuse1[4] = {0.8f,0.0f,0.0f,1.0f};
- // float specular1[4] = {0.1f,0.3f,0.1f,1.0f};
- // float shininess1 = 0.8f;
- float specular1[] = {1.0f,1.0f,1.0f,1.0f};
- float shininess1 = 100.0f;
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient1);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse1);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular1);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess1);
- for (int i = 1; i<9; i++)
- if (m_bVisible[i])
- {
- glPushMatrix();
- glTranslatef(m_fPosition[i][0],m_fPosition[i][1],m_fPosition[i][2]);
- glutSolidSphere(BALL_RADIUS,20,16);
- glPopMatrix();
- }
- // if (m_bVisible[8])
- // {
- // glPushMatrix();
- // glTranslatef(m_fPosition[8][0],m_fPosition[8][1],m_fPosition[8][2]);
- // float ambient2[4] = {0.0f,0.1f,0.1f,1.0f};
- // float diffuse2[4] = {0.1f,0.1f,0.1f,1.0f};
- //// float specular2[4] = {0.2f,0.2f,0.2f,1.0f};
- //// float shininess2 = 0.8f;
- // float specular2[] = {1.0f,1.0f,1.0f,1.0f};
- // float shininess2 = 100.0f;
- //
- // glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient2);
- // glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse2);
- // glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular2);
- // glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess2);
- // glutSolidSphere(BALL_RADIUS,20,16);
- // glPopMatrix();
- // }
- float ambient3[4] = {0.09f,0.0f,0.1f,1.0f};
- float diffuse3[4] = {0.0f,0.0f,0.8f,1.0f};
- // float specular3[4] = {0.1f,0.3f,0.1f,1.0f};
- // float shininess3 = 0.8f;
- float specular3[] = {1.0f,1.0f,1.0f,1.0f};
- float shininess3 = 100.0f;
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient3);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse3);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular3);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess3);
- for (i = 9; i<16; i++)
- if (m_bVisible[i])
- {
- glPushMatrix();
- glTranslatef(m_fPosition[i][0],m_fPosition[i][1],m_fPosition[i][2]);
- glutSolidSphere(BALL_RADIUS,20,16);
- glPopMatrix();
- }
- glPopMatrix();
- }
- int CBilliardsPlayView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- Init();
-
- return 0;
- }
- BOOL CBilliardsPlayView::SetThePixelFormat(CDC *pDC)
- {
- static PIXELFORMATDESCRIPTOR pfd = {
- sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
- 1, // version number
- PFD_DRAW_TO_WINDOW | // support window
- PFD_SUPPORT_OPENGL | // support OpenGL
- PFD_DOUBLEBUFFER, // double buffered
- PFD_TYPE_RGBA, // RGBA type
- 24, // 24-bit color depth
- 0, 0, 0, 0, 0, 0, // color bits ignored
- 0, // no alpha buffer
- 0, // shift bit ignored
- 0, // no accumulation buffer
- 0, 0, 0, 0, // accum bits ignored
- 32, // 32-bit z-buffer
- 0, // no stencil buffer
- 0, // no auxiliary buffer
- PFD_MAIN_PLANE, // main layer
- 0, // reserved
- 0, 0, 0 // layer masks ignored
- };
- int pixelformat;
- if((pixelformat = ChoosePixelFormat(m_hDc, &pfd)) == 0)
- {
- MessageBox( "ChoosePixelFormat failed", "Error", MB_OK);
- return FALSE;
- }
- if(SetPixelFormat(m_hDc, pixelformat, &pfd) == FALSE)
- {
- MessageBox( "SetPixelFormat failed", "Error", MB_OK);
- return FALSE;
- }
- CreateRGBPalette(m_hDc);
- return TRUE;
- }
- BOOL CBilliardsPlayView::PreCreateWindow(CREATESTRUCT& cs)
- {
- cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN ;
- cs.dwExStyle |= WS_EX_CLIENTEDGE;
- cs.style &= ~WS_BORDER;
- cs.lpszClass = AfxRegisterWndClass(CS_OWNDC|CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
- ::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);
-
- if (!CWnd::PreCreateWindow(cs))
- return FALSE;
- return TRUE;
- }
- void CBilliardsPlayView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
-
- Project();
- }
- void CBilliardsPlayView::Project()
- {
- RECT rect;
- GetClientRect( &rect);
- GLsizei nWidth = rect.right;
- GLsizei nHeight = rect.bottom;
- nHeight = (nHeight == 0) ? 1 : nHeight;
- float dAspect = (float)nWidth/(float)nHeight;
- m_fViewWidth = m_fViewHeight * dAspect;
- glViewport(0,0,nWidth,nHeight);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-m_fViewWidth, m_fViewWidth,
- -m_fViewHeight, m_fViewHeight,
- m_fViewNear, m_fViewFar );
- gluLookAt(m_sEye.origin.x,m_sEye.origin.y,m_sEye.origin.z,
- m_sEye.center.x,m_sEye.center.y,m_sEye.center.z,
- m_sEye.up.x,m_sEye.up.y,m_sEye.up.z);
- glMatrixMode(GL_MODELVIEW);
- }
- BOOL CBilliardsPlayView::OnEraseBkgnd(CDC* pDC)
- {
- return TRUE;
- }
- void CBilliardsPlayView::DrawScene()
- {
- int j;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- if (m_bAnimate)
- {
- if (Calculate())
- {
- KillTimer(ANIMATE_TIMER);
- m_bAnimate = FALSE;
- if (m_nEnter != 100)
- {
- CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
- CBilliardsPlayView *pView = (CBilliardsPlayView *)(pFrame->m_wndSplitter).GetPane(0,1);
- CBilliardsDoc *pDoc = (CBilliardsDoc *)pView->GetDocument();
- CString strTemp;
- if (m_nEnter <= 0)
- m_bCanHit = !m_bCanHit;
- else
- {
- if (m_bCanHit)
- {
- //strTemp = _T("Hehe, 我进球了");
- //pDoc->SendMsg(strTemp);
- }
- if (pDoc->m_bPlayer == SERVER)
- {
- for (j=8; j>0; j--)
- if (m_bVisible[j])
- break;
- if (j<=0)
- {
- //pDoc->WinGame();
- }
- else if (m_bCanHit && !m_bVisible[8])
- {
- //pDoc->LoseGame();
- }
- else
- {
- for (j=8; j<NUM_BALL; j++)
- if (m_bVisible[j])
- break;
- if (j>=NUM_BALL)
- {
- // pDoc->LoseGame();
- }
- else if (!m_bCanHit && !m_bVisible[8])
- {
- // pDoc->WinGame();
- }
- }
- }
- else if (pDoc->m_bPlayer == CLIENT)
- {
- for (j=8; j<NUM_BALL; j++)
- if (m_bVisible[j])
- break;
- if (j>=NUM_BALL)
- {
- //pDoc->WinGame();
- }
- else if (m_bCanHit && !m_bVisible[8])
- {
- //pDoc->LoseGame();
- }
- else
- {
- for (j=8; j>0; j--)
- if (m_bVisible[j])
- break;
- if (j<=0)
- {
- // pDoc->LoseGame();
- }
- else if (!m_bCanHit && !m_bVisible[8])
- {
- // pDoc->WinGame();
- }
- }
- }
- if (!m_bVisible[0])
- m_bCanHit = !m_bCanHit;
- }
- if (pDoc->m_bPlayer == IDLE)
- m_bCanHit = TRUE;
- else
- {
- if (m_bCanHit)
- {
- //strTemp = _T("1该我击球");
- //pDoc->m_pClientSocket->Send(strTemp,strTemp.GetLength());
- }
- }
- }
- if (!m_bVisible[0]) //母球落袋后重画母球
- {
- m_fPosition[0][1]=m_fPosition[0][2]=0.0f;
- m_fPosition[0][0] = - 2.0*TABLE_LENGTH/3.0;
- m_bVisible[0]=TRUE;
- }
- m_fStrength=22.5f;
- m_fDirection[0]=1.0f;
- m_fDirection[2]=0.0f;
- m_fVelocity[0][0]=5.0f;
- }
- }
- DrawPlayground();
- DrawBall();
- if (!m_bAnimate)
- {
- glPushName(1);
- DrawArrow();
- glPopName();
- }
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-
- glFlush();
- SwapBuffers(m_hDc); //交换缓冲区
- }
- void CBilliardsPlayView::DrawArrow()
- {
- float angle;
- int mode;
- glGetIntegerv(GL_RENDER_MODE , &mode);
- glDisable(GL_LIGHTING);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glTranslatef(0.0f, TABLE_HEIGHT/2.0+2.0*BALL_RADIUS, 0.0f);
- glTranslatef(m_fPosition[0][0],m_fPosition[0][1],m_fPosition[0][2]);
- glColor3f(0.5f,0.5f,0.0f);
- glLineWidth(1.5);
- if (m_fDirection[0]>=0.0)
- angle = asin(m_fDirection[2])/M_PI*180.0;
- else
- angle = 180.0 - asin(m_fDirection[2])/M_PI*180.0;
- glRotatef(-angle,0.0f,1.0f,0.0f);
- glBegin(GL_LINES);
- glVertex3f(0.0f,0.0f,0.0f);
- glVertex3f(m_fStrength,0.0,0.0);
- glEnd();
- glTranslatef(m_fStrength,0.0f,0.0f);
- glBegin(GL_TRIANGLES);
- glVertex3f(-2.0f, 0.0f, 2.0f);
- glVertex3f(-2.0f, 0.0f, -2.0f);
- glVertex3f(3.0f, 0.0f, 0.0f);
- glEnd();
- glPopMatrix();
- glEnable(GL_LIGHTING);
- glLineWidth(1.0);
- }
- int CBilliardsPlayView::Calculate()
- {
- CMainFrame *pView=(CMainFrame *)(AfxGetMainWnd());
- float x1,z1,x2,z2,x3,z3;
- float tmpf,minf;
- BOOL mark[NUM_BALL][NUM_BALL];
- int i,j;
- int k;
- x1 = TABLE_LENGTH - BAR_WIDTH;
- z1 = TABLE_WIDTH - BAR_WIDTH;
- x2 = 0.0;
- z2 = TABLE_WIDTH;
- for (i=0;i<NUM_BALL;i++)
- if (m_bVisible[i])
- {
- x3 = fabs(m_fPosition[i][0]);
- z3 = fabs(m_fPosition[i][2]);
- if (((x1-x3)*(x1-x3)+(z1-z3)*(z1-z3)<2.0*BALL_RADIUS*BALL_RADIUS)||
- ((x2-x3)*(x2-x3)+(z2-z3)*(z2-z3)<2.0*BALL_RADIUS*BALL_RADIUS))//球进洞了
- {
- m_bVisible[i] = FALSE;
- if(pView->m_bSoundGoal)
- sndPlaySound("res\goal.wav",SND_ASYNC);
- if (m_nEnter<i) //?
- m_nEnter = i;
- }
- }
- for (i=0;i<NUM_BALL;i++)
- for (j=0;j<NUM_BALL;j++)
- mark[i][j]=FALSE;
- for (i=0;i<NUM_BALL;i++)
- if (m_bVisible[i])
- {
- if ((m_fPosition[i][0]>TABLE_LENGTH-BAR_WIDTH-BALL_RADIUS)&&(fabs(m_fPosition[i][2])<TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS))
- {//右壁
- m_fPosition[i][0]=TABLE_LENGTH-BAR_WIDTH-BALL_RADIUS;
- hitx=INFINITY;
- hitz=INFINITY;
- if (m_fVelocity[i][0]>0.0){
- m_fVelocity[i][0] = -DECR*m_fVelocity[i][0];
- if(pView->m_bSoundCush)
- sndPlaySound("res\cush.wav",SND_ASYNC);
- }
- }
- else if ((m_fPosition[i][0]<-(TABLE_LENGTH-BAR_WIDTH-BALL_RADIUS))&&(fabs(m_fPosition[i][2])<TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS))
- {//左壁
- m_fPosition[i][0]=-(TABLE_LENGTH-BAR_WIDTH-BALL_RADIUS);
- hitx=INFINITY;
- hitz=INFINITY;
- if (m_fVelocity[i][0]<0.0){
- m_fVelocity[i][0] = -DECR*m_fVelocity[i][0];
- if(pView->m_bSoundCush)
- sndPlaySound("res\cush.wav",SND_ASYNC);
- }
- }
- else if ((m_fPosition[i][2]>TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS)&&(fabs(m_fPosition[i][0])>1.2*BALL_RADIUS))
- {//上壁
- m_fPosition[i][2]=TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS;
- hitx=INFINITY;
- hitz=INFINITY;
- if (m_fVelocity[i][2]>0.0){
- m_fVelocity[i][2] = -DECR*m_fVelocity[i][2];
- if(pView->m_bSoundCush)
- sndPlaySound("res\cush.wav",SND_ASYNC);
- }
- }
- else if ((m_fPosition[i][2]<-(TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS))&&(fabs(m_fPosition[i][0])>1.2*BALL_RADIUS))
- {//下壁
- m_fPosition[i][2]=-(TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS);
- hitx=INFINITY;
- hitz=INFINITY;
- if (m_fVelocity[i][2]<0.0){
- m_fVelocity[i][2] = -DECR*m_fVelocity[i][2];
- if(pView->m_bSoundCush)
- sndPlaySound("res\cush.wav",SND_ASYNC);
- }
- }
- else//不碰壁
- {
- minf = 8*BALL_RADIUS*BALL_RADIUS;
- for (j=0;j<NUM_BALL;j++)
- if (m_bVisible[j]&&(i!=j)&&!mark[i][j])
- {
- tmpf = (m_fPosition[i][0]-m_fPosition[j][0])*(m_fPosition[i][0]-m_fPosition[j][0])+(m_fPosition[i][2]-m_fPosition[j][2])*(m_fPosition[i][2]-m_fPosition[j][2]);
- //两球心距离的平方和
- if (tmpf<minf)
- {
- minf=tmpf;
- k=j;
- }
- }
- if (minf<=4*BALL_RADIUS*BALL_RADIUS)//两球心距离的平方和
- {
- float line[3];
- float t1,t2;
- float vec1[3],vec2[3],vec3[3],vec4[3];
-
- line[0]=m_fPosition[k][0]-m_fPosition[i][0]; //x坐标差
- line[1]=0.0f;
- line[2]=m_fPosition[k][2]-m_fPosition[i][2]; //z坐标差
- t1 = sqrt(DOTPROD3(line,line)); //长度
- if (t1>0.0)
- VEC3_V_OP_S(line,line,/,t1); //line[i]=line[i]/t1,成单位向量
-
- t1=DOTPROD3(m_fVelocity[i],line); //i号球的速度乘单位向量
- t2=DOTPROD3(m_fVelocity[k],line); //k号球的速度乘单位向量
- VEC3_V_OP_S(vec1,line,*,t1); //恢复原line的长度,放入vec1
- VEC3_V_OP_V(vec1,m_fVelocity[i],-,vec1); //i号球的x,z方向的分速度-vec1x,z方向分速度
- VEC3_V_OP_S(vec2,line,*,t2); //k号球的速度
- VEC3_V_OP_V(vec2,m_fVelocity[k],-,vec2); //
- if (t1-t2>0.0)
- {
- VEC3_V_OP_S(vec3,line,*,t2);
- VEC3_V_OP_V(m_fVelocity[i],vec1,+,vec3);
- VEC3_V_OP_S(vec4,line,*,t1);
- VEC3_V_OP_V(m_fVelocity[k],vec2,+,vec4);
- mark[i][k]=mark[k][i]=TRUE;
- if(pView->m_bSoundBall)
- sndPlaySound("res\ball2ball.wav",SND_ASYNC);
- }
- hitx=INFINITY;
- hitz=INFINITY;
-
- }
- }
-
- if (fabs(m_fPosition[i][0])>TABLE_LENGTH||fabs(m_fPosition[i][2])>TABLE_WIDTH)
- {
- m_bVisible[i]=FALSE;
- if(pView->m_bSoundGoal)
- sndPlaySound("res\goal.wav",SND_ASYNC);
- if (m_nEnter<i)
- m_nEnter = i;
- }
- }
- for (i=0;i<NUM_BALL;i++)
- if (m_bVisible[i])
- {
- float t1,s1;
- float vec1[3];
- t1 = sqrt(DOTPROD3(m_fVelocity[i],m_fVelocity[i]));
- if (t1>0.0f)
- {
- VEC3_V_OP_S(vec1,m_fVelocity[i],/,t1);
- s1 = t1+ACCELERATION/2.0;
- t1 = t1+ACCELERATION;
- if (t1<-0.1*ACCELERATION) //速度小于一定值就停下来
- {
- s1=0.0f;
- t1=0.0f;
- }
- VEC3_V_OP_S(m_fVelocity[i],vec1,*,t1);
- VEC3_V_OP_S(vec1,vec1,*,s1);
-
- if(i==0){
- if(DOTPROD3(vec1,vec1)>((m_fPosition[i][0]-hitx)*(m_fPosition[i][0]-hitx)+(m_fPosition[i][2]-hitz)*(m_fPosition[i][2]-hitz))){
- m_fPosition[i][0]=hitx;
- m_fPosition[i][2]=hitz;
- hitx=INFINITY;
- hitz=INFINITY;
- }
- else
- VEC3_V_OP_V(m_fPosition[i],m_fPosition[i],+,vec1);
- }
- else
- VEC3_V_OP_V(m_fPosition[i],m_fPosition[i],+,vec1);
- x3 = fabs(m_fPosition[i][0]);
- z3 = fabs(m_fPosition[i][2]);
- if (((x1-x3)*(x1-x3)+(z1-z3)*(z1-z3)<BALL_RADIUS*BALL_RADIUS)||
- ((x2-x3)*(x2-x3)+(z2-z3)*(z2-z3)<BALL_RADIUS*BALL_RADIUS))
- ;
- //以下防止球越界过多
- else if ((m_fPosition[i][0]>TABLE_LENGTH-BAR_WIDTH-BALL_RADIUS)&&(fabs(m_fPosition[i][2])<TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS))
- {
- m_fPosition[i][0]=TABLE_LENGTH-BAR_WIDTH-BALL_RADIUS+0.01;
-
- }
- else if ((m_fPosition[i][0]<-(TABLE_LENGTH-BAR_WIDTH-BALL_RADIUS))&&(fabs(m_fPosition[i][2])<TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS))
- {
- m_fPosition[i][0]=-(TABLE_LENGTH-BAR_WIDTH-BALL_RADIUS)-0.01;
- hitx=INFINITY;
- hitz=INFINITY;
- }
- else if ((m_fPosition[i][2]>TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS)&&(fabs(m_fPosition[i][0])>1.2*BALL_RADIUS))
- {
- m_fPosition[i][2]=TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS+0.01;
- hitx=INFINITY;
- hitz=INFINITY;
- }
- else if ((m_fPosition[i][2]<-(TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS))&&(fabs(m_fPosition[i][0])>1.2*BALL_RADIUS))
- {
- m_fPosition[i][2]=-(TABLE_WIDTH-BAR_WIDTH-BALL_RADIUS)-0.01;
- hitx=INFINITY;
- hitz=INFINITY;
- }
-
- for (j=0;j<NUM_BALL;j++)
- if (m_bVisible[j]&&(i!=j))
- {
- tmpf = (m_fPosition[i][0]-m_fPosition[j][0])*(m_fPosition[i][0]-m_fPosition[j][0])+(m_fPosition[i][2]-m_fPosition[j][2])*(m_fPosition[i][2]-m_fPosition[j][2]);
- if (tmpf<4*BALL_RADIUS*BALL_RADIUS)
-
- break;
- }
- if (j<NUM_BALL) //出现两球距离小于直径的情况
- {
-
- VEC3_V_OP_S(vec1,vec1,/,2.0);
- VEC3_V_OP_V(m_fPosition[i],m_fPosition[i],-,vec1);
-
- }
- }
- }
- for (i=0;i<NUM_BALL;i++)
- if (m_bVisible[i])
- if ((m_fVelocity[i][0]!=0.0)||(m_fVelocity[i][2]!=0.0))
- break;
- if (i<NUM_BALL)
- return 0;
- return 1;
- }
- void CBilliardsPlayView::MouseSpinGlobal(UINT nFlags, int x, int y, int init)
- {
- float centerX, centerY;
- float radius;
- float w, h; // window
- RECT rect;
- GetClientRect( &rect);
- w =(float)rect.right;
- h =(float)rect.bottom;
- h = (h == 0.0f) ? 1.0f : h;
- centerX = w / 2.0f;
- centerY = h / 2.0f;
- radius = (w > h) ? centerY : centerX ;
- if (init)
- {
- Trackball( 0, radius, centerX, centerY, (float)x, (float)(h-y),
- m_spinAxes[0], m_spinAxes[1], m_spinAxes[2], m_spinAngle);
- }
- else if ( nFlags & MK_LBUTTON )
- {
- Trackball(1, radius, centerX, centerY, (float)x, (float)(h-y),
- m_spinAxes[0], m_spinAxes[1], m_spinAxes[2], m_spinAngle);
- SpinGlobal(m_spinAxes, m_spinAngle);
- }
- }
- void CBilliardsPlayView::SpinGlobal(float axes[], float angle)
- {
- EyeRotate(m_vProjectCenter, axes, angle, m_sEye );
- DrawScene();
- }
- void CBilliardsPlayView::MouseZoom(UINT nFlags, int x, int y)
- {
- float w, h;
- float scale;
- static float oldY, dy ;
- RECT rect;
- GetClientRect( &rect);
- w =(float)rect.right;
- h =(float)rect.bottom;
- h = (h == 0.0f) ? 1.0f : h;
- if( m_bLButtonDown && (nFlags & MK_LBUTTON))
- {
- dy=oldY-y;
- scale=1.0f+dy/h;
- Zoom(scale);
- oldY=(float)y;
- }
- else
- {
- oldY=(float)y;
- }
- }
- void CBilliardsPlayView::Zoom(float scale)
- {
- double a[1][2];
- a[0][0] = 1.0;
- a[0][1] = 2.0;
- double *p;
- p = (double *)a;
- if(scale<0.001) return;
- m_fViewHeight/=scale;
- Project();
- DrawScene();
- }
- void CBilliardsPlayView::MouseTranslate(UINT nFlags, int x, int y)
- {
- float w, h;
- static float oldX, oldY, dx, dy, d[3] ;
- RECT rect;
- GetClientRect( &rect);
- w =(float)rect.right;
- h =(float)rect.bottom;
- h = (h == 0.0f) ? 1.0f : h;
- if( m_bLButtonDown && (nFlags & MK_LBUTTON))
- {
- dx=x-oldX;
- dy=oldY-y;
- d[0]=m_fViewWidth*dx/w*0.8f;
- d[1]=m_fViewHeight*dy/h*0.8f;
- d[2]=0.0f;
- Translate(d);
- oldX=(float)x;
- oldY=(float)y;
- }
- else
- {
- oldX=(float)x;
- oldY=(float)y;
- }
- }
- void CBilliardsPlayView::Translate(float d[])
- {
- EyeTranslate(d, m_sEye);
- DrawScene();
- }
- void CBilliardsPlayView::OnMouseMove(UINT nFlags, CPoint point)
- {
- CBilliardsFormView *pView=(CBilliardsFormView *)(((CMainFrame *)AfxGetMainWnd())->m_wndSplitter.GetPane(0,1));
- if ( nFlags & MK_LBUTTON )
- {
- if (m_nMouseAct == MOUSE_SPIN)
- {
- MouseSpinGlobal(nFlags, point.x, point.y, 0);
- }
- else if (m_nMouseAct == MOUSE_ZOOM)
- {
- MouseZoom(nFlags, point.x, point.y);
- }
- else if (m_nMouseAct == MOUSE_TRANSLATE)
- {
- MouseTranslate(nFlags, point.x, point.y);
- }
-
-
- else if (m_nMouseAct == MOUSE_SELECT)
- {
- if (m_nSelectObject == 1)
- {
- int x,y;
- int j;
- //float slope;
- //float a,b,c;//斜率
- //float tempx,tempx1,tempx2,tempz,tempz1,tempz2,templength;
-
- float length=INFINITY; //当无穷大用;
- GLdouble modelMatrix[16];
- GLdouble projMatrix[16];
- GLint viewport[4];
- RECT rect;
- GLdouble dx,dy,dz;
- GLdouble sx,sy,sz;
- GLdouble ox,oy,oz;
- float tmpf;
- x = point.x;
- y = point.y;
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glTranslatef(0.0f, TABLE_HEIGHT/2.0+2.0*BALL_RADIUS, 0.0f);
- glTranslatef(m_fPosition[0][0],m_fPosition[0][1],m_fPosition[0][2]);
- GetClientRect(&rect);
- y = rect.bottom-y;
- glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
- glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
- glGetIntegerv(GL_VIEWPORT,viewport);
- gluProject(m_fDirection[0],0.0f,m_fDirection[2],
- modelMatrix,projMatrix,viewport,
- &sx,&sy,&sz);
- gluProject(0.0f,0.0f,0.0f,
- modelMatrix,projMatrix,viewport,
- &ox,&oy,&oz);
- tmpf = sqrt(((float)x-ox)*((float)x-ox)+((float)y-oy)*((float)y-oy))/
- sqrt((sx-ox)*(sx-ox)+(sy-oy)*(sy-oy));
- gluProject(tmpf*m_fDirection[0],0.0f,tmpf*m_fDirection[2],
- modelMatrix,projMatrix,viewport,
- &sx,&sy,&sz);
- gluUnProject((float)x,(float)y,sz,
- modelMatrix,projMatrix,viewport,
- &dx,&dy,&dz);
- m_fDirection[0] = dx;
- m_fDirection[2] = dz;
- m_fStrength = tmpf = sqrt(dx*dx+dz*dz);
- /*
- if(dx!=0){
- slope=dz/dx;
- for (j=0; j<NUM_BALL; j++)
- if (m_bVisible[j]){
- b=-(2.0*m_fPosition[j][0]+2.0*m_fPosition[0][0]*slope-(2.0*m_fPosition[j][2]*slope));
- a=slope;
- c=m_fPosition[j][0]*m_fPosition[j][0]*slope*slope-2.0*m_fPosition[0][2]*m_fPosition[j][2]*slope+m_fPosition[j][2]*m_fPosition[j][2]-4.0*BALL_RADIUS*BALL_RADIUS;
- if(b*b-4*a*c>0){
- tempx2=(-b-sqrt(b*b-4*a*c))/(2*a);
- tempx1=(-b+sqrt(b*b-4*a*c))/(2*a);
- tempx=fabs(tempx1-m_fPosition[0][0])-fabs(tempx2-m_fPosition[0][0])<0?tempx1:tempx2;
- tempz=slope*(tempx-m_fPosition[0][0])+m_fPosition[0][2];
- templength=sqrt((tempx-m_fPosition[0][0])*(tempx-m_fPosition[0][0])+(tempz-m_fPosition[0][2])*(tempz-m_fPosition[0][2]));
- if(length>templength){
- length=templength;
- hitx=tempx;
- hitz=tempz;
- }
- }
- }
- }
- else{
- for (j=0; j<NUM_BALL; j++)
- if (m_bVisible[j]){
- if(fabs(m_fPosition[j][2]-m_fPosition[0][2])<2*BALL_RADIUS){
- tempz1=m_fPosition[j][2]-sqrt(4*BALL_RADIUS*BALL_RADIUS-(m_fPosition[0][0]-m_fPosition[j][0])*(m_fPosition[0][0]-m_fPosition[j][0]));
- tempz2=m_fPosition[j][2]+sqrt(4*BALL_RADIUS*BALL_RADIUS-(m_fPosition[0][0]-m_fPosition[j][0])*(m_fPosition[0][0]-m_fPosition[j][0]));
- tempz=fabs(tempz1-m_fPosition[0][2])-fabs(tempz2-m_fPosition[0][2])<0?tempz1:tempz2;
- templength=fabs(m_fPosition[j][2]-m_fPosition[0][2]);
- if(length>templength){
- length=templength;
- hitx=m_fPosition[0][0];
- hitz=tempz;
- }
- }
- }
- }
- */
- VEC3_V_OP_S(m_fDirection,m_fDirection,/,tmpf);
- if (tmpf<16.0)
- tmpf = 16.0;
- else if (tmpf>30.0)
- tmpf = 30.0;
- tmpf = (tmpf-15.0)*2.0/3.0;
- VEC3_V_OP_S(m_fVelocity[0],m_fDirection,*,tmpf);
- pView->m_ctlProgressPower.SetPos(DOTPROD3(m_fVelocity[0],m_fVelocity[0]));
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- DrawScene();
- }
- }
- }
- CView::OnMouseMove(nFlags, point);
- }
- void CBilliardsPlayView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- m_spinAngle = 0.0f;
- if (m_nMouseAct == MOUSE_SPIN)
- {
- MouseSpinGlobal(nFlags, point.x, point.y, 1);
- }
- else if (m_nMouseAct == MOUSE_ZOOM)
- {
- MouseZoom(nFlags, point.x, point.y);
- }
- else if (m_nMouseAct == MOUSE_TRANSLATE)
- {
- MouseTranslate(nFlags, point.x, point.y);
- }
- else if (m_nMouseAct == MOUSE_SELECT)
- {
- if (m_bCanHit)
- {
- int hit = MouseSelect(point.x, point.y);
- if (hit>0)
- {
- GLuint name[3];
- m_nSelectObject = GetSelectObjFront(hit, name);
- }
- }
- }
-
- CView::OnLButtonDown(nFlags, point);
- /*
- MSG msg;
- while(::PeekMessage( &msg, m_hWnd,
- WM_MOUSEMOVE, WM_MOUSEMOVE,
- PM_REMOVE))
- ;
- */
- m_bLButtonDown = TRUE;
- }
- void CBilliardsPlayView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- m_bLButtonDown = FALSE;
- m_nSelectObject = -1;
- /*
- MSG msg;
- while(::PeekMessage( &msg, m_hWnd,
- WM_MOUSEMOVE, WM_MOUSEMOVE,
- PM_REMOVE))
- ;
- */
- CView::OnLButtonUp(nFlags, point);
- }
- int CBilliardsPlayView::MouseSelect(int x, int y)
- {
- RECT rect;
- float winH;
- GLint viewport[4];
- glSelectBuffer(100, m_SelectBuffer);
- glRenderMode(GL_SELECT);
- glInitNames();
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- GetClientRect( &rect);
- winH =(float)rect.bottom;
- winH =(winH == 0.0f) ? 1.0f : winH;
- glGetIntegerv(GL_VIEWPORT,viewport);
- gluPickMatrix(x, winH - y, 5, 5, viewport);
- glFrustum(-m_fViewWidth, m_fViewWidth,
- -m_fViewHeight, m_fViewHeight,
- m_fViewNear, m_fViewFar );
- gluLookAt(m_sEye.origin.x,m_sEye.origin.y,m_sEye.origin.z,
- m_sEye.center.x,m_sEye.center.y,m_sEye.center.z,
- m_sEye.up.x,m_sEye.up.y,m_sEye.up.z);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- DrawScene();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- int selecthit = glRenderMode(GL_RENDER);
- return selecthit;
- }
- int CBilliardsPlayView::GetSelectObjFront(int selecthits, unsigned int *name)
- {
- int i,j,result;
- GLuint mindepth;
- if (selecthits<=0)
- return -1;
- result=0;
- j=0;
- mindepth=0;
- mindepth=~mindepth;
- for (i=0;i<selecthits;i++)
- {
- if (m_SelectBuffer[j]<=0)
- {
- j=j+3+m_SelectBuffer[j];
- continue;
- }
- if (m_SelectBuffer[j+1]<mindepth)
- {
- mindepth=m_SelectBuffer[j+1];
- result=j;
- }
- j=j+3+m_SelectBuffer[j];
- }
- if (m_SelectBuffer[result]<=0)
- return -1;
- for (i=0;i<m_SelectBuffer[result];i++)
- name[i]=m_SelectBuffer[result+i+3];
- return m_SelectBuffer[result];
- }
- void CBilliardsPlayView::HitBall()
- {
- if (!m_bAnimate)
- {
- m_nEnter = 100;
- CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
- CBilliardsPlayView *pView = (CBilliardsPlayView *)(pFrame->m_wndSplitter).GetPane(0,1);
- CBilliardsDoc *pDoc = (CBilliardsDoc *)pView->GetDocument();
- if (pDoc->m_bPlayer!=IDLE)
- {
- m_nEnter = -1;
- if (m_bCanHit)
- pDoc->SendVelocity(m_fVelocity[0]);
- }
- m_bAnimate = TRUE;
- SetTimer(ANIMATE_TIMER,5,NULL);
- }
- }
- void CBilliardsPlayView::OnTimer(UINT nIDEvent)
- {
- CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
- CBilliardsPlayView *pView = (CBilliardsPlayView *)(pFrame->m_wndSplitter).GetPane(0,1);
- if (nIDEvent == ANIMATE_TIMER){
- DrawScene();
- //Invalidate();
- pView->GetDlgItem(IDC_BUTTON_SHOOT)->EnableWindow(m_bCanHit&&!m_bAnimate);
- }
- CView::OnTimer(nIDEvent);
- }