Some style cleanups by Fredrik Ekdahl. Thanks!

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22013 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-08-19 20:14:48 +00:00
parent 0e5fe45f13
commit be98a6028d
12 changed files with 426 additions and 355 deletions
+1 -3
View File
@@ -5,8 +5,7 @@
#include <GL/gl.h>
class FPS
{
class FPS {
public:
FPS();
~FPS();
@@ -15,6 +14,5 @@ public:
private:
static void drawChar(GLfloat x, GLfloat y, GLint number);
};
+33 -21
View File
@@ -3,22 +3,17 @@
This file may be used under the terms of the Be Sample Code License.
*/
#include <stdlib.h>
#include <GL/gl.h>
#include <InterfaceKit.h>
#include "GLObject.h"
#include <GL/gl.h>
#include <stdlib.h>
#include <InterfaceKit.h>
#include "glob.h"
struct material {
float ambient[3], diffuse[3], specular[3];
};
float *colors[] =
{
NULL,white,yellow,blue,red,green
};
float *colors[] = {NULL, white, yellow, blue, red, green};
material materials[] = {
// Null
@@ -63,23 +58,32 @@ material materials[] = {
extern long setEvent(sem_id event);
GLObject::GLObject(ObjectView *ov)
: rotX(0),
rotY(0),
lastRotX(0),
lastRotY(0),
spinX(2),
spinY(2),
x(0),
y(0),
z(-2.0),
color(4),
solidity(0),
changed(false),
objView(ov)
{
rotX = rotY = lastRotX = lastRotY = 0;
spinX = spinY = 2;
x = y = 0;
z = -2.0;
color = 4;
solidity = 0;
changed = false;
objView = ov;
};
GLObject::~GLObject()
{
};
void GLObject::MenuInvoked(BPoint point)
void
GLObject::MenuInvoked(BPoint point)
{
BPopUpMenu *m = new BPopUpMenu("Object",false,false);
BMenuItem *i;
@@ -126,7 +130,9 @@ void GLObject::MenuInvoked(BPoint point)
setEvent(objView->drawEvent);
};
bool GLObject::SpinIt()
bool
GLObject::SpinIt()
{
rotX += spinX;
rotY += spinY;
@@ -138,7 +144,9 @@ bool GLObject::SpinIt()
return c;
};
void GLObject::Draw(bool forID, float IDcolor[])
void
GLObject::Draw(bool forID, float IDcolor[])
{
glPushMatrix();
glTranslatef(x, y, z);
@@ -156,6 +164,7 @@ void GLObject::Draw(bool forID, float IDcolor[])
changed = false;
};
TriangleObject::TriangleObject(ObjectView *ov, char *filename)
: GLObject(ov),
points(100,100),
@@ -247,6 +256,7 @@ TriangleObject::TriangleObject(ObjectView *ov, char *filename)
fclose(f);
};
TriangleObject::~TriangleObject()
{
for (int i=0;i<qs.num_items;i++) {
@@ -254,7 +264,9 @@ TriangleObject::~TriangleObject()
};
};
void TriangleObject::DoDrawing(bool forID)
void
TriangleObject::DoDrawing(bool forID)
{
if (!forID) {
float c[3][4];
+16 -13
View File
@@ -2,8 +2,11 @@
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef GL_OBJECT_H
#define GL_OBJECT_H
#include "ObjectView.h"
#include "util.h"
struct point {
float x,y,z;
@@ -20,35 +23,35 @@ struct quadStrip {
int *pts;
};
#include "util.h"
class GLObject {
public:
float rotX,rotY,spinX,spinY,lastRotX,lastRotY;
float x,y,z;
int color;
int solidity;
bool changed;
ObjectView * objView;
GLObject(ObjectView *ov);
virtual ~GLObject();
virtual void Draw(bool forID, float IDcolor[]);
virtual bool SpinIt();
virtual void MenuInvoked(BPoint point);
virtual void DoDrawing(bool forID) {};
float rotX,rotY,spinX,spinY,lastRotX,lastRotY;
float x,y,z;
int color;
int solidity;
bool changed;
ObjectView * objView;
};
class TriangleObject : public GLObject {
public:
BufferArray<point> points;
BufferArray<tri> triangles;
BufferArray<quadStrip> qs;
TriangleObject(ObjectView *ov, char *filename);
virtual ~TriangleObject();
virtual void DoDrawing(bool forID);
BufferArray<point> points;
BufferArray<tri> triangles;
BufferArray<quadStrip> qs;
};
#endif // GL_OBJECT_H
+60 -26
View File
@@ -3,16 +3,17 @@
This file may be used under the terms of the Be Sample Code License.
*/
#include "ObjectView.h"
#include <stdio.h>
#include <stdlib.h>
#include <InterfaceKit.h>
#include <FindDirectory.h>
#include "ObjectView.h"
#include "ResScroll.h"
#include "GLObject.h"
#include "FPS.h"
#include "GLObject.h"
#include "ResScroll.h"
#define teapotData "teapot.data"
char teapotPath[PATH_MAX];
@@ -35,12 +36,14 @@ float red[3] = {1.0,0.0,0.0};
float *bgColor = black;
struct light {
float *ambient;
float *diffuse;
float *specular;
};
light lights[] = {
{NULL, NULL, NULL},
{dimWhite, white, white},
@@ -50,17 +53,9 @@ light lights[] = {
{dimWhite, green, green}
};
long signalEvent(sem_id event)
{
long c;
get_sem_count(event,&c);
if (c<0)
release_sem_etc(event,-c,0);
return 0;
};
long setEvent(sem_id event)
long
signalEvent(sem_id event)
{
long c;
get_sem_count(event,&c);
@@ -71,7 +66,20 @@ long setEvent(sem_id event)
};
long waitEvent(sem_id event)
long
setEvent(sem_id event)
{
long c;
get_sem_count(event,&c);
if (c<0)
release_sem_etc(event,-c,0);
return 0;
};
long
waitEvent(sem_id event)
{
acquire_sem(event);
@@ -83,7 +91,9 @@ long waitEvent(sem_id event)
return 0;
};
long simonThread(ObjectView *ov)
long
simonThread(ObjectView *ov)
{
int noPause=0;
while (acquire_sem_etc(ov->quittingSem,1,B_TIMEOUT,0) == B_NO_ERROR) {
@@ -101,6 +111,7 @@ long simonThread(ObjectView *ov)
return 0;
};
ObjectView::ObjectView(BRect r, char *name, ulong resizingMode, ulong options)
: BGLView(r,name,resizingMode,0,options)
{
@@ -130,13 +141,16 @@ ObjectView::ObjectView(BRect r, char *name, ulong resizingMode, ulong options)
objListLock.Unlock();
};
ObjectView::~ObjectView()
{
delete_sem(quittingSem);
delete_sem(drawEvent);
};
void ObjectView::AttachedToWindow()
void
ObjectView::AttachedToWindow()
{
float position[] = {0.0, 3.0, 3.0, 0.0};
float position1[] = {-3.0, -3.0, 3.0, 0.0};
@@ -204,7 +218,9 @@ void ObjectView::AttachedToWindow()
setEvent(drawEvent);
};
void ObjectView::DetachedFromWindow()
void
ObjectView::DetachedFromWindow()
{
BGLView::DetachedFromWindow();
@@ -224,7 +240,9 @@ void ObjectView::DetachedFromWindow()
while (locks--) Window()->Lock();
};
void ObjectView::Pulse()
void
ObjectView::Pulse()
{
Window()->Lock();
BRect p = Parent()->Bounds();
@@ -237,7 +255,9 @@ void ObjectView::Pulse()
Window()->Unlock();
};
void ObjectView::MessageReceived(BMessage *msg)
void
ObjectView::MessageReceived(BMessage *msg)
{
BMenuItem *i;
bool *b;
@@ -320,7 +340,9 @@ void ObjectView::MessageReceived(BMessage *msg)
};
};
int ObjectView::ObjectAtPoint(BPoint p)
int
ObjectView::ObjectAtPoint(BPoint p)
{
LockGL();
glShadeModel(GL_FLAT);
@@ -347,7 +369,9 @@ int ObjectView::ObjectAtPoint(BPoint p)
return objNum;
};
void ObjectView::MouseDown(BPoint p)
void
ObjectView::MouseDown(BPoint p)
{
BPoint op=p,np=p;
BRect bounds = Bounds();
@@ -441,7 +465,9 @@ void ObjectView::MouseDown(BPoint p)
setEvent(drawEvent);
};
void ObjectView::FrameResized(float w, float h)
void
ObjectView::FrameResized(float w, float h)
{
LockGL();
@@ -481,7 +507,9 @@ void ObjectView::FrameResized(float w, float h)
setEvent(drawEvent);
}
bool ObjectView::RepositionView()
bool
ObjectView::RepositionView()
{
if (!(persp != lastPersp) &&
!(lastObjectDistance != objectDistance) &&
@@ -516,7 +544,9 @@ bool ObjectView::RepositionView()
return true;
};
void ObjectView::EnforceState()
void
ObjectView::EnforceState()
{
glShadeModel(gouraud?GL_SMOOTH:GL_FLAT);
if (zbuf) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
@@ -542,7 +572,9 @@ void ObjectView::EnforceState()
};
};
bool ObjectView::SpinIt()
bool
ObjectView::SpinIt()
{
bool changed = false;
@@ -615,7 +647,9 @@ bool ObjectView::SpinIt()
return changed;
};
void ObjectView::DrawFrame(bool noPause)
void
ObjectView::DrawFrame(bool noPause)
{
LockGL();
glClear(GL_COLOR_BUFFER_BIT|(zbuf?GL_DEPTH_BUFFER_BIT:0));
+20 -18
View File
@@ -3,8 +3,8 @@
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef ObjectView_h
#define ObjectView_h
#ifndef OBJECT_VIEW_H
#define OBJECT_VIEW_H
#include <GL/glu.h>
#include <GLView.h>
@@ -33,8 +33,25 @@ enum lights {
#define HISTSIZE 10
class ResScroll;
class ObjectView : public BGLView {
public:
ObjectView(BRect r, char *name,
ulong resizingMode, ulong options);
~ObjectView();
virtual void MouseDown(BPoint p);
virtual void MessageReceived(BMessage *msg);
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void FrameResized(float width, float height);
bool SpinIt();
int ObjectAtPoint(BPoint p);
virtual void DrawFrame(bool noPause);
virtual void Pulse();
void EnforceState();
bool RepositionView();
sem_id drawEvent;
sem_id quittingSem;
thread_id drawThread;
@@ -59,21 +76,6 @@ bool lastFog,fog;
bool forceRedraw;
float objectDistance,lastObjectDistance;
ObjectView(BRect r, char *name,
ulong resizingMode, ulong options);
~ObjectView();
virtual void MouseDown(BPoint p);
virtual void MessageReceived(BMessage *msg);
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void FrameResized(float width, float height);
bool SpinIt();
int ObjectAtPoint(BPoint p);
virtual void DrawFrame(bool noPause);
virtual void Pulse();
void EnforceState();
bool RepositionView();
};
#endif
#endif // OBJECT_VIEW_H
+2 -3
View File
@@ -3,8 +3,8 @@
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef ResScroll_h
#define ResScroll_h
#ifndef RESSCROLL_H
#define RESSCROLL_H
#include <interface/ScrollBar.h>
@@ -17,7 +17,6 @@ public:
ResScroll(BRect r, const char *name,
ObjectView *target, orientation posture);
virtual void ValueChanged(float value);
};
#endif
+2 -1
View File
@@ -5,7 +5,8 @@
#include "error.h"
void fatalerror(char *s)
void
fatalerror(char *s)
{
printf("FATAL ERROR: %s\n",s);
};
+3 -3
View File
@@ -3,8 +3,8 @@
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef error_h
#define error_h
#ifndef ERROR_H
#define ERROR_H
#include <stdio.h>
@@ -28,4 +28,4 @@ extern void fatalerror(char *);
#endif //DEBUGGING
#endif
#endif // ERROR_H
+1 -1
View File
@@ -3,7 +3,7 @@
This file may be used under the terms of the Be Sample Code License.
*/
#include "GL/gl.h"
#include <GL/gl.h>
void auxSolidTeapot(GLdouble scale);
void auxWireTeapot(GLdouble scale);
+13 -7
View File
@@ -3,27 +3,29 @@
This file may be used under the terms of the Be Sample Code License.
*/
#include <InterfaceKit.h>
#include <stdio.h>
#include <InterfaceKit.h>
#include "ObjectView.h"
class QuitWindow : public BDirectWindow
{
class QuitWindow : public BDirectWindow {
public:
QuitWindow(BRect r, char *name, window_type wt, ulong something);
virtual bool QuitRequested();
virtual void DirectConnected( direct_buffer_info *info );
ObjectView *bgl;
ObjectView *bgl;
};
QuitWindow::QuitWindow(BRect r, char *name, window_type wt, ulong something)
: BDirectWindow(r,name,wt,something)
{
}
bool QuitWindow::QuitRequested()
bool
QuitWindow::QuitRequested()
{
printf("closing \n");
bgl->EnableDirectMode( false );
@@ -31,14 +33,18 @@ printf( "closing \n" );
return true;
};
void QuitWindow::DirectConnected( direct_buffer_info *info )
void
QuitWindow::DirectConnected(direct_buffer_info *info)
{
if (bgl)
bgl->DirectConnected( info );
bgl->EnableDirectMode( true );
}
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
GLenum type = BGL_RGB | BGL_DEPTH | BGL_DOUBLE;
//GLenum type = BGL_RGB | BGL_DEPTH | BGL_SINGLE;
+37 -21
View File
@@ -3,15 +3,14 @@
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef list_h
#define list_h
#ifndef UTIL_H
#define UTIL_H
#include <memory.h>
#include "error.h"
template <class contents>
struct LispNode
{
struct LispNode {
contents *car;
LispNode *cdr;
@@ -31,27 +30,34 @@ struct LispNode
template <class contents>
struct LispList
{
struct LispList {
LispNode<contents> *first;
/* -------- List creation --------------- */
/* Create an empty list */
inline LispList()
{ first = 0; }
{
first = 0;
}
/* Create a list pointing to the specified node */
inline LispList(LispNode<contents> *_first)
{ first = _first; }
{
first = _first;
}
/* ?? */
inline LispList(LispList &init)
{ first = init.first; }
{
first = init.first;
}
/* ---------- List queries ------------- */
inline int is_empty()
{ return first == 0; }
{
return first == 0;
}
/* Determines if a thing is on the list */
inline int is_present(contents *element)
@@ -102,7 +108,9 @@ struct LispList
first = new LispNode<contents>(new_element, first);
}
inline void add_head(contents *new_element)
{ add_head_new(new_element); }
{
add_head_new(new_element);
}
/* Create new node pointing to thing, & add to end of list. */
inline void add_tail_new(contents *new_element)
@@ -113,7 +121,9 @@ struct LispList
*pred = new LispNode< contents >(new_element);
}
inline void add_tail(contents *new_element)
{ add_tail_new(new_element); }
{
add_tail_new(new_element);
}
/* Create new node pointing to thing, & add anywhere on list */
inline void add_new(contents *new_element)
@@ -230,8 +240,7 @@ struct LispList
inline contents *get_head()
{
contents *c = 0;
if(first)
{
if(first) {
c = first->car;
delete rem_head();
}
@@ -240,22 +249,30 @@ struct LispList
/* Take something off the list */
inline contents *get()
{ return(get_head()); }
{
return(get_head());
}
/* XXX inline contents *get_tail() { } */
/* -------- Stack simulation (by j.h.) ------------ */
/* Put a thing onto the head of the list */
inline void push(contents *c)
{ put_head( c ); }
{
put_head(c);
}
/* Remove a thing from the head of the list */
inline contents *pop()
{ return(get_head()); }
{
return(get_head());
}
/* Pop everything off the stack. Empty the stack/list. */
inline void pop_all()
{ rem_del_all(); }
{
rem_del_all();
}
/* ----------- list/list manipulations ------------ */
@@ -330,8 +347,7 @@ struct DoubleLinkedList : public DoubleLinkedNode<thetype>
};
template <class T>
struct BufferArray
{
struct BufferArray {
T * items;
int num_items;
int num_slots;
@@ -378,4 +394,4 @@ struct BufferArray
};
};
#endif
#endif // UTIL_H