From c84df63fc265915e18cbacce8f4481969dbdcce5 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Thu, 19 Aug 2010 17:18:55 +0000 Subject: [PATCH] * fixed warnings in 3dmov git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38274 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/3dmov/ViewBook.cpp | 99 ++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/src/apps/3dmov/ViewBook.cpp b/src/apps/3dmov/ViewBook.cpp index 69875adba0..31b36c1678 100644 --- a/src/apps/3dmov/ViewBook.cpp +++ b/src/apps/3dmov/ViewBook.cpp @@ -4,10 +4,10 @@ DESCRIPTION: Haiku version of the famous BeInc demo 3Dmov The book has 4 pages with images, and the user can move pages 2/3. Texture management is really primitive - only the default image is - shared, while the other page images are unique instances. + shared, while the other page images are unique instances. */ -#include +#include #include #include @@ -42,18 +42,18 @@ public: }; Paper(float x_size, float y_size, ORIENTATION orientation, const int number_columns = 6, const int number_rows = 4); ~Paper(); - + void Render(); void SetMediaSource(TEXTURE_SIDE side, MediaSource *source); void SetAngle(float angle); - + private: ORIENTATION fOrientation; MediaSource *fFrontMediaSource; MediaSource *fBackMediaSource; float *fGeometry; float *fTextureCoords; - + int fNumberVertices; float fWidth, fHeight; int fNumberColumns, fNumberRows; @@ -82,12 +82,12 @@ Paper :: Paper(float x_size, float y_size, ORIENTATION orientation, const int nu fHeight = y_size; fNumberColumns = number_columns; fNumberRows = number_rows; - + fNumberVertices = (fNumberColumns*2+1)*fNumberRows + 1; fGeometry = new float [fNumberVertices*3]; fTextureCoords = new float [fNumberVertices * 2]; InitTextureCoordinates(); - + SetAngle(0); } @@ -115,7 +115,7 @@ void Paper :: SetMediaSource(TEXTURE_SIDE side, MediaSource *source) else fBackMediaSource = source; } - + /* FUNCTION: Paper :: SetAngle ARGUMENTS: angle 0 - paper is on left side of book 90 - paper is vertical @@ -138,32 +138,32 @@ void Paper :: Render() { glPushMatrix(); glTranslatef(-0.5f*fWidth, -0.5f*fHeight, 0); - + if ((fOrientation == FRONT_FACING) || (fOrientation == FRONT_AND_BACK_FACING)) { glColor4f(1,1,1,1); glBindTexture(GL_TEXTURE_2D, fFrontMediaSource->mTextureID); - + glTexCoordPointer(2, GL_FLOAT, 0, fTextureCoords); - glVertexPointer(3, GL_FLOAT, 0, fGeometry); + glVertexPointer(3, GL_FLOAT, 0, fGeometry); glDrawArrays(GL_TRIANGLE_STRIP, 0, fNumberVertices); } - + if ((fOrientation == BACK_FACING) || (fOrientation == FRONT_AND_BACK_FACING)) { glColor4f(1,1,1,1); glBindTexture(GL_TEXTURE_2D, fBackMediaSource->mTextureID); - + // Mirror texture coordinates glMatrixMode(GL_TEXTURE); glScalef(-1,1,1); - + glFrontFace(GL_CW); glTexCoordPointer(2, GL_FLOAT, 0, fTextureCoords); - glVertexPointer(3, GL_FLOAT, 0, fGeometry); + glVertexPointer(3, GL_FLOAT, 0, fGeometry); glDrawArrays(GL_TRIANGLE_STRIP, 0, fNumberVertices); glFrontFace(GL_CCW); - + // Restore texture mirroring glScalef(-1,1,1); glMatrixMode(GL_MODELVIEW); @@ -190,7 +190,7 @@ void Paper :: InitTextureCoordinates() { *p++ = (float)c/fNumberColumns; *p++ = 1 - (float)(r+1)/fNumberRows; - + *p++ = (float)(c+1)/fNumberColumns; *p++ = 1 - (float)(r+2)/fNumberRows; } @@ -198,7 +198,7 @@ void Paper :: InitTextureCoordinates() { *p++ = (float)c/fNumberColumns; *p++ = 1 - (float)(r+1)/fNumberRows; - + *p++ = (float)c/fNumberColumns; *p++ = 1 - (float)r/fNumberRows; } @@ -214,7 +214,7 @@ void Paper :: ModifyGeometry() { float *p = fGeometry; const float kPageConcaveHeight = 0.1f*fWidth; - + // Cache frequent calculations float ca = cosd(fAngle); float w = fWidth * sind(fAngle); @@ -272,7 +272,7 @@ ViewBook :: ViewBook(BRect frame) fMediaSources[i] = 0; for (int i=0; i < NUMBER_PAGES; i++) fPages[i] = 0; - + fMouseTracking = false; fPageAngle = kPageMaxAngle; } @@ -283,13 +283,13 @@ ViewBook :: ViewBook(BRect frame) DESCRIPTION: Destructor */ ViewBook :: ~ViewBook() -{ +{ for (int i=0; i < NUMBER_SOURCES; i++) { if (fMediaSources[i] != GetDefaultMediaSource()) delete fMediaSources[i]; } - + for (int i=0; i < NUMBER_PAGES; i++) delete fPages[i]; } @@ -302,18 +302,17 @@ ViewBook :: ~ViewBook() void ViewBook :: AttachedToWindow(void) { ViewObject::AttachedToWindow(); - + LockGL(); glClearColor(0,0,0,1); - + fPages[PAGE_MIDDLE] = new Paper(kPageWidth, kPageHeight, Paper::FRONT_AND_BACK_FACING); fPages[PAGE_LEFT] = new Paper(kPageWidth, kPageHeight, Paper::FRONT_FACING); fPages[PAGE_RIGHT] = new Paper(kPageWidth, kPageHeight, Paper::BACK_FACING); - + for (int i=0; i < NUMBER_SOURCES; i++) fMediaSources[i] = GetDefaultMediaSource(); - - MediaSource *default_source = GetDefaultMediaSource(); + // left page fPages[PAGE_LEFT]->SetMediaSource(Paper::FRONT_TEXTURE, fMediaSources[0]); // middle page @@ -322,23 +321,23 @@ void ViewBook :: AttachedToWindow(void) // right page fPages[PAGE_RIGHT]->SetMediaSource(Paper::BACK_TEXTURE, fMediaSources[3]); fPages[PAGE_RIGHT]->SetAngle(180); - + UnlockGL(); -} +} /* FUNCTION: ViewBook :: Render ARGUMENTS: none RETURN: n/a - DESCRIPTION: Draw view contents + DESCRIPTION: Draw view contents */ void ViewBook :: Render(void) { LockGL(); - + bigtime_t current_time = real_time_clock_usecs(); - bigtime_t delta = current_time - fStartTime; + bigtime_t delta = current_time - fStartTime; fStartTime = current_time; - + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // page freefall (gravity) @@ -350,27 +349,27 @@ void ViewBook :: Render(void) fPageAngle += 30*(float)delta/1000000.0f; } fPages[PAGE_MIDDLE]->SetAngle(fPageAngle); - + // Draw pages glPushMatrix(); glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0); fPages[PAGE_MIDDLE]->Render(); glPopMatrix(); - + glPushMatrix(); glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0); fPages[PAGE_LEFT]->Render(); glPopMatrix(); - + glPushMatrix(); glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0); fPages[PAGE_RIGHT]->Render(); glPopMatrix(); - - + + glFlush(); SwapBuffers(); - + // Frame rate /* static int fps = 0; @@ -390,16 +389,16 @@ void ViewBook :: Render(void) /* FUNCTION: ViewBook :: MouseDown ARGUMENTS: p RETURN: n/a - DESCRIPTION: Hook function called when mouse down detected + DESCRIPTION: Hook function called when mouse down detected */ void ViewBook :: MouseDown(BPoint p) { // Determine mouse button BMessage* msg = Window()->CurrentMessage(); uint32 buttons; - + msg->FindInt32("buttons", (int32*)&buttons); - + if (buttons & B_PRIMARY_MOUSE_BUTTON) { Paper::TEXTURE_SIDE side = Paper::UNASSIGNED_TEXTURE; @@ -417,7 +416,7 @@ void ViewBook :: MouseDown(BPoint p) transit message RETURN: n/a - DESCRIPTION: Hook function called when mouse move detected + DESCRIPTION: Hook function called when mouse move detected */ void ViewBook :: MouseMoved(BPoint p, uint32 transit, const BMessage *message) { @@ -438,7 +437,7 @@ void ViewBook :: MouseMoved(BPoint p, uint32 transit, const BMessage *message) /* FUNCTION: ViewBook :: MouseUp ARGUMENTS: p RETURN: n/a - DESCRIPTION: Hook function called when mouse up detected + DESCRIPTION: Hook function called when mouse up detected */ void ViewBook :: MouseUp(BPoint p) { @@ -449,13 +448,13 @@ void ViewBook :: MouseUp(BPoint p) ARGUMENTS: mouse_x mouse_y RETURN: page corresponding to mouse_x, mouse_y - DESCRIPTION: Determine which page does mouse_x/mouse_y correspond to + DESCRIPTION: Determine which page does mouse_x/mouse_y correspond to */ Paper * ViewBook :: GetPage(float mouse_x, float mouse_y, int *side) { BRect frame = Bounds(); Paper *page = 0; - + if (fPageAngle > 90) { if (mouse_x < 0.5f*frame.Width()) @@ -490,13 +489,13 @@ Paper * ViewBook :: GetPage(float mouse_x, float mouse_y, int *side) mouse_x mouse_y RETURN: true if source ownership acquired - DESCRIPTION: Hook function called when user drags/drops image to app window + DESCRIPTION: Hook function called when user drags/drops image to app window */ bool ViewBook :: SurfaceUpdate(MediaSource *source, float mouse_x, float mouse_y) { Paper::TEXTURE_SIDE side = Paper::UNASSIGNED_TEXTURE; Paper *page = GetPage(mouse_x, mouse_y, (int *)&side); - + LockGL(); int index = -1; if (page == fPages[PAGE_LEFT]) @@ -514,11 +513,11 @@ bool ViewBook :: SurfaceUpdate(MediaSource *source, float mouse_x, float mouse_y { if (fMediaSources[index] != GetDefaultMediaSource()) delete fMediaSources[index]; - } + } page->SetMediaSource(side, source); fMediaSources[index] = source; UnlockGL(); - + return true; }