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_
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. */
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
#define ROUNDING 0.5
#define LEVEL_COUNT 32
(the star was invisible last time we tried drawing it) */
#define INVALID 0x10000000
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
#define PIXEL_1_BYTE 0
#define PIXEL_2_BYTES 1
#define PIXEL_4_BYTES 2
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 {
void *bits;
int32 bytes_per_row;
int32 bytes_per_pixel;
or PIXEL_4_BYTES. */
int32 depth_mode;
int32 buffer_width;
int32 buffer_height;
color_space depth;
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];
buffer. */
uint32 back_color;
format. */
uint32 clip_list_count;
clipping_rect clip_bounds;
clipping_rect clip_list[64];
of the 32 different bits used to render the different
size of stars. */
void *pattern_bits[32];
} buffer;
typedef struct {
float x;
float y;
float z;
float size;
uint8 color_type;
uint8 level;
will be used, depending of the ligthing level and the half-
pixel alignment. */
uint16 pattern_level;
int16 h;
int16 v;
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;
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;
the star field. */
typedef struct {
cube. */
float x;
float y;
float z;
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;
float m[3][3];
float offset_h, offset_v;
used for the first quick clipping. */
float xz_min, xz_max, yz_min, yz_max;
clipping, and the square factor used in the lighting formula */
float z_min, z_max, z_max_square;
object of size 1.0 at a depth of 1.0 would look like */
float zoom_factor;
} geometry;
represent different sizes of stars. */
extern int8 pattern_dh[32];
extern int8 pattern_dv[32];
void InitPatterns();
void RefreshStarPacket(buffer *buf, star_packet *sp, geometry *geo);
after the clipping changed. */
void RefreshClipping(buffer *buf, star_packet *sp);
#endif