Added chart demo

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15794 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-01-02 15:09:03 +00:00
parent 8e64a82404
commit be51f21d8a
12 changed files with 4762 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
/*
Chart.cpp
by Pierre Raynaud-Richard.
*/
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef CHART_WINDOW_H
#include "ChartWindow.h"
#endif
#ifndef CHART_H
#include "Chart.h"
#endif
#include <Debug.h>
int
main()
{
ChartApp *myApplication;
myApplication = new ChartApp();
myApplication->Run();
delete(myApplication);
return(0);
}
ChartApp::ChartApp() : BApplication("application/x-vnd.Be.ChartDemo")
{
aWindow = new ChartWindow(BRect(120, 150, 629, 557), "Charts");
// showing the window will also start the direct connection. If you
// Sync() after the show, the direct connection will be established
// when the Sync() return (as far as any part of the content area of
// the window is visible after the show).
aWindow->Show();
}
+32
View File
@@ -0,0 +1,32 @@
/*
Chart.h
by Pierre Raynaud-Richard.
*/
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef CHART_H
#define CHART_H
#ifndef _APPLICATION_H
#include <Application.h>
#endif
#ifndef CHART_WINDOW_H
#include "ChartWindow.h"
#endif
/* not too much to be said... */
class ChartApp : public BApplication {
public:
ChartApp();
private:
ChartWindow *aWindow;
};
#endif
Binary file not shown.
+628
View File
@@ -0,0 +1,628 @@
/*
ChartRender.c
by Pierre Raynaud-Richard.
Copyright 1998 Be Incorporated, All Rights Reserved.
*/
/* This file has been designed to be easy to compile as a stand-alone
piece of code, allowing you to use advanced intel compiler, even
if they are compatible with the whole Be environment. To accomplish
that purpose, all declarations were concentrated in ChartRender.h
(see that header file for more infos). */
#include "ChartRender.h"
/* This table provide the horizontal and vertical offset of the matrix
of pixel used for drawing stars. This matrix is designed as follow:
-- [00] [01] [02] [03] --
[04] [05] [06] [07] [08] [09]
[10] [11] [12] [13] [14] [15]
[16] [17] [18] [19] [20] [21]
[22] [23] [24] [25] [26] [27]
-- [28] [29] [30] [31] --
The reference pixel is [12]. */
int8 pattern_dh[32] = {
-1, 0, 1, 2,
-2, -1, 0, 1, 2, 3,
-2, -1, 0, 1, 2, 3,
-2, -1, 0, 1, 2, 3,
-2, -1, 0, 1, 2, 3,
-1, 0, 1, 2
};
int8 pattern_dv[32] = {
-2, -2, -2, -2,
-1, -1, -1, -1, -1, -1,
0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2,
3, 3, 3, 3
};
/* Those table contains a preprocessed version of the 32 size of star,
represented in the 32 pixels matrix, by alpha-blending density [0 to 7].
Those matrix are stored in packed format, as a the list of all pixel
whose alpha-blending density is > 0. There is 4 cases because every
star can be aligned at half a pixel in both direction (we implement
sub-pixel precision and anti-aliasing to reduce the jittering). */
static uint8 pattern_list[4*LEVEL_COUNT][32];
static uint8 pattern_list_count[4*LEVEL_COUNT];
static uint8 pattern_color_offset[4*LEVEL_COUNT][32];
/* this table store the alpha-blending level of the center pixel. This
is used for size so small that only the center pixel is lighted. */
static uint8 pixel_color_offset[LEVEL_COUNT];
/* Those mask are use for fast clipping, to determine which of the 32
pixels of the standard star matrix are visible when coming closer
from a left, right, top or bottom clipping border. */
static uint32 visible_mask_left[6] = {
0xffffffff,
0xffbefbef,
0xef3cf3ce,
0xce38e38c,
0x8c30c308,
0x08208200
};
static uint32 visible_mask_right[6] = {
0xffffffff,
0xf7df7dff,
0x73cf3cf7,
0x31c71c73,
0x10c30c31,
0x00410410,
};
static uint32 visible_mask_top[6] = {
0xffffffff,
0xfffffff0,
0xfffffc00,
0xffff0000,
0xffc00000,
0xf0000000
};
static uint32 visible_mask_bottom[6] = {
0xffffffff,
0x0fffffff,
0x003fffff,
0x0000ffff,
0x000003ff,
0x0000000f
};
/* Private functions used only internally. */
float b_sqrt(float x);
bool ProjectStar(star *s, geometry *geo);
bool CheckClipping(star *s, buffer *buf, bool reset_clipping);
void DrawStar(star *s, buffer *buf);
void EraseStar(star *s, buffer *buf);
/* Good approximation of square root, for x > 0.0 That resolves
the problem of having a dependency with the math library, and
it's good enough for what we need. */
float b_sqrt(float x) {
uint32 val;
float y,z,t;
float flottant, tampon;
flottant = x;
val = *((uint32*)&flottant);
val >>= 1;
val += 0x1FC00000L;
*((uint32*)&tampon) = val;
y = tampon;
z = y*y+x;
t = y*y-x;
y *= (float)4.0;
x = z*z;
t = t*t;
y = z*y;
t = (float)2.0*x-t;
return t/y;
}
/* This function initialise the 32 sizes of anti-aliased star, each one
represented in 4 different half-pixel alignement :
x : -0.25, y : -0.25
x : +0.25, y : -0.25
x : -0.25, y : +0.25
x : +0.25, y : +0.25 */
void InitPatterns()
{
int32 i, j, k, count;
float radius, x0, y0, x, y, dist, delta, coeff;
uint8 color;
uint8 *list, *color_offset;
/* do the 4 half-pixel alignement */
for (j=0; j<4; j++) {
if (j&1) x0 = 1.25;
else x0 = 0.75;
if (j&2) y0 = 1.25;
else y0 = 0.75;
/* do the 32 sizes */
for (i=0; i<LEVEL_COUNT; i++) {
radius = (float)(i+1) * (2.8/(float)LEVEL_COUNT);
count = 0;
list = pattern_list[j*LEVEL_COUNT + i];
color_offset = pattern_color_offset[j*LEVEL_COUNT + i];
/* scan the 32 pixels of the matrix */
for (k=0; k<32; k++) {
x = ((float)pattern_dh[k] + ROUNDING) - x0;
y = ((float)pattern_dv[k] + ROUNDING) - y0;
dist = b_sqrt(x*x + y*y);
/* process non source pixel */
if (dist > 0.5) {
delta = radius - dist + 0.5;
if (delta >= 1.0) {
*color_offset++ = 7;
*list++ = k;
count++;
}
else if (delta > 0.5) {
*color_offset++ = (uint8)(7.499 - 16.0 * (1.0 - delta) * (1.0 - delta) + ROUNDING);
*list++ = k;
count++;
}
else if (delta > 0) {
color = (uint8)(16.0 * delta * delta);
if (color > 0) {
*color_offset++ = color;
*list++ = k;
count++;
}
}
}
/* process source pixel (the one containing the center of the star) */
else {
if (radius < 0.25) {
color = (uint8)(32.0 * radius * radius + ROUNDING);
if (color == 0)
color++;
}
else if (radius < 0.75) {
delta = radius + 0.25;
color = (uint8)(7.499 - 22.0 * (1.0 - delta) * (1.0 - delta) + ROUNDING);
}
else
color = 7;
*color_offset++ = color;
*list++ = k;
count++;
pixel_color_offset[i] = color;
}
}
pattern_list_count[j*LEVEL_COUNT + i] = count;
}
}
}
/* Project a star (s) in the view space of the camera, as described by (geo).
Returns true if the star seems to be visible (in the pyramid of vision,
closer than the rear plan, farther than the front plan), or false if it's
clear that the star isnot visible. */
bool ProjectStar(star *s, geometry *geo)
{
int32 h_double, v_double, level;
float x0, y0, z0, x, y, z, inv_z;
/* Calculate the coordinate of the star after doing the cycling operation
that convert the cube of the starfield in a torus. This ensure that
get the copy of the star that is the only one likely to be visible from
the camera. */
x0 = s->x;
if (x0 < geo->cutx)
x0 += 1.0;
y0 = s->y;
if (y0 < geo->cuty)
y0 += 1.0;
z0 = s->z;
if (z0 < geo->cutz)
z0 += 1.0;
/* Translate the star relative to the position of the camera. */
x0 -= geo->x;
y0 -= geo->y;
z0 -= geo->z;
/* Calculate the z coordinate (depth) of the star in the camera referential. */
z = geo->m[0][2]*x0 + geo->m[1][2]*y0 + geo->m[2][2]*z0;
/* Do the rear and front plan clipping */
if ((z < geo->z_min) || (z > geo->z_max))
return false;
/* Calculate the x coordinate (horizontal) of the star in the camera referential. */
x = geo->m[0][0]*x0 + geo->m[1][0]*y0 + geo->m[2][0]*z0;
/* Do the left and right clipping based on the pyramid of vision. */
if ((x < geo->xz_min*z-BORDER_CLIPPING) || (x > geo->xz_max*z+BORDER_CLIPPING))
return false;
/* Calculate the y coordinate (vertical) of the star in the camera referential. */
y = geo->m[0][1]*x0 + geo->m[1][1]*y0 + geo->m[2][1]*z0;
/* Do the top and bottom clipping based on the pyramid of vision. */
if ((y < geo->yz_min*z-BORDER_CLIPPING) || (y > geo->yz_max*z+BORDER_CLIPPING))
return false;
/* Calculate the invert of z, used to project both H and V coordinate. Apply
the zoom-factor at the same time. The zoom-factor was overscale by a factor
of two in advance, for the half-pixel precision processing */
inv_z = geo->zoom_factor/z;
/* Calculate the double pixel coordinate in the buffer (in half-pixel). */
h_double = (int32)(x * inv_z + geo->offset_h);
v_double = (int32)(y * inv_z + geo->offset_v);
/* Calculate the light level of the star. We use that little weird function
to a get faster gradient to black near the rear plan. */
level = (int32)(s->size * (inv_z * geo->z_max_square - z * geo->zoom_factor)) >> 8;
/* The light level can go higher that our max (saturation). */
if (level >= LEVEL_COUNT)
level = LEVEL_COUNT-1;
/* Get the real pixel coordinate in the buffer from the double coordinates */
s->h = h_double >> 1;
s->v = v_double >> 1;
/* Save the light level (used to recognize single pixel star) */
s->level = level;
/* switch between the 4 pattern table use for the 4 half-aligned. */
if ((h_double & 1) == 1) level += LEVEL_COUNT;
if ((v_double & 1) == 1) level += 2*LEVEL_COUNT;
s->pattern_level = level;
return true;
}
/* Once a star has been projected (using ProjectStar), we need to determine
which pixel of the star matrix are visible (if any). This depend of the
clipping of the specific buffer you're using. This function will do that
for the star (s), in the buffer (buf). It will return false if the star
is fully invisible, true if not. The falg reset_clipping is used to
reprocess the clipping from scratsh, or to just cumulate the new clipping
to the last drawing clipping (this is needed when updating the clipping
of every stars after changing the clipping region of the buffer). */
bool CheckClipping(star *s, buffer *buf, bool reset_clipping)
{
int32 i, delta;
uint32 total_visible, tmp_visible;
clipping_rect box;
clipping_rect *r;
/* Simple case : the star is represented by only one pixel. */
if (pattern_list_count[s->pattern_level] == 1) {
/* if the pixel is not in the bounding box of the clipping region,
the star is guarantee to be invisible. */
if ((s->h < buf->clip_bounds.left) ||
(s->h > buf->clip_bounds.right) ||
(s->v < buf->clip_bounds.top) ||
(s->v > buf->clip_bounds.bottom))
goto invisible;
/* if the clipping region contains only one rectangle, then it's
equal to its bounding box, so no further test are needed. */
if (buf->clip_list_count == 1)
goto visible;
/* In the other case, we need to go through the list of rectangle
of the clipping region and check if the pixel is in any of those */
r = buf->clip_list;
for (i=0; i<buf->clip_list_count; r++, i++)
if ((s->h >= r->left) &&
(s->h <= r->right) &&
(s->v >= r->top) &&
(s->v <= r->bottom))
goto visible;
/* The pixel is not visible. The star is marked as not drawn. */
invisible:
s->last_draw_offset = INVALID;
return false;
visible:
/* The pixel is visible. The offset at which the star should be draw is
calculated and store for using by drawing (and erasing later). */
s->last_draw_offset = s->v * buf->bytes_per_row + s->h * buf->bytes_per_pixel;
return true;
}
/* Complex case : the star is represented by more than one pixel. */
else {
/* Calculate the box the bounding box of the matrix of 32 pixels used
to represent the star, called box. */
box.left = s->h - 2;
box.right = s->h + 3;
box.top = s->v - 2;
box.bottom = s->v + 3;
/* Check if the box is fully outside of the bounding box of the clipping
region. That woudl guarantee that the star is invisible. */
if ((box.right < buf->clip_bounds.left) ||
(box.left > buf->clip_bounds.right) ||
(box.bottom < buf->clip_bounds.top) ||
(box.top > buf->clip_bounds.bottom))
goto invisible_pat;
/* Now, we have to go through the list of rectangle of the clipping region
and cumulate the mask of the star matrix pixels that are visible in any
of those rectangle. At start time, the mask is empty. */
total_visible = 0;
r = buf->clip_list;
for (i=0; i<buf->clip_list_count; r++, i++) {
/* When reseting the clipping, all pixel of the matrix are tested. In
the other mode, only the pixel previously visible are tested (as we
want to know which one of the previously drawn pixel still need to
be erased. */
if (reset_clipping)
tmp_visible = 0xffffffff;
else
tmp_visible = s->last_draw_pattern;
/* Calculate the clipping on the left side of the rectangle. */
delta = r->left-box.left;
if (delta > 5)
continue;
if (delta > 0)
tmp_visible &= visible_mask_left[delta];
/* Calculate the clipping on the right side of the rectangle. */
delta = box.right-r->right;
if (delta > 5)
continue;
if (delta > 0)
tmp_visible &= visible_mask_right[delta];
/* Calculate the clipping on the top side of the rectangle. */
delta = r->top-box.top;
if (delta > 5)
continue;
if (delta > 0)
tmp_visible &= visible_mask_top[delta];
/* Calculate the clipping on the bottom side of the rectangle. */
delta = box.bottom-r->bottom;
if (delta > 5)
continue;
if (delta > 0)
tmp_visible &= visible_mask_bottom[delta];
/* Pixel of the matrix not clipped out at that point are visible
inside this rectangle of the clipping region. We need to add
them to the mask of currently known visible pixel. */
total_visible |= tmp_visible;
/* If all pixel of the matrix are already visible, no need to continue
further. */
if (total_visible == 0xffffffff)
goto visible_pat;
}
/* If no pixel are visible, then we know... */
if (total_visible != 0)
goto visible_pat;
/* The star is not visible. It's marked as not drawn. */
invisible_pat:
s->last_draw_offset = INVALID;
return false;
visible_pat:
/* The star is partially visible. The offset at which the star should be
draw is calculated and store for using by drawing (and erasing later).
The mask of which pixel of the matrix are visible is store for use
at drawing and erasing time. */
s->last_draw_offset = s->v * buf->bytes_per_row + s->h * buf->bytes_per_pixel;
s->last_draw_pattern = total_visible;
return true;
}
}
/* After calling ProjectStar and CheckClipping, we're finally ready to
draw the star in its destination buffer. So let's do it... */
void DrawStar(star *s, buffer *buf)
{
int32 i, index, count;
uint8 *draw8;
uint16 *draw16;
uint32 *draw32;
uint32 *colors;
uint8 *pat_list;
uint8 *pat_color_offset;
/* Simple case : the star is represented by only one pixel. */
count = pattern_list_count[s->pattern_level];
if (count == 1) {
/* Depending the depth mode of the drawing buffer... */
switch (buf->depth_mode) {
case PIXEL_1_BYTE :
/* Get the pointer to the address we want to draw to... */
draw8 = (uint8*)((char*)buf->bits + s->last_draw_offset);
/* ... and write the color pattern we want to use depending of
the lighting level and the color scheme of the star. */
*draw8 = buf->colors[s->color_type][pixel_color_offset[s->level]];
break;
case PIXEL_2_BYTES :
/* Same thing for 2 bytes mode */
draw16 = (uint16*)((char*)buf->bits + s->last_draw_offset);
*draw16 = buf->colors[s->color_type][pixel_color_offset[s->level]];
break;
case PIXEL_4_BYTES :
/* Same thing for 4 bytes mode */
draw32 = (uint32*)((char*)buf->bits + s->last_draw_offset);
*draw32 = buf->colors[s->color_type][pixel_color_offset[s->level]];
break;
}
}
/* Complex case : the star is represented by a multiple pixels. */
else {
/* Pointer to the color table used depending the color scheme of
the star. */
colors = buf->colors[s->color_type];
pat_list = pattern_list[s->pattern_level];
pat_color_offset = pattern_color_offset[s->pattern_level];
/* Plot all pixel used to represent the star one after one... */
for (i=0; i<count; i++) {
/* This is the index of the pixel in the matrix */
index = pat_list[i];
/* Check if this pixel is visible (using the result of the clipping) */
if (s->last_draw_pattern & (1<<index)) {
switch (buf->depth_mode) {
case PIXEL_1_BYTE :
/* Get the pointer to the address we want to draw to... */
draw8 = (uint8*)((char*)buf->pattern_bits[index] + s->last_draw_offset);
/* ... and write the color pattern we want to use depending of
the lighting level and the color scheme of the star. */
*draw8 = colors[pat_color_offset[i]];
break;
case PIXEL_2_BYTES :
/* Same thing for 2 bytes mode */
draw16 = (uint16*)((char*)buf->pattern_bits[index] + s->last_draw_offset);
*draw16 = colors[pat_color_offset[i]];
break;
case PIXEL_4_BYTES :
/* Same thing for 4 bytes mode */
draw32 = (uint32*)((char*)buf->pattern_bits[index] + s->last_draw_offset);
*draw32 = colors[pat_color_offset[i]];
break;
}
}
}
}
}
/* Before redrawing a star at its new position, we need to erase what we draw
at the previous frame... */
void EraseStar(star *s, buffer *buf)
{
int32 i, index, count;
uint8 *draw8;
uint16 *draw16;
uint32 *draw32;
uint32 back_color;
uint8 *pat_list;
/* Color pattern we use to erase the buffer. */
back_color = buf->back_color;
/* Simple case : the star is represented by only one pixel. */
count = pattern_list_count[s->pattern_level];
if (count == 1) {
/* Depending the depth mode of the drawing buffer... */
switch (buf->depth_mode) {
case PIXEL_1_BYTE :
/* Get the pointer to the address we want to erase... */
draw8 = (uint8*)((char*)buf->bits + s->last_draw_offset);
/* ... and write the background color pattern. */
*draw8 = back_color;
break;
case PIXEL_2_BYTES :
/* Same thing for 2 bytes mode */
draw16 = (uint16*)((char*)buf->bits + s->last_draw_offset);
*draw16 = back_color;
break;
case PIXEL_4_BYTES :
/* Same thing for 4 bytes mode */
draw32 = (uint32*)((char*)buf->bits + s->last_draw_offset);
*draw32 = back_color;
break;
}
}
/* Complex case : the star is represented by a multiple pixels. */
else {
pat_list = pattern_list[s->pattern_level];
/* Erase all pixel used to represent the star one after one... */
for (i=0; i<count; i++) {
index = pat_list[i];
/* Check if this pixel is visible (using the result of the clipping) */
if (s->last_draw_pattern & (1<<index)) {
switch (buf->depth_mode) {
case PIXEL_1_BYTE :
/* Get the pointer to the address we want to draw to... */
draw8 = (uint8*)((char*)buf->pattern_bits[index] + s->last_draw_offset);
/* ... and write the background color pattern. */
*draw8 = back_color;
break;
case PIXEL_2_BYTES :
/* Same thing for 2 bytes mode */
draw16 = (uint16*)((char*)buf->pattern_bits[index] + s->last_draw_offset);
*draw16 = back_color;
break;
case PIXEL_4_BYTES :
/* Same thing for 4 bytes mode */
draw32 = (uint32*)((char*)buf->pattern_bits[index] + s->last_draw_offset);
*draw32 = back_color;
break;
}
}
}
}
}
/* This function do the transition from previous state to the new state
as described in (geo), in the buffer (buf), for the list of star (sp) */
void RefreshStarPacket(buffer *buf, star_packet *sp, geometry *geo)
{
int32 i, min_count;
star *s;
/* Calculate the number of stars that were process during the
previous frame and still need to be process for that frame. */
min_count = sp->erase_count;
if (sp->count < min_count)
min_count = sp->count;
s = sp->list;
/* For all those star... */
for (i=0; i<min_count; s++, i++) {
/* ... erase them if necessary, ... */
if (s->last_draw_offset != INVALID)
EraseStar(s, buf);
/* ... project them at their new position, ... */
if (ProjectStar(s, geo)) {
/* ... check the clipping of the buffer if the star are in
the pyramid of vision, ... */
if (CheckClipping(s, buf, true))
/* ... and draw them if they're really visible. */
DrawStar(s, buf);
}
/* ... or mark them as invisible if they're not in the pyramid
of vision. */
else
s->last_draw_offset = INVALID;
}
/* For star that were process at the previous frame but that we don't
want to process anymore, we just need to erase them. */
for (; i<sp->erase_count; s++, i++)
if (s->last_draw_offset != INVALID)
EraseStar(s, buf);
/* For star that were not process before, but are now, we just need to
go through the projection, clipping and drawing steps. */
for (; i<sp->count; s++, i++) {
if (ProjectStar(s, geo)) {
if (CheckClipping(s, buf, true))
DrawStar(s, buf);
}
else
s->last_draw_offset = INVALID;
}
}
/* Update the clipping visibility of all star of the list (sp) to
respect the new clipping defined for the buffer (buf). */
void RefreshClipping(buffer *buf, star_packet *sp)
{
star *s;
int32 i;
s = sp->list;
for (i=0; i<sp->erase_count; s++, i++)
if (s->last_draw_offset != INVALID)
CheckClipping(s, buf, false);
}
+230
View File
@@ -0,0 +1,230 @@
/*
ChartRender.h
by Pierre Raynaud-Richard.
*/
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef _CHART_RENDER_
#define _CHART_RENDER_
/* This header file can be easily converted to encapsulate ALL declarations
related to basic drawing and animation in the application. The idea
was to reduce the most processor-intensive part of the application
to its minimal "C-like" core, independent of the Be headers, so that
the corresponding source code (in ChartRender.cpp) can be compiled
with another compiler and just linked with the rest of the projects.
That allows you to use advanced compilers generating faster code for
the critical part of the demo. The drawback is that such manipulation
is difficult and should be reserved for really critical code.
This is really useful only on intel. */
/* In this version, we just include the Be headers. That's the only Be
specific part. To break that dependencies, just switch that #if
statement to 0. */
#if 1
#include <SupportDefs.h>
#include <GraphicsDefs.h>
#include <DirectWindow.h>
#else
typedef enum {
B_RGB32 = 0x0008,
B_RGBA32 = 0x2008,
B_RGB16 = 0x0005,
B_RGB15 = 0x0010,
B_RGBA15 = 0x2010,
B_CMAP8 = 0x0004,
B_RGB32_BIG = 0x1008,
B_RGBA32_BIG = 0x3008,
B_RGB16_BIG = 0x1005,
B_RGB15_BIG = 0x1010,
B_RGBA15_BIG = 0x3010
} color_space;
typedef signed char int8;
typedef unsigned char uint8;
typedef short int16;
typedef unsigned short uint16;
typedef long int32;
typedef unsigned long uint32;
typedef unsigned char bool;
#define false 0
#define true 1
typedef struct {
int32 left;
int32 top;
int32 right;
int32 bottom;
} clipping_rect;
#endif
/* Rounding is always done in C-standard mode */
#define ROUNDING 0.5
/* Count of different light level available for a star. */
#define LEVEL_COUNT 32
/* Used to mark the last drawing offset of a star as unused
(the star was invisible last time we tried drawing it) */
#define INVALID 0x10000000
/* Clipping is done in 2 pass. A pixel clipping handle the
real window visibility clipping. A geometric clipping
sort out all stars that are clearly out of the pyramid
of vision of the full-window. As star are bigger than
just a pixel, we need a error margin to compensate for
that, so that we don't clipped out star that would be
barely visible on the side. */
#define BORDER_CLIPPING 0.01
/* the three drawing row-format. */
#define PIXEL_1_BYTE 0
#define PIXEL_2_BYTES 1
#define PIXEL_4_BYTES 2
/* This is the generic definition of a drawing buffer. This
can describe both an offscreen bitmap or a directwindow
frame-buffer. That the layer that allows us to abstract
our real drawing buffer and make our drawing code indepen-
dant of its real target, so that it's trivial to switch
from Bitmap mode to DirectWindow mode. */
typedef struct {
/* base address of the buffer. */
void *bits;
/* count of bytes between the begining of 2 lines. */
int32 bytes_per_row;
/* count of bytes per pixel. */
int32 bytes_per_pixel;
/* row-format of the buffer (PIXEL_1_BYTE, PIXEL_2_BYTES
or PIXEL_4_BYTES. */
int32 depth_mode;
/* buffer dimensions. */
int32 buffer_width;
int32 buffer_height;
/* color_space of the buffer. */
color_space depth;
/* 7x8x32 bits words representing the row value of the 7
possible star color, at 8 different light levels. If
the pixel encoding doesn't use 4 bytes, the color
value is repeated as many as necessary to fill the
32 bits. */
uint32 colors[7][8];
/* same color value, for the background color of the
buffer. */
uint32 back_color;
/* clipping of the buffer, in the standard DirectWindow
format. */
uint32 clip_list_count;
clipping_rect clip_bounds;
clipping_rect clip_list[64];
/* base address of the buffer offset by the delta offset
of the 32 different bits used to render the different
size of stars. */
void *pattern_bits[32];
} buffer;
/* this strcuture is used to represent a star. */
typedef struct {
/* position of the star in a [0-1]x[0-1]x[0-1] cube */
float x;
float y;
float z;
/* size coefficient. Some star are bigger than others */
float size;
/* color profile of the star (between the 7 existing colors */
uint8 color_type;
/* lighting level */
uint8 level;
/* pattern level. Used to design which representation of star
will be used, depending of the ligthing level and the half-
pixel alignment. */
uint16 pattern_level;
/* screen coordinate, relative to the center */
int16 h;
int16 v;
/* if the star was drawn at the previous frame, this contains
the drawing offset of the reference pixel in the buffer.
Then last_draw_pattern contains the mask of bits really
draw in the star pixel pattern (32 pixels max).
If the star wasn't draw, last_draw_offset contains INVALID */
int32 last_draw_offset;
int32 last_draw_pattern;
} star;
/* struct defining a collection of star. Include a array of stars,
the count of currently used members of the array (the array can
be bigger and only partialy used, and the previous value of that
count (call erase_count) that define which stars were drawn
before, and so need to be erase for this frame. */
typedef struct {
star *list;
int32 count;
int32 erase_count;
} star_packet;
/* this struct define the full geometry of the camera looking at
the star field. */
typedef struct {
/* position of the camera in the extended [0-2]x[0-2]x[0-2]
cube. */
float x;
float y;
float z;
/* those values define the limit below which stars should be
virtually duplicate in extended space. That allows to move
the [0-1]x[0-1]x[0-1] star cube (as a cycling torus on the
3 axis), to any position inside the [0-2]x[0-2]x[0-2] cube.
The pyramid of vision is designed to be always included
inside a [0-1]x[0-1]x[0-1]. So all stars are defined in
such a small cube, then the cube will cycle using those
3 variables (for example, cutx = 0.3 will virtually cut
the [0-0.3]x[0-1]x[0-1] of the cube and duplicate it at
[1.0-1.3]x[0-1]x[0-1], creating a [0.3-1.3]x[0-1]x[0-1]
star field. Doing the same thing on the 3 axis, allows
to cycle the starfield wherever it's needed to fully
include the pyramid of vision. That way, the camera
always look at a properly positionned 1x1x1 starfield... */
float cutx;
float cuty;
float cutz;
/* rotation matrix of the camera */
float m[3][3];
/* offset of the center of the camera vision axis in the window */
float offset_h, offset_v;
/* min and max ratio x/z or y/z defining the pyramid of vision
used for the first quick clipping. */
float xz_min, xz_max, yz_min, yz_max;
/* min and max visibility threshold used for the front and rear
clipping, and the square factor used in the lighting formula */
float z_min, z_max, z_max_square;
/* zoom factor of the camera, basically how large (in pixel) a
object of size 1.0 at a depth of 1.0 would look like */
float zoom_factor;
} geometry;
/* offset (horizontal and vertical) of the 32 pixels used to
represent different sizes of stars. */
extern int8 pattern_dh[32];
extern int8 pattern_dv[32];
/* the public API of th animation module */
/* first time init */
void InitPatterns();
/* used to move/draw/erase a colection of star in specific buffer */
void RefreshStarPacket(buffer *buf, star_packet *sp, geometry *geo);
/* used to update the visibility status of a collection of stars
after the clipping changed. */
void RefreshClipping(buffer *buf, star_packet *sp);
#endif
+255
View File
@@ -0,0 +1,255 @@
/*
ChartRender.h
by Pierre Raynaud-Richard.
*/
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef _CHART_RENDER_
#define _CHART_RENDER_
/* This header file has been designed to encapsulate ALL declarations
related to basic drawing and animation in the application. The idea
was to reduce the most processor-intesinve part of the application
to its minimal "C-like" core, independent of the Be headers, so that
the correspondant source code (in ChartRender.c) can be compiled
with another compiler and just link with the rest of the projects.
That allow you to use advanced compiler generating faster code for
the critical part of the demo. The drawback is that such manipulation
is difficult and should be reserved for really critical code.
This is really useful only on intel. */
/* this is used for a non Be-environment */
#if 0
/* this is a copy of the part of GraphicsDefs.h we really use. */
typedef enum {
B_RGB32 = 0x0008,
B_RGBA32 = 0x2008,
B_RGB16 = 0x0005,
B_RGB15 = 0x0010,
B_RGBA15 = 0x2010,
B_CMAP8 = 0x0004,
B_RGB32_BIG = 0x1008,
B_RGBA32_BIG = 0x3008,
B_RGB16_BIG = 0x1005,
B_RGB15_BIG = 0x1010,
B_RGBA15_BIG = 0x3010
} color_space;
/* this is a copy of the part of SupportDefs.h we really use */
typedef signed char int8;
typedef unsigned char uint8;
typedef short int16;
typedef unsigned short uint16;
typedef long int32;
typedef unsigned long uint32;
typedef unsigned char bool;
#define false 0
#define true 1
/* this is a copy of the part of DirectWindow.h we really use */
typedef struct {
int32 left;
int32 top;
int32 right;
int32 bottom;
} clipping_rect;
/* The default rounding mode on intel processor is round to
closest. With the intel compiler, it's possible to ask for
the floating to integer conversion to be done that way and
not the C-standard way (round to floor). This constant is
used to compensate for the change of conversion algorythm.
Using the CPU native mode is faster than the C-standard
mode. Another crazy optimisation you shouldn't care too
much about (except if you're a crazy geek). */
#ifdef __INTEL__
#define ROUNDING 0.0
#else
#define ROUNDING 0.5
#endif
/* This represent the standard Be-environment */
#else
/* We just include the Be headers */
#include <SupportDefs.h>
#include <GraphicsDefs.h>
#include <DirectWindow.h>
/* Rounding is always done in C-standard mode */
#define ROUNDING 0.5
#endif
/* Count of different light level available for a star. */
#define LEVEL_COUNT 32
/* Used to mark the last drawing offset of a star as unused
(the star was invisible last time we tried drawing it) */
#define INVALID 0x10000000
/* Clipping is done in 2 pass. A pixel clipping handle the
real window visibility clipping. A geometric clipping
sort out all stars that are clearly out of the pyramid
of vision of the full-window. As star are bigger than
just a pixel, we need a error margin to compensate for
that, so that we don't clipped out star that would be
barely visible on the side. */
#define BORDER_CLIPPING 0.01
/* the three drawing row-format. */
#define PIXEL_1_BYTE 0
#define PIXEL_2_BYTES 1
#define PIXEL_4_BYTES 2
#ifdef __cplusplus
extern "C" {
#endif
/* This is the generic definition of a drawing buffer. This
can describe both an offscreen bitmap or a directwindow
frame-buffer. That the layer that allows us to abstract
our real drawing buffer and make our drawing code indepen-
dant of its real target, so that it's trivial to switch
from Bitmap mode to DirectWindow mode. */
typedef struct {
/* base address of the buffer. */
void *bits;
/* count of bytes between the begining of 2 lines. */
int32 bytes_per_row;
/* count of bytes per pixel. */
int32 bytes_per_pixel;
/* row-format of the buffer (PIXEL_1_BYTE, PIXEL_2_BYTES
or PIXEL_4_BYTES. */
int32 depth_mode;
/* buffer dimensions. */
int32 buffer_width;
int32 buffer_height;
/* color_space of the buffer. */
color_space depth;
/* 7x8x32 bits words representing the row value of the 7
possible star color, at 8 different light levels. If
the pixel encoding doesn't use 4 bytes, the color
value is repeated as many as necessary to fill the
32 bits. */
uint32 colors[7][8];
/* same color value, for the background color of the
buffer. */
uint32 back_color;
/* clipping of the buffer, in the standard DirectWindow
format. */
uint32 clip_list_count;
clipping_rect clip_bounds;
clipping_rect clip_list[64];
/* base address of the buffer offset by the delta offset
of the 32 different bits used to render the different
size of stars. */
void *pattern_bits[32];
} buffer;
/* this strcuture is used to represent a star. */
typedef struct {
/* position of the star in a [0-1]x[0-1]x[0-1] cube */
float x;
float y;
float z;
/* size coefficient. Some star are bigger than others */
float size;
/* color profile of the star (between the 7 existing colors */
uint8 color_type;
/* lighting level */
uint8 level;
/* pattern level. Used to design which representation of star
will be used, depending of the ligthing level and the half-
pixel alignment. */
uint16 pattern_level;
/* screen coordinate, relative to the center */
int16 h;
int16 v;
/* if the star was drawn at the previous frame, this contains
the drawing offset of the reference pixel in the buffer.
Then last_draw_pattern contains the mask of bits really
draw in the star pixel pattern (32 pixels max).
If the star wasn't draw, last_draw_offset contains INVALID */
int32 last_draw_offset;
int32 last_draw_pattern;
} star;
/* struct defining a collection of star. Include a array of stars,
the count of currently used members of the array (the array can
be bigger and only partialy used, and the previous value of that
count (call erase_count) that define which stars were drawn
before, and so need to be erase for this frame. */
typedef struct {
star *list;
int32 count;
int32 erase_count;
} star_packet;
/* this struct define the full geometry of the camera looking at
the star field. */
typedef struct {
/* position of the camera in the extended [0-2]x[0-2]x[0-2]
cube. */
float x;
float y;
float z;
/* those values define the limit below which stars should be
virtually duplicate in extended space. That allows to move
the [0-1]x[0-1]x[0-1] star cube (as a cycling torus on the
3 axis), to any position inside the [0-2]x[0-2]x[0-2] cube.
The pyramid of vision is designed to be always included
inside a [0-1]x[0-1]x[0-1]. So all stars are defined in
such a small cube, then the cube will cycle using those
3 variables (for example, cutx = 0.3 will virtually cut
the [0-0.3]x[0-1]x[0-1] of the cube and duplicate it at
[1.0-1.3]x[0-1]x[0-1], creating a [0.3-1.3]x[0-1]x[0-1]
star field. Doing the same thing on the 3 axis, allows
to cycle the starfield wherever it's needed to fully
include the pyramid of vision. That way, the camera
always look at a properly positionned 1x1x1 starfield... */
float cutx;
float cuty;
float cutz;
/* rotation matrix of the camera */
float m[3][3];
/* offset of the center of the camera vision axis in the window */
float offset_h, offset_v;
/* min and max ratio x/z or y/z defining the pyramid of vision
used for the first quick clipping. */
float xz_min, xz_max, yz_min, yz_max;
/* min and max visibility threshold used for the front and rear
clipping, and the square factor used in the lighting formula */
float z_min, z_max, z_max_square;
/* zoom factor of the camera, basically how large (in pixel) a
object of size 1.0 at a depth of 1.0 would look like */
float zoom_factor;
} geometry;
/* offset (horizontal and vertical) of the 32 pixels used to
represent different sizes of stars. */
int8 pattern_dh[32];
int8 pattern_dv[32];
/* the public API of th animation module */
/* first time init */
void InitPatterns();
/* used to move/draw/erase a colection of star in specific buffer */
void RefreshStarPacket(buffer *buf, star_packet *sp, geometry *geo);
/* used to update the visibility status of a collection of stars
after the clipping changed. */
void RefreshClipping(buffer *buf, star_packet *sp);
#ifdef __cplusplus
};
#endif
#endif
+83
View File
@@ -0,0 +1,83 @@
/*
ChartView.cpp
by Pierre Raynaud-Richard.
*/
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#include "ChartView.h"
#include "ChartWindow.h"
/* Straightforward constructor */
ChartView::ChartView(BRect rect) :
BView(rect, "", B_FOLLOW_ALL, B_WILL_DRAW) {;}
/* The drawing function just draw the offscreen if it exists and is used */
void ChartView::Draw(BRect r)
{
ChartWindow *w;
w = dynamic_cast<ChartWindow *>(Window());
if ((w->offscreen != 0) && (w->set.display == DISPLAY_BITMAP))
DrawBitmap(w->offscreen, r, r);
}
/* Send a message to the window if the user click anywhere in the animation
view. This is used to go out of fullscreen demo mode. */
void ChartView::MouseDown(BPoint where)
{
Window()->PostMessage(BACK_DEMO_MSG);
}
/* Another straightforward constructor. The default target setting for the
frames/s vue-meter is 5 (as 5 * 12 = 60 frames/s) */
InstantView::InstantView(BRect rect) :
BView(rect, "", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW)
{
step = 5;
}
/* Draw the colored bars of the vue-meter depending the current framerate
of the window animation. The color coding depends of the target framerate
as encoded by step. */
void InstantView::Draw(BRect r)
{
int32 i;
ChartWindow *w;
w = dynamic_cast<ChartWindow *>(Window());
for (i=0; i< w->instant_load_level; i++) {
if (i<step) SetHighColor(255.0, 90.0, 90.0);
else if ((i/step) & 1) SetHighColor(90.0, 255.0, 90.0);
else SetHighColor(40.0, 200.0, 40.0);
FillRect(BRect(3+i*4, 2, 5+i*4, 19));
}
Flush();
}
/* Straightforward constructor */
ChartColorControl::ChartColorControl(BPoint start, BMessage *message) :
BColorControl(start, B_CELLS_32x8, 8.0, "", message)
{
}
/* We overwrite SetValue to send a message to the target everytime
the setting change and not only at the end. */
void ChartColorControl::SetValue(int32 color_value)
{
BLooper *looper;
BColorControl::SetValue(color_value);
Target(&looper);
if (looper) {
BMessage msg(*Message());
msg.AddInt32("be:value", color_value);
looper->PostMessage(&msg);
}
}
+46
View File
@@ -0,0 +1,46 @@
/*
ChartView.h
by Pierre Raynaud-Richard.
*/
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef CHART_VIEW_H
#define CHART_VIEW_H
#include <View.h>
#include <ColorControl.h>
/* This view used for the star animation area. It just need to know how
to draw and handle mouse down event. */
class ChartView : public BView {
public:
ChartView(BRect frame);
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint where);
};
/* This view is used to draw the instant load vue-meter */
class InstantView : public BView {
public:
int32 step;
InstantView(BRect frame);
virtual void Draw(BRect updateRect);
};
/* This view is used to work around a bug in the current ColorControl,
that doesn't allow live feedback when changing the color. */
class ChartColorControl : public BColorControl {
public:
ChartColorControl(BPoint start, BMessage *message);
virtual void SetValue(int32 color_value);
};
#endif
File diff suppressed because it is too large Load Diff
+434
View File
@@ -0,0 +1,434 @@
/*
ChartWindow.h
by Pierre Raynaud-Richard.
*/
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef CHART_WINDOW_H
#define CHART_WINDOW_H
#ifndef _DIRECT_WINDOW_H
#include <DirectWindow.h>
#endif
#ifndef CHART_VIEW_H
#include "ChartView.h"
#endif
#include <OS.h>
#include <Locker.h>
#include <StringView.h>
#include <PictureButton.h>
#ifndef _CHART_RENDER_
#include "ChartRender.h"
#endif
/* This window can be used in 3 modes : window mode is just a
normal window (that you move and resize freely), fullscreen
resize the window to adjust its content area to the full
size of the screen. Demo mode resize the window to have the
animate part of it fit the full screen. */
enum {
WINDOW_MODE = 0,
FULLSCREEN_MODE = 1,
FULLDEMO_MODE = 2
};
/* Special animation mode. Comet create 2 comets flying around
randomaly. Novas add a couple start with flashing burst of
light. Battle was never implemented... */
enum {
SPECIAL_NONE = 0,
SPECIAL_COMET = 1,
SPECIAL_NOVAS = 2,
SPECIAL_BATTLE = 3
};
/* Three types of display mode : line is supposed to use line
array to draw pixel (but is not currently implemented). Bitmap
use an offscreen BBitmap and DrawBitmap for each frame. Direct
use the DirectWindow API to draw directly on the screen. */
enum {
DISPLAY_OFF = 0,
DISPLAY_LINE = 1,
DISPLAY_BITMAP = 2,
DISPLAY_DIRECT = 3
};
/* Five ways of moving the camera around : not at all, simple
rotation around the center of the starfield, slow straight
move, fast straight move, and a random move (flying around). */
enum {
ANIMATION_OFF = 0,
ANIMATION_ROTATE = 1,
ANIMATION_SLOW_MOVE = 2,
ANIMATION_FAST_MOVE = 3,
ANIMATION_FREE_MOVE = 4
};
/* Three types of star field. A new random starfield is created
everytime you change the starfield type. The first will just
put stars randomly in space. The second will concentrate
star in 10 places. The last one will put half the star in a
big spiral galaxy, and the other one in a few amas. */
enum {
SPACE_CHAOS = 0,
SPACE_AMAS = 1,
SPACE_SPIRAL = 2
};
/* All messages exchanged between the UI and the engine. */
enum {
ANIM_OFF_MSG = 1000,
ANIM_SLOW_ROT_MSG = 1001,
ANIM_SLOW_MOVE_MSG = 1002,
ANIM_FAST_MOVE_MSG = 1003,
ANIM_FREE_MOVE_MSG = 1004,
DISP_OFF_MSG = 2000,
DISP_LINE_MSG = 2001,
DISP_BITMAP_MSG = 2002,
DISP_DIRECT_MSG = 2003,
OPEN_COLOR_MSG = 3000,
OPEN_DENSITY_MSG = 3100,
OPEN_REFRESH_MSG = 3200,
SPACE_CHAOS_MSG = 3300,
SPACE_AMAS_MSG = 3301,
SPACE_SPIRAL_MSG = 3302,
FULL_SCREEN_MSG = 4000,
AUTO_DEMO_MSG = 4100,
BACK_DEMO_MSG = 4101,
SECOND_THREAD_MSG = 4200,
COLORS_RED_MSG = 5000,
COLORS_GREEN_MSG = 5001,
COLORS_BLUE_MSG = 5002,
COLORS_YELLOW_MSG = 5003,
COLORS_ORANGE_MSG = 5004,
COLORS_PINK_MSG = 5005,
COLORS_WHITE_MSG = 5006,
SPECIAL_NONE_MSG = 6000,
SPECIAL_COMET_MSG = 6001,
SPECIAL_NOVAS_MSG = 6002,
SPECIAL_BATTLE_MSG = 6003,
COLOR_PALETTE_MSG = 7000,
STAR_DENSITY_MSG = 8000,
REFRESH_RATE_MSG = 9000
};
enum {
/* Number of star used to generate the special animation */
SPECIAL_COUNT_MAX = 512,
/* Number of keypoint used for the "random" animation */
KEY_POINT_MAX = 16
};
/* Basic 3D point/vector class, used for basic vectorial
operations. */
class TPoint {
public:
float x;
float y;
float z;
TPoint operator* (const float k) const;
TPoint operator- (const TPoint& v2) const;
TPoint operator+ (const TPoint& v2) const;
TPoint operator^ (const TPoint& v2) const;
float Length() const;
};
/* Basic 3x3 matrix used for 3D transform. */
class TMatrix {
public:
float m[3][3];
TPoint operator* (const TPoint& v) const;
TPoint Axis(int32 index);
TMatrix Transpose() const;
void Set(const float alpha, const float theta, const float phi);
};
/* The main window class, encapsulating both UI and engine. */
class ChartWindow : public BDirectWindow {
public:
/* standard constructor and destructor */
ChartWindow(BRect frame, const char *name);
virtual ~ChartWindow();
/* standard window members */
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void ScreenChanged(BRect screen_size, color_space depth);
virtual void FrameResized(float new_width, float new_height);
/* this struct embedded all user settable parameters that
can be set by the UI. The idea is to solve all possible
synchronisation problem between the UI settings and the
engine (when using DirectWindow mode) by defining a
current setting state and a next setting state. The UI
touches only the next setting state, never the one
currently use by the engine. This way the engine doesn't
have to be synchronised with the UI. */
struct setting {
/* do we want to use the second thread ? */
bool second_thread;
/* which ones of the 7 star colors are we using ? */
bool colors[7];
/* what window configuration mode are we using ? */
int32 fullscreen_mode;
/* what special mode are we using ? */
int32 special;
/* what display mode are we using ? */
int32 display;
/* what starfield model are we using ? */
int32 space_model;
/* what camera animation are we using ? */
int32 animation;
/* what is the density of the current starfield
model ? */
int32 star_density;
/* what's the current required refresh rate ? */
float refresh_rate;
/* what's the current background color for the animated
view ? */
rgb_color back_color;
/* what's the current color_space of the screen ? */
color_space depth;
/* what's the current dimension of the content area of
the window ? */
int32 width, height;
/* used to copy a whole setting in another. */
void Set(setting *master);
};
/* this union is used to store special animation information
that are defined per star. */
typedef union {
/* for the comet, it's a speed vector and to
counters to define how long the star will
continue before disappearing. */
struct {
float dx;
float dy;
float dz;
int32 count;
int32 count0;
} comet;
/* for the novas, just counters to define the
pulse cycle of the star. */
struct {
float count;
int32 count0;
} nova;
/* battle was not implemented. */
struct {
int32 count;
} battle;
} special;
/* public instance members */
/* the current instantenuous potential frame/rate
as display by the vue-meter. */
int32 instant_load_level;
/* the offscreen Bitmap used, if any. */
BBitmap *offscreen;
/* the current active setting used by the engine */
setting set;
/* the private stuff... */
private:
/* User Interface related stuff. */
/* Find a window by its name if already opened. */
static BWindow *GetAppWindow(char *name);
/* Used to set the content of PictureButton. */
BPicture *ButtonPicture(bool active, int32 button_type);
/* Those function create and handle the other settings
floating windows, for the background color, the star
density and the refresh rate. */
void OpenColorPalette(BPoint here);
void OpenStarDensity(BPoint here);
void OpenRefresh(BPoint here);
/* Draw the state of the instant-load vue-meter */
void DrawInstantLoad(float frame_per_second);
/* Print the performances numbers, based on the real framerate. */
void PrintStatNumbers(float fps);
/* Engine setting related functions. */
/* Init the geometry engine of the camera at startup. */
void InitGeometry();
/* Check and apply changes between a new setting state
and the currently used one. */
void ChangeSetting(setting new_set);
/* Initialise a new starfield of the specified model. */
void InitStars(int32 model);
/* Fill a star list with random stars in [0-1]x[0-1]x[0-1]. */
void FillStarList(star *list, int32 count);
/* Init a new special animation of a specific type. */
void InitSpecials(int32 code);
/* Change the star field colors depending a new set of
selected colors. */
void SetStarColors(int32 *color_list, int32 color_count);
/* Change the global geometry of the camera when the
viewing area is resized. */
void SetGeometry(int32 dh, int32 dv);
/* Change the color_space configuration of a buffer */
void SetColorSpace(buffer *buf, color_space depth);
/* Used to sync the pre-offset matrix pointer whenever the buffer
bits pointer changes. */
void SetPatternBits(buffer *buf);
/* Engine processing related functions. */
/* those functions are the two processing threads launcher */
static long Animation(void *data);
static long Animation2(void *data);
/* After every camera move or rotation, reprocess the torus
cycle of the starfield to maintain the pyramid of vision
of the camera completly inside a 1x1x1 iteration of the
starfield. */
void SetCubeOffset();
/* Process the camera animation for a specified time step */
void CameraAnimation(float time_factor);
/* Used by the random move camera animation. */
void SelectNewTarget();
void FollowTarget();
/* Process the special animation for a specified time step */
void AnimSpecials(float time_step);
/* Sync the embedded camera state with the window class camera
state (before calling the embedded C-engine in ChartRender.c */
void SyncGeo();
/* Control the star processing (done by 1 or 2 threads) and
executed by the embedded C-engine in ChartRender.c */
void RefreshStars(buffer *buf, float time_step);
/* Offscreen bitmap configuration related functions. */
/* Used to update the state of the offscreen Bitmap to stay
in sync with the current settings. */
void CheckBitmap(color_space depth, int32 width, int32 height);
/* Set the basic clipping of the offscreen Bitmap (everything
visible) */
void SetBitmapClipping(int32 width, int32 height);
/* Draw the offscreen bitmap background. */
void SetBitmapBackGround();
/* DirectWindow related functions */
/* Process a change of state in the direct access to the
frame buffer. */
void SwitchContext(direct_buffer_info *info);
public:
/* this is the hook controling direct screen connection */
virtual void DirectConnected(direct_buffer_info *info);
private:
/* Pseudo-random generator state and increment function. */
int32 crc_alea;
inline void CrcStep();
/* Various private instance variables. */
/* the next setting, as modified by the UI */
setting next_set;
/* a boolean used to enable a work-around for a bug in
the DirectWindow flags setting. Only needed for the
release 3.0 */
bool need_r3_buffer_reset_work_around;
/* the buffer descriptors for the offscreen bitmap and
the DirectWindow buffer. */
buffer bitmap_buffer;
buffer direct_buffer;
/* current maximal dimensions of the offscreen Bitmap buffer */
int32 max_width, max_height;
/* memorize previous state for switch between fullscreen
and window mode */
BRect PreviousFrame;
int32 previous_fullscreen_mode;
/* cycling threshold for the cubic torus starfield, that
guarantees that the 1x1x1 sample will contain the full
pyramid of vision. */
TPoint cut;
/* maximal depth of the pyramid of vision */
float depth_ref;
int32 back_color_index;
/* target frame duration, in microsecond. */
bigtime_t frame_delay;
/* various UI object that we need to reach directly. */
BButton *offwindow_button;
ChartView *background;
BStringView *cpu_load, *frames;
InstantView *instant_load;
BPictureButton *color_button, *density_button, *refresh_button;
/* states used to describe the camera position, rotation
and dynamic (in other case than free move). */
float camera_alpha, camera_theta, camera_phi;
float d_alpha;
float d_theta;
float d_phi;
int32 cnt_alpha, cnt_theta, cnt_phi;
TPoint origin;
TMatrix camera;
TMatrix camera_invert;
/* the camera geometry descriptor required by the embedded
C-engine (just a copy of part of the previous states) */
geometry geo;
/* states used by the free move camera animation */
int32 tracking_target;
int32 key_point_count;
float speed, target_speed;
float last_dynamic_delay;
TPoint key_points[KEY_POINT_MAX];
/* main starfield. */
star_packet stars;
/* used for the special animation */
TPoint comet[2];
TPoint delta_comet[2];
special *special_list;
star_packet specials;
/* the two processing threads. */
thread_id animation_thread;
thread_id second_animation_thread;
/* context of the second processing thread (when used). */
float second_thread_threshold;
buffer *second_thread_buffer;
sem_id second_thread_lock;
sem_id second_thread_release;
bigtime_t second_thread_delay;
star_packet stars2;
star_packet specials2;
/* Flag used to terminate the processing threads */
bool kill_my_thread;
/* Direct connection status */
bool direct_connected;
/* used to synchronise the star animation drawing. */
sem_id drawing_lock;
};
#endif
+12
View File
@@ -0,0 +1,12 @@
SubDir HAIKU_TOP src tests kits game chart ;
Application Chart :
Chart.cpp
ChartRender.cpp
ChartView.cpp
ChartWindow.cpp
: libbe.so libgame.so libroot.so
: Chart.rsrc
;
+31
View File
@@ -0,0 +1,31 @@
----------------------
Be Sample Code License
----------------------
Copyright 1991-1999, Be Incorporated.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.