3D Graphics


Typedefs

typedef short fixed_t

Functions

void cy3d_draw_background (char *buff, color_t sky_clr, color_t floor_clr)
void cy3d_draw_sky (char *buff, color_t clr)
void cy3d_draw_map_buffer (char *dst, char *src)
void cy3d_draw_map_buffer_xor (char *dst, char *src)
void cy3d_mirror_buffer (char *buff)
void cy3d_draw_tex_column (char *buff, int ray, fixed_t y, raster_t *tex, int index, int column, int shift, int *zbuff)
void cy3d_draw_sprite (char *buff, point_t p, raster_t *spr, int index, int *zbuff)
void cy3d_draw_wall (char *buff, point_t p1, point_t p2, raster_t *tex, int index, int shift, int *zbuff)
raster_tcy3d_load (char *name)
raster_tcy3d_load_tex (int index)
raster_tcy3d_load_spr (int index)
fixed_t cy3d_sin (int direction)
fixed_t cy3d_cos (int direction)
int cy3d_sqrt (long value)
point_t cy3d_warp (point_t p, point_t camera, int direction)
point_t cy3d_move (point_t p, fixed_t distance, int direction)
pos_t cy3d_pos (point_t p)
point_t cy3d_point (pos_t p)
fixed_t cy3d_distance (point_t p1, point_t p2)
long cy3d_distance2 (point_t p1, point_t p2)


Compounds

     struct   point_tA point on a plane, with the coordinates represented by fixed point (8.8) values
     struct   pos_tA point on a plane, with the coordinates represented by integer values
     struct   raster_tA collection of sprites or textures used by the CyOS 3D library


Detailed Description

These functions implement Wolfenstein3D/Ultima Underworld style graphics -- they simplify creation of your own 3D worlds. Please, pay special attention to the cy3d_draw_sprite() and cy3d_draw_wall() functions.


Typedef Documentation

typedef short fixed_t
 

Values with the fixed point ( 8.8 ).

Values with the fixed point ( 8.8 ). The 8 high bits represent the integer. The 8 low bits represent a fraction. (i.e. 0x0F80 is 15.5).


Function Documentation

fixed_t cy3d_cos ( int direction )
 

Calculates the cosine of the angle.

Parameters:
direction   Value of the angle (in degrees). Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
Cosine of the angle
See also:
cy3d_sin.

fixed_t cy3d_distance ( point_t p1,
point_t p2 )
 

Retrieves the distance between two points.

Parameters:
p1   Position of the first point
p2   Position of the second point Note: cy3d.dl must be loaded to the Cybiko computer
Returns:
the distance between two points.
See also:
cy3d_distance2.

long cy3d_distance2 ( point_t p1,
point_t p2 )
 

Retrieves the square of the distance between the two points.

Parameters:
p1   Position of the first point.
p2   Position of the second point. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
Square of the distance between the two points
   #include <cywin.h>
   ...
   long lSDistance;
   point_t first_location;
   point_t second_location;
   ...
   //Retrieves the square of the distance between the two points.
   lSDistance = cy3d_distance2( first_location, second_location );
   ...
See also:
cy3d_distance.

void cy3d_draw_background ( char * buff,
color_t sky_clr,
color_t floor_clr )
 

Fills the top and bottom of the screen with the specified colors.

Parameters:
buff   Pointer to the video buffer.
sky_clr   Color of the top of the screen
floor_clr   Color of the bottom of the screen. Note: cy3d.dl must be loaded on the Cybiko computer.
Returns:
None

void cy3d_draw_map_buffer ( char * dst,
char * src )
 

Copies from the source video buffer to the destination video buffer performing bitwise OR.

Parameters:
dst   Pointer to the destination video buffer.
src   Pointer to the source video buffer. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
None

void cy3d_draw_map_buffer_xor ( char * dst,
char * src )
 

Copies from the source video buffer to the destination video buffer performing bitwise XOR.

Parameters:
dst   Pointer to the destination video buffer.
src   Pointer to the source video buffer. Note: cy3d.dl must be loaded on the Cybiko computer.
Returns:
None.

void cy3d_draw_sky ( char * buff,
color_t clr )
 

Fills the top part of the screen with the specified color.

Parameters:
buff   Pointer to the video buffer
clr   Color of the screen top Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
None
   #include <cywin.h>
   ...
   struct module_t main_module;
   ...
   init_module( &main_module );
   ...
   char* ptr_video_page =
     DisplayGraphics_get_page_ptr( main_module.m_gfx, 0 );
   ...
   cy3d_draw_sky( ptr_video_page, CLR_LTGRAY );
   ...

