* fixed warnings in 3dmov
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38274 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+49
-50
@@ -4,10 +4,10 @@
|
|||||||
DESCRIPTION: Haiku version of the famous BeInc demo 3Dmov
|
DESCRIPTION: Haiku version of the famous BeInc demo 3Dmov
|
||||||
The book has 4 pages with images, and the user can move pages 2/3.
|
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
|
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 <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
@@ -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(float x_size, float y_size, ORIENTATION orientation, const int number_columns = 6, const int number_rows = 4);
|
||||||
~Paper();
|
~Paper();
|
||||||
|
|
||||||
void Render();
|
void Render();
|
||||||
void SetMediaSource(TEXTURE_SIDE side, MediaSource *source);
|
void SetMediaSource(TEXTURE_SIDE side, MediaSource *source);
|
||||||
void SetAngle(float angle);
|
void SetAngle(float angle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ORIENTATION fOrientation;
|
ORIENTATION fOrientation;
|
||||||
MediaSource *fFrontMediaSource;
|
MediaSource *fFrontMediaSource;
|
||||||
MediaSource *fBackMediaSource;
|
MediaSource *fBackMediaSource;
|
||||||
float *fGeometry;
|
float *fGeometry;
|
||||||
float *fTextureCoords;
|
float *fTextureCoords;
|
||||||
|
|
||||||
int fNumberVertices;
|
int fNumberVertices;
|
||||||
float fWidth, fHeight;
|
float fWidth, fHeight;
|
||||||
int fNumberColumns, fNumberRows;
|
int fNumberColumns, fNumberRows;
|
||||||
@@ -82,12 +82,12 @@ Paper :: Paper(float x_size, float y_size, ORIENTATION orientation, const int nu
|
|||||||
fHeight = y_size;
|
fHeight = y_size;
|
||||||
fNumberColumns = number_columns;
|
fNumberColumns = number_columns;
|
||||||
fNumberRows = number_rows;
|
fNumberRows = number_rows;
|
||||||
|
|
||||||
fNumberVertices = (fNumberColumns*2+1)*fNumberRows + 1;
|
fNumberVertices = (fNumberColumns*2+1)*fNumberRows + 1;
|
||||||
fGeometry = new float [fNumberVertices*3];
|
fGeometry = new float [fNumberVertices*3];
|
||||||
fTextureCoords = new float [fNumberVertices * 2];
|
fTextureCoords = new float [fNumberVertices * 2];
|
||||||
InitTextureCoordinates();
|
InitTextureCoordinates();
|
||||||
|
|
||||||
SetAngle(0);
|
SetAngle(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ void Paper :: SetMediaSource(TEXTURE_SIDE side, MediaSource *source)
|
|||||||
else
|
else
|
||||||
fBackMediaSource = source;
|
fBackMediaSource = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FUNCTION: Paper :: SetAngle
|
/* FUNCTION: Paper :: SetAngle
|
||||||
ARGUMENTS: angle 0 - paper is on left side of book
|
ARGUMENTS: angle 0 - paper is on left side of book
|
||||||
90 - paper is vertical
|
90 - paper is vertical
|
||||||
@@ -138,32 +138,32 @@ void Paper :: Render()
|
|||||||
{
|
{
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(-0.5f*fWidth, -0.5f*fHeight, 0);
|
glTranslatef(-0.5f*fWidth, -0.5f*fHeight, 0);
|
||||||
|
|
||||||
if ((fOrientation == FRONT_FACING) || (fOrientation == FRONT_AND_BACK_FACING))
|
if ((fOrientation == FRONT_FACING) || (fOrientation == FRONT_AND_BACK_FACING))
|
||||||
{
|
{
|
||||||
glColor4f(1,1,1,1);
|
glColor4f(1,1,1,1);
|
||||||
glBindTexture(GL_TEXTURE_2D, fFrontMediaSource->mTextureID);
|
glBindTexture(GL_TEXTURE_2D, fFrontMediaSource->mTextureID);
|
||||||
|
|
||||||
glTexCoordPointer(2, GL_FLOAT, 0, fTextureCoords);
|
glTexCoordPointer(2, GL_FLOAT, 0, fTextureCoords);
|
||||||
glVertexPointer(3, GL_FLOAT, 0, fGeometry);
|
glVertexPointer(3, GL_FLOAT, 0, fGeometry);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, fNumberVertices);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, fNumberVertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fOrientation == BACK_FACING) || (fOrientation == FRONT_AND_BACK_FACING))
|
if ((fOrientation == BACK_FACING) || (fOrientation == FRONT_AND_BACK_FACING))
|
||||||
{
|
{
|
||||||
glColor4f(1,1,1,1);
|
glColor4f(1,1,1,1);
|
||||||
glBindTexture(GL_TEXTURE_2D, fBackMediaSource->mTextureID);
|
glBindTexture(GL_TEXTURE_2D, fBackMediaSource->mTextureID);
|
||||||
|
|
||||||
// Mirror texture coordinates
|
// Mirror texture coordinates
|
||||||
glMatrixMode(GL_TEXTURE);
|
glMatrixMode(GL_TEXTURE);
|
||||||
glScalef(-1,1,1);
|
glScalef(-1,1,1);
|
||||||
|
|
||||||
glFrontFace(GL_CW);
|
glFrontFace(GL_CW);
|
||||||
glTexCoordPointer(2, GL_FLOAT, 0, fTextureCoords);
|
glTexCoordPointer(2, GL_FLOAT, 0, fTextureCoords);
|
||||||
glVertexPointer(3, GL_FLOAT, 0, fGeometry);
|
glVertexPointer(3, GL_FLOAT, 0, fGeometry);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, fNumberVertices);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, fNumberVertices);
|
||||||
glFrontFace(GL_CCW);
|
glFrontFace(GL_CCW);
|
||||||
|
|
||||||
// Restore texture mirroring
|
// Restore texture mirroring
|
||||||
glScalef(-1,1,1);
|
glScalef(-1,1,1);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
@@ -190,7 +190,7 @@ void Paper :: InitTextureCoordinates()
|
|||||||
{
|
{
|
||||||
*p++ = (float)c/fNumberColumns;
|
*p++ = (float)c/fNumberColumns;
|
||||||
*p++ = 1 - (float)(r+1)/fNumberRows;
|
*p++ = 1 - (float)(r+1)/fNumberRows;
|
||||||
|
|
||||||
*p++ = (float)(c+1)/fNumberColumns;
|
*p++ = (float)(c+1)/fNumberColumns;
|
||||||
*p++ = 1 - (float)(r+2)/fNumberRows;
|
*p++ = 1 - (float)(r+2)/fNumberRows;
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ void Paper :: InitTextureCoordinates()
|
|||||||
{
|
{
|
||||||
*p++ = (float)c/fNumberColumns;
|
*p++ = (float)c/fNumberColumns;
|
||||||
*p++ = 1 - (float)(r+1)/fNumberRows;
|
*p++ = 1 - (float)(r+1)/fNumberRows;
|
||||||
|
|
||||||
*p++ = (float)c/fNumberColumns;
|
*p++ = (float)c/fNumberColumns;
|
||||||
*p++ = 1 - (float)r/fNumberRows;
|
*p++ = 1 - (float)r/fNumberRows;
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,7 @@ void Paper :: ModifyGeometry()
|
|||||||
{
|
{
|
||||||
float *p = fGeometry;
|
float *p = fGeometry;
|
||||||
const float kPageConcaveHeight = 0.1f*fWidth;
|
const float kPageConcaveHeight = 0.1f*fWidth;
|
||||||
|
|
||||||
// Cache frequent calculations
|
// Cache frequent calculations
|
||||||
float ca = cosd(fAngle);
|
float ca = cosd(fAngle);
|
||||||
float w = fWidth * sind(fAngle);
|
float w = fWidth * sind(fAngle);
|
||||||
@@ -272,7 +272,7 @@ ViewBook :: ViewBook(BRect frame)
|
|||||||
fMediaSources[i] = 0;
|
fMediaSources[i] = 0;
|
||||||
for (int i=0; i < NUMBER_PAGES; i++)
|
for (int i=0; i < NUMBER_PAGES; i++)
|
||||||
fPages[i] = 0;
|
fPages[i] = 0;
|
||||||
|
|
||||||
fMouseTracking = false;
|
fMouseTracking = false;
|
||||||
fPageAngle = kPageMaxAngle;
|
fPageAngle = kPageMaxAngle;
|
||||||
}
|
}
|
||||||
@@ -283,13 +283,13 @@ ViewBook :: ViewBook(BRect frame)
|
|||||||
DESCRIPTION: Destructor
|
DESCRIPTION: Destructor
|
||||||
*/
|
*/
|
||||||
ViewBook :: ~ViewBook()
|
ViewBook :: ~ViewBook()
|
||||||
{
|
{
|
||||||
for (int i=0; i < NUMBER_SOURCES; i++)
|
for (int i=0; i < NUMBER_SOURCES; i++)
|
||||||
{
|
{
|
||||||
if (fMediaSources[i] != GetDefaultMediaSource())
|
if (fMediaSources[i] != GetDefaultMediaSource())
|
||||||
delete fMediaSources[i];
|
delete fMediaSources[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i < NUMBER_PAGES; i++)
|
for (int i=0; i < NUMBER_PAGES; i++)
|
||||||
delete fPages[i];
|
delete fPages[i];
|
||||||
}
|
}
|
||||||
@@ -302,18 +302,17 @@ ViewBook :: ~ViewBook()
|
|||||||
void ViewBook :: AttachedToWindow(void)
|
void ViewBook :: AttachedToWindow(void)
|
||||||
{
|
{
|
||||||
ViewObject::AttachedToWindow();
|
ViewObject::AttachedToWindow();
|
||||||
|
|
||||||
LockGL();
|
LockGL();
|
||||||
glClearColor(0,0,0,1);
|
glClearColor(0,0,0,1);
|
||||||
|
|
||||||
fPages[PAGE_MIDDLE] = new Paper(kPageWidth, kPageHeight, Paper::FRONT_AND_BACK_FACING);
|
fPages[PAGE_MIDDLE] = new Paper(kPageWidth, kPageHeight, Paper::FRONT_AND_BACK_FACING);
|
||||||
fPages[PAGE_LEFT] = new Paper(kPageWidth, kPageHeight, Paper::FRONT_FACING);
|
fPages[PAGE_LEFT] = new Paper(kPageWidth, kPageHeight, Paper::FRONT_FACING);
|
||||||
fPages[PAGE_RIGHT] = new Paper(kPageWidth, kPageHeight, Paper::BACK_FACING);
|
fPages[PAGE_RIGHT] = new Paper(kPageWidth, kPageHeight, Paper::BACK_FACING);
|
||||||
|
|
||||||
for (int i=0; i < NUMBER_SOURCES; i++)
|
for (int i=0; i < NUMBER_SOURCES; i++)
|
||||||
fMediaSources[i] = GetDefaultMediaSource();
|
fMediaSources[i] = GetDefaultMediaSource();
|
||||||
|
|
||||||
MediaSource *default_source = GetDefaultMediaSource();
|
|
||||||
// left page
|
// left page
|
||||||
fPages[PAGE_LEFT]->SetMediaSource(Paper::FRONT_TEXTURE, fMediaSources[0]);
|
fPages[PAGE_LEFT]->SetMediaSource(Paper::FRONT_TEXTURE, fMediaSources[0]);
|
||||||
// middle page
|
// middle page
|
||||||
@@ -322,23 +321,23 @@ void ViewBook :: AttachedToWindow(void)
|
|||||||
// right page
|
// right page
|
||||||
fPages[PAGE_RIGHT]->SetMediaSource(Paper::BACK_TEXTURE, fMediaSources[3]);
|
fPages[PAGE_RIGHT]->SetMediaSource(Paper::BACK_TEXTURE, fMediaSources[3]);
|
||||||
fPages[PAGE_RIGHT]->SetAngle(180);
|
fPages[PAGE_RIGHT]->SetAngle(180);
|
||||||
|
|
||||||
UnlockGL();
|
UnlockGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FUNCTION: ViewBook :: Render
|
/* FUNCTION: ViewBook :: Render
|
||||||
ARGUMENTS: none
|
ARGUMENTS: none
|
||||||
RETURN: n/a
|
RETURN: n/a
|
||||||
DESCRIPTION: Draw view contents
|
DESCRIPTION: Draw view contents
|
||||||
*/
|
*/
|
||||||
void ViewBook :: Render(void)
|
void ViewBook :: Render(void)
|
||||||
{
|
{
|
||||||
LockGL();
|
LockGL();
|
||||||
|
|
||||||
bigtime_t current_time = real_time_clock_usecs();
|
bigtime_t current_time = real_time_clock_usecs();
|
||||||
bigtime_t delta = current_time - fStartTime;
|
bigtime_t delta = current_time - fStartTime;
|
||||||
fStartTime = current_time;
|
fStartTime = current_time;
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// page freefall (gravity)
|
// page freefall (gravity)
|
||||||
@@ -350,27 +349,27 @@ void ViewBook :: Render(void)
|
|||||||
fPageAngle += 30*(float)delta/1000000.0f;
|
fPageAngle += 30*(float)delta/1000000.0f;
|
||||||
}
|
}
|
||||||
fPages[PAGE_MIDDLE]->SetAngle(fPageAngle);
|
fPages[PAGE_MIDDLE]->SetAngle(fPageAngle);
|
||||||
|
|
||||||
// Draw pages
|
// Draw pages
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0);
|
glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0);
|
||||||
fPages[PAGE_MIDDLE]->Render();
|
fPages[PAGE_MIDDLE]->Render();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0);
|
glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0);
|
||||||
fPages[PAGE_LEFT]->Render();
|
fPages[PAGE_LEFT]->Render();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0);
|
glTranslatef(-0.5f*kPageWidth, 0.5f*kPageHeight, 0);
|
||||||
fPages[PAGE_RIGHT]->Render();
|
fPages[PAGE_RIGHT]->Render();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
|
||||||
glFlush();
|
glFlush();
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
|
|
||||||
// Frame rate
|
// Frame rate
|
||||||
/*
|
/*
|
||||||
static int fps = 0;
|
static int fps = 0;
|
||||||
@@ -390,16 +389,16 @@ void ViewBook :: Render(void)
|
|||||||
/* FUNCTION: ViewBook :: MouseDown
|
/* FUNCTION: ViewBook :: MouseDown
|
||||||
ARGUMENTS: p
|
ARGUMENTS: p
|
||||||
RETURN: n/a
|
RETURN: n/a
|
||||||
DESCRIPTION: Hook function called when mouse down detected
|
DESCRIPTION: Hook function called when mouse down detected
|
||||||
*/
|
*/
|
||||||
void ViewBook :: MouseDown(BPoint p)
|
void ViewBook :: MouseDown(BPoint p)
|
||||||
{
|
{
|
||||||
// Determine mouse button
|
// Determine mouse button
|
||||||
BMessage* msg = Window()->CurrentMessage();
|
BMessage* msg = Window()->CurrentMessage();
|
||||||
uint32 buttons;
|
uint32 buttons;
|
||||||
|
|
||||||
msg->FindInt32("buttons", (int32*)&buttons);
|
msg->FindInt32("buttons", (int32*)&buttons);
|
||||||
|
|
||||||
if (buttons & B_PRIMARY_MOUSE_BUTTON)
|
if (buttons & B_PRIMARY_MOUSE_BUTTON)
|
||||||
{
|
{
|
||||||
Paper::TEXTURE_SIDE side = Paper::UNASSIGNED_TEXTURE;
|
Paper::TEXTURE_SIDE side = Paper::UNASSIGNED_TEXTURE;
|
||||||
@@ -417,7 +416,7 @@ void ViewBook :: MouseDown(BPoint p)
|
|||||||
transit
|
transit
|
||||||
message
|
message
|
||||||
RETURN: n/a
|
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)
|
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
|
/* FUNCTION: ViewBook :: MouseUp
|
||||||
ARGUMENTS: p
|
ARGUMENTS: p
|
||||||
RETURN: n/a
|
RETURN: n/a
|
||||||
DESCRIPTION: Hook function called when mouse up detected
|
DESCRIPTION: Hook function called when mouse up detected
|
||||||
*/
|
*/
|
||||||
void ViewBook :: MouseUp(BPoint p)
|
void ViewBook :: MouseUp(BPoint p)
|
||||||
{
|
{
|
||||||
@@ -449,13 +448,13 @@ void ViewBook :: MouseUp(BPoint p)
|
|||||||
ARGUMENTS: mouse_x
|
ARGUMENTS: mouse_x
|
||||||
mouse_y
|
mouse_y
|
||||||
RETURN: page corresponding to 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)
|
Paper * ViewBook :: GetPage(float mouse_x, float mouse_y, int *side)
|
||||||
{
|
{
|
||||||
BRect frame = Bounds();
|
BRect frame = Bounds();
|
||||||
Paper *page = 0;
|
Paper *page = 0;
|
||||||
|
|
||||||
if (fPageAngle > 90)
|
if (fPageAngle > 90)
|
||||||
{
|
{
|
||||||
if (mouse_x < 0.5f*frame.Width())
|
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_x
|
||||||
mouse_y
|
mouse_y
|
||||||
RETURN: true if source ownership acquired
|
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)
|
bool ViewBook :: SurfaceUpdate(MediaSource *source, float mouse_x, float mouse_y)
|
||||||
{
|
{
|
||||||
Paper::TEXTURE_SIDE side = Paper::UNASSIGNED_TEXTURE;
|
Paper::TEXTURE_SIDE side = Paper::UNASSIGNED_TEXTURE;
|
||||||
Paper *page = GetPage(mouse_x, mouse_y, (int *)&side);
|
Paper *page = GetPage(mouse_x, mouse_y, (int *)&side);
|
||||||
|
|
||||||
LockGL();
|
LockGL();
|
||||||
int index = -1;
|
int index = -1;
|
||||||
if (page == fPages[PAGE_LEFT])
|
if (page == fPages[PAGE_LEFT])
|
||||||
@@ -514,11 +513,11 @@ bool ViewBook :: SurfaceUpdate(MediaSource *source, float mouse_x, float mouse_y
|
|||||||
{
|
{
|
||||||
if (fMediaSources[index] != GetDefaultMediaSource())
|
if (fMediaSources[index] != GetDefaultMediaSource())
|
||||||
delete fMediaSources[index];
|
delete fMediaSources[index];
|
||||||
}
|
}
|
||||||
page->SetMediaSource(side, source);
|
page->SetMediaSource(side, source);
|
||||||
fMediaSources[index] = source;
|
fMediaSources[index] = source;
|
||||||
UnlockGL();
|
UnlockGL();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user