1 /* 2 3 ChartRender.h 4 5 by Pierre Raynaud-Richard. 6 7 */ 8 9 /* 10 Copyright 1999, Be Incorporated. All Rights Reserved. 11 This file may be used under the terms of the Be Sample Code License. 12 */ 13 14 #ifndef _CHART_RENDER_ 15 #define _CHART_RENDER_ 16 17 /* This header file can be easily converted to encapsulate ALL declarations 18 related to basic drawing and animation in the application. The idea 19 was to reduce the most processor-intensive part of the application 20 to its minimal "C-like" core, independent of the Be headers, so that 21 the corresponding source code (in ChartRender.cpp) can be compiled 22 with another compiler and just linked with the rest of the projects. 23 24 That allows you to use advanced compilers generating faster code for 25 the critical part of the demo. The drawback is that such manipulation 26 is difficult and should be reserved for really critical code. 27 This is really useful only on intel. */ 28 29 /* In this version, we just include the Be headers. That's the only Be 30 specific part. To break that dependencies, just switch that #if 31 statement to 0. */ 32 33 #if 1 34 35 #include <SupportDefs.h> 36 #include <GraphicsDefs.h> 37 #include <DirectWindow.h> 38 39 #else 40 41 typedef enum { 42 B_RGB32 = 0x0008, 43 B_RGBA32 = 0x2008, 44 B_RGB16 = 0x0005, 45 B_RGB15 = 0x0010, 46 B_RGBA15 = 0x2010, 47 B_CMAP8 = 0x0004, 48 B_RGB32_BIG = 0x1008, 49 B_RGBA32_BIG = 0x3008, 50 B_RGB16_BIG = 0x1005, 51 B_RGB15_BIG = 0x1010, 52 B_RGBA15_BIG = 0x3010 53 } color_space; 54 55 typedef signed char int8; 56 typedef unsigned char uint8; 57 typedef short int16; 58 typedef unsigned short uint16; 59 typedef long int32; 60 typedef unsigned long uint32; 61 typedef unsigned char bool; 62 #define false 0 63 #define true 1 64 65 typedef struct { 66 int32 left; 67 int32 top; 68 int32 right; 69 int32 bottom; 70 } clipping_rect; 71 72 #endif 73 74 /* Rounding is always done in C-standard mode */ 75 #define ROUNDING 0.5 76 77 /* Count of different light level available for a star. */ 78 #define LEVEL_COUNT 32 79 /* Used to mark the last drawing offset of a star as unused 80 (the star was invisible last time we tried drawing it) */ 81 #define INVALID 0x10000000 82 /* Clipping is done in 2 pass. A pixel clipping handle the 83 real window visibility clipping. A geometric clipping 84 sort out all stars that are clearly out of the pyramid 85 of vision of the full-window. As star are bigger than 86 just a pixel, we need a error margin to compensate for 87 that, so that we don't clipped out star that would be 88 barely visible on the side. */ 89 #define BORDER_CLIPPING 0.01 90 91 /* the three drawing row-format. */ 92 #define PIXEL_1_BYTE 0 93 #define PIXEL_2_BYTES 1 94 #define PIXEL_4_BYTES 2 95 96 /* This is the generic definition of a drawing buffer. This 97 can describe both an offscreen bitmap or a directwindow 98 frame-buffer. That the layer that allows us to abstract 99 our real drawing buffer and make our drawing code indepen- 100 dant of its real target, so that it's trivial to switch 101 from Bitmap mode to DirectWindow mode. */ 102 typedef struct { 103 /* base address of the buffer. */ 104 void *bits; 105 /* count of bytes between the begining of 2 lines. */ 106 int32 bytes_per_row; 107 /* count of bytes per pixel. */ 108 int32 bytes_per_pixel; 109 /* row-format of the buffer (PIXEL_1_BYTE, PIXEL_2_BYTES 110 or PIXEL_4_BYTES. */ 111 int32 depth_mode; 112 /* buffer dimensions. */ 113 int32 buffer_width; 114 int32 buffer_height; 115 /* color_space of the buffer. */ 116 color_space depth; 117 /* 7x8x32 bits words representing the row value of the 7 118 possible star color, at 8 different light levels. If 119 the pixel encoding doesn't use 4 bytes, the color 120 value is repeated as many as necessary to fill the 121 32 bits. */ 122 uint32 colors[7][8]; 123 /* same color value, for the background color of the 124 buffer. */ 125 uint32 back_color; 126 /* clipping of the buffer, in the standard DirectWindow 127 format. */ 128 uint32 clip_list_count; 129 clipping_rect clip_bounds; 130 clipping_rect clip_list[64]; 131 /* base address of the buffer offset by the delta offset 132 of the 32 different bits used to render the different 133 size of stars. */ 134 void *pattern_bits[32]; 135 } buffer; 136 137 /* this strcuture is used to represent a star. */ 138 typedef struct { 139 /* position of the star in a [0-1]x[0-1]x[0-1] cube */ 140 float x; 141 float y; 142 float z; 143 /* size coefficient. Some star are bigger than others */ 144 float size; 145 /* color profile of the star (between the 7 existing colors */ 146 uint8 color_type; 147 /* lighting level */ 148 uint8 level; 149 /* pattern level. Used to design which representation of star 150 will be used, depending of the ligthing level and the half- 151 pixel alignment. */ 152 uint16 pattern_level; 153 /* screen coordinate, relative to the center */ 154 int16 h; 155 int16 v; 156 /* if the star was drawn at the previous frame, this contains 157 the drawing offset of the reference pixel in the buffer. 158 Then last_draw_pattern contains the mask of bits really 159 draw in the star pixel pattern (32 pixels max). 160 If the star wasn't draw, last_draw_offset contains INVALID */ 161 int32 last_draw_offset; 162 int32 last_draw_pattern; 163 } star; 164 165 /* struct defining a collection of star. Include a array of stars, 166 the count of currently used members of the array (the array can 167 be bigger and only partialy used, and the previous value of that 168 count (call erase_count) that define which stars were drawn 169 before, and so need to be erase for this frame. */ 170 typedef struct { 171 star *list; 172 int32 count; 173 int32 erase_count; 174 } star_packet; 175 176 /* this struct define the full geometry of the camera looking at 177 the star field. */ 178 typedef struct { 179 /* position of the camera in the extended [0-2]x[0-2]x[0-2] 180 cube. */ 181 float x; 182 float y; 183 float z; 184 /* those values define the limit below which stars should be 185 virtually duplicate in extended space. That allows to move 186 the [0-1]x[0-1]x[0-1] star cube (as a cycling torus on the 187 3 axis), to any position inside the [0-2]x[0-2]x[0-2] cube. 188 The pyramid of vision is designed to be always included 189 inside a [0-1]x[0-1]x[0-1]. So all stars are defined in 190 such a small cube, then the cube will cycle using those 191 3 variables (for example, cutx = 0.3 will virtually cut 192 the [0-0.3]x[0-1]x[0-1] of the cube and duplicate it at 193 [1.0-1.3]x[0-1]x[0-1], creating a [0.3-1.3]x[0-1]x[0-1] 194 star field. Doing the same thing on the 3 axis, allows 195 to cycle the starfield wherever it's needed to fully 196 include the pyramid of vision. That way, the camera 197 always look at a properly positionned 1x1x1 starfield... */ 198 float cutx; 199 float cuty; 200 float cutz; 201 /* rotation matrix of the camera */ 202 float m[3][3]; 203 /* offset of the center of the camera vision axis in the window */ 204 float offset_h, offset_v; 205 /* min and max ratio x/z or y/z defining the pyramid of vision 206 used for the first quick clipping. */ 207 float xz_min, xz_max, yz_min, yz_max; 208 /* min and max visibility threshold used for the front and rear 209 clipping, and the square factor used in the lighting formula */ 210 float z_min, z_max, z_max_square; 211 /* zoom factor of the camera, basically how large (in pixel) a 212 object of size 1.0 at a depth of 1.0 would look like */ 213 float zoom_factor; 214 } geometry; 215 216 /* offset (horizontal and vertical) of the 32 pixels used to 217 represent different sizes of stars. */ 218 extern int8 pattern_dh[32]; 219 extern int8 pattern_dv[32]; 220 221 /* the public API of th animation module */ 222 /* first time init */ 223 void InitPatterns(); 224 /* used to move/draw/erase a colection of star in specific buffer */ 225 void RefreshStarPacket(buffer *buf, star_packet *sp, geometry *geo); 226 /* used to update the visibility status of a collection of stars 227 after the clipping changed. */ 228 void RefreshClipping(buffer *buf, star_packet *sp); 229 230 #endif 231