void cy3d_draw_sprite ( char * buff,
point_t p,
raster_t * spr,
int index,
int * zbuff )
 

Draws a sprite in the specified position in the 3D world.
Parts of the image that are not visible will be truncated (due to the z-buffer).

Parameters:
buff   Pointer to the video buffer
p   Position of the sprite in the 3D world
spr   Pointer to the collection of the sprites
index   The sprite's index in the sprite collection
zbuff   Pointer to the z-buffer. Note: cy3d.dl must be loaded on the Cybiko computer.
Returns:
None
   #include <cywin.h>
   ...
   // Coordinates of the Cybiko sign (sprite) in the scene.
   point_t sign_location[ 2 ] =
   {
     { 0, 512 }, { 0, -512 }
   };
   ...
   void render_objects( char* ptr_gfx_buffer,
     point_t camera, int direction, int* z_buffer )
   {
    int index;
    ...
    // Transforms and renders column.
    for( index = 0; index < MAX_COLUMN; index++ )
    {
      cy3d_draw_sprite( ptr_gfx_buffer,
        cy3d_warp( column_location[ index ], camera, direction ),
          ptr_column, 0, z_buffer );
    }
    // Transforms and renders signs.
    for( index = 0; index < MAX_SIGN; index++ )
    {
      int effective_index = ( camera.p_y > 0 ) ? 1 - index : index ;
      ...
      cy3d_draw_sprite( ptr_gfx_buffer,
        cy3d_warp( sign_location[ effective_index ], camera, direction ),
          ptr_sign, sign_frame, z_buffer );
    }
     sign_frame++;
     sign_frame %= 19;
   }
   ...
See also:
cy3d_draw_wall.

void cy3d_draw_tex_column ( char * buff,
int ray,
fixed_t y,
raster_t * tex,
int index,
int column,
int shift,
int * zbuff )
 

Draws a column of the texture.
This is useful for rendering the walls in the 3D world. The corresponding element of the z-buffer will be updated.

Parameters:
buff   Pointer to the video buffer
ray   Index ( 0 - 159 ). tg( angle ) = ( 80 - ray ) / 100
y   y-coordinate of the column in the 3D world
tex   Pointer to the texture collection
index   Texture's index in the collection
column   Column's index in the texture ( 0 - 31 )
shift   Shifts the texture to vertical
zbuff   Pointer to the z-buffer. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
None

void cy3d_draw_wall ( char * buff,
point_t p1,
point_t p2,
raster_t * tex,
int index,
int shift,
int * zbuff )
 

Draws wall in the 3D world.

Parameters:
pointer   To the video buffer
p1   Starting point of the of the wall in the 3D world
p2   Ending point of the of the wall in the 3D world
tex   Pointer to the texture collection
index   Texture's index in the collection
shift   Shifts the texture to vertical
zbuff   Pointer to the z-buffer. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
None
   #include <cywin.h>
   ...
   int iIndex, iShift, *Z_buff, iDirection;
   raster_t* ptr_walls_tex;
   char* ptr_gfx_buffer;
   point_t camera;
   ...
   struct Wall
   {
    point_t p1;
    point_t p2;
   };
   ...
   struct Wall* ptr_wall;
   ...
   cy3d_draw_wall( ptr_gfx_buffer,
      cy3d_warp( ptr_wall->p1, camera, iDirection ),
      cy3d_warp( ptr_wall->p2, camera, iDirection ),
      ptr_walls_tex,
      iIndex,
      iShift,
      Z_buff );
   ...
See also:
cy3d_draw_sprite.

raster_t * cy3d_load ( char * name )
 

Loads the image collection with the specified name.
If the name of the file ends with the ".spr" the size of the image will be set to 256. Otherwise it will be set to 128. Note: The collection must be linked to the application using the filer utility.

Parameters:
name   Name of the image collection. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
Pointer to the image collection
   #include <cywin.h>
   ...
   raster_t* ptr_coll;
   ...
   ptr_coll = cy3d_load( "sign.spr" );
   ...
   free( ptr_coll );
   ...
   ptr_coll = cy3d_load( "wall.tex" );
   ...
   free( ptr_coll );
   ...
See also:
cy3d_load_tex, cy3d_load_spr.

raster_t * cy3d_load_spr ( int index )
 

Loads the sprite collection with the specified index in the application resource list.
Size of the image will be set to 256. Note: The collection must be linked to the application using the filer utility.

