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