Parameters:
index   Index of the collection in the application resource list. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
Pointer to the sprite collection
   #include <cywin.h>
   ...
   raster_t* ptr_obj_spr;
   ...
   ptr_obj_spr = cy3d_load_spr( 5 );
   ...
   free( ptr_obj_spr );
   ...
See also:
cy3d_load, cy3d_load_tex.

raster_t * cy3d_load_tex ( int index )
 

Loads the texture collection with the specified index in the application resource list.
Size of the image will be set to 128. Note: The collection must be linked to the application using filer utility.

Parameters:
index   Index of the collection in the application resource list. Note: cy3d.dl must be loaded on the Cybiko computer.
Returns:
Pointer to the texture collection.
   #include <cywin.h>
   ...
   raster_t* ptr_walls_tex;
   ...
   ptr_walls_tex = cy3d_load_tex( 1 );
   ...
   free( ptr_walls_tex );
   ...
See also:
cy3d_load, cy3d_load_spr.

void cy3d_mirror_buffer ( char * buff )
 

Copies the top part of the screen to the bottom part of the screen.

Parameters:
buff   Pointer to the video buffer. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
None
   #include <cywin.h>
   ...
   struct module_t main_module;
   ...
   init_module( &main_module );
   ...
   char* ptr_video_page =
     DisplayGraphics_get_page_ptr( main_module.m_gfx, 0 );
   ...
   cy3d_mirror_buffer( ptr_video_page );
   ...

point_t cy3d_move ( point_t p,
fixed_t distance,
int direction )
 

Moves a point by a fixed distance in the specified direction.

Parameters:
p   Starting coordinate of the point
distance   Distance the point is to move
direction   Direction of the movement. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
Position of the point after it has moved
   #include <cywin.h>
   ...
   point_t new_position;
   ...
   if( DirectKeyboard_is_key_pressed( ptr_keyboard, KEY_UP ))
   {
     new_position = cy3d_move( camera, 64, direction );
     ...
     if( is_position_acceptable( new_position ))
     {
       camera = new_position;
     }
   }
   ...

point_t cy3d_point ( pos_t p )
 

Converts the point's coordinates from integer values to fixed point (8.8) values.

Parameters:
p   The point's coordinates, represented by integer values. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
The point's coordinates, represented by fixed point (8.8) values

pos_t cy3d_pos ( point_t p )
 

Converts the point's coordinates, from fixed point (8.8) values to integer values.

Parameters:
p   The point's coordinates, represented by fixed point ( 8.8 ) values. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
The pointer's coordinates, represented by integer values

fixed_t cy3d_sin ( int direction )
 

Calculates sine of the angle.

Parameters:
direction   The angle's value (in degrees). Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
Sine of the angle
See also:
cy3d_cos.

int cy3d_sqrt ( long value )
 

Retrieves square root of the value.

Parameters:
value   Nonnegative value whose square root will be obtained Note: cy3d.dl must be loaded to the Cybiko computer.
Returns:
square root of the value.

point_t cy3d_warp ( point_t p,
point_t camera,
int direction )
 

Transforms the point's position in the 3D world to its position in the camera's coordinate system (i.e.
in this coordinate system, the camera is in (0, 0) and directed to the 0Y direction)

Parameters:
p   the point's position before transformation
camera   The camera's position
direction   The camera's direction. Note: cy3d.dl must be loaded on the Cybiko computer
Returns:
the point's position after transformation
   #include <cywin.h>
   ...
   // Coordinates of the Cybiko sign (sprite) in the scene.
   point_t sign_location[ 2 ] =
   {
     { 0, 512 }, { 0, -512 }
   };
   ...
   void render_objects( char* ptr_gfx_buffer,
     point_t camera, int direction, int* z_buffer )
   {
    int index;
    ...
    // Transforms and renders column.
    for( index = 0; index < MAX_COLUMN; index++ )
    {
      cy3d_draw_sprite( ptr_gfx_buffer,
        cy3d_warp( column_location[ index ], camera, direction ),
          ptr_column, 0, z_buffer );
    }
    // Transforms and renders signs.
    for( index = 0; index < MAX_SIGN; index++ )
    {
      int effective_index = ( camera.p_y > 0 ) ? 1 - index : index ;
      ...
      cy3d_draw_sprite( ptr_gfx_buffer,
        cy3d_warp( sign_location[ effective_index ], camera, direction ),
          ptr_sign, sign_frame, z_buffer );
    }
     sign_frame++;
     sign_frame %= 19;
   }
   ...