Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
water.h File Reference

Jo Engine water: a sea with waves around the camera (see below), objects seen through it, floating hulls. More...

Go to the source code of this file.

Data Structures

struct  jo_water_wave
 A wave of the swell (a sine along a direction). More...
struct  jo_water_level
 A level of the grid. More...
struct  jo_water_steps
 Gouraud steps per channel (16: the color as it is). More...
struct  jo_water_config
 Configuration of the water (jo_water_default_config(), then change what you need). More...
struct  jo_water_point
 Height and slopes of the surface at a point (see jo_water_sample()). More...
struct  jo_water_floating
 An object that falls in the water and floats on the waves (a crate, a barrel, a buoy): see jo_water_float(). More...

Macros

#define JO_WATER_MAX_WAVES
 Waves at most in the swell.
#define JO_WATER_MAX_LEVELS
 Levels at most.
#define JO_WATER_MAX_CELLS
 Quads on a side of a level at most.
#define JO_WATER_MAX_OBJECTS
 Objects under the water at most.
#define JO_WATER_MAX_ABOVE
 Objects above the water given in a frame at most (see jo_water_add_above()).
#define JO_WATER_DIP_LEVELS
 Depth levels of a jo_water_dip at most.

Typedefs

typedef struct s_jo_water jo_water
 The water (see jo_water_create()).
typedef struct s_jo_water_object jo_water_object
 An object under the water (see jo_water_add_model()).
typedef struct s_jo_water_dip jo_water_dip
 An object on the water whose polygons under the surface are seen through the water (the hull of a boat, of a jet ski: see jo_water_add_dip()).

Enumerations

enum  jo_water_look_kind {
  JO_WATER_LOOK_DEFAULT , JO_WATER_LOOK_MINT_LAGOON , JO_WATER_LOOK_TROPICAL_TEAL , JO_WATER_LOOK_MERMAID_BLUE ,
  JO_WATER_LOOK_OCEAN_BLUE , JO_WATER_LOOK_FRENCH_BLUE , JO_WATER_LOOK_DEEP_CONTRAST , JO_WATER_LOOK_BRIGHT_TURQUOISE ,
  JO_WATER_LOOK_CARIBBEAN , JO_WATER_LOOK_DEEP_PACIFIC , JO_WATER_LOOK_SUNNY_BEACH , JO_WATER_LOOK_COUNT
}
 The standard looks of the water (its color and the light of its waves, see jo_water_config_look()). More...
enum  jo_water_swell_kind { JO_WATER_SWELL_GENTLE , JO_WATER_SWELL_CHOPPY , JO_WATER_SWELL_STORM , JO_WATER_SWELL_COUNT }
 The standard swells (see jo_water_swell()): waves of 130 to 700 units, for quads of 16 to 64 units near the camera (jo_water_config.levels: a wave is drawn on the levels with min_cells_per_wave quads per wavelength). More...

Functions

void jo_water_default_config (jo_water_config *const config)
 A configuration that works: 4 levels (quads of 8, 16, 32, 64 units), the swell JO_WATER_SWELL_CHOPPY, the look JO_WATER_LOOK_DEFAULT.
static __jo_force_inline void __water_set_look (jo_water_config *const config, const jo_color color, const signed char shallow_r, const signed char shallow_g, const signed char shallow_b, const signed char deep_r, const signed char deep_g, const signed char deep_b, const int sky, const int slope_light_min, const int slope_light_max, const int glint)
 Set the values of a look (see jo_water_config_look()).
static __jo_force_inline void jo_water_config_look (jo_water_config *const config, const jo_water_look_kind look)
 Set a standard look in a configuration: color, shallow, deep, sky, slope_light_min, slope_light_max, glint (the rest as it is; for a water already made: then jo_water_set_look()).
static __jo_force_inline int jo_water_look_blend (const jo_water_look_kind look)
 The mix of the water with the bottom of the sea that goes with a standard look (see jo_water_blend_with_bottom()).
static __jo_force_inline void jo_water_blend_with_bottom (const int blend)
 The water seen through: the VDP2 mixes the RGB pixels of the sprites (the water, the objects under it, see jo_water_add_model()) with the screen behind them (the bottom of the sea: RBG0 for instance); the pixels of the palette stay opaque (the objects above the water: their colors in the color RAM with the MSB at 0).
static __jo_force_inline void __water_set_wave (jo_water_wave *const wave, const int length, const int direction, const jo_fixed height, const int period)
 Set a wave (see jo_water_swell()).
static __jo_force_inline int jo_water_swell (jo_water_wave *const waves, const jo_water_swell_kind swell)
 A standard swell (its directions not along the grid of the water).
jo_water * jo_water_create (const jo_water_config *const config)
 Create the water: load the textures, create the grid.
void jo_water_update (jo_water *const w, const int frame, const int x, const int y, const int z, const jo_angle heading)
 Move the waves to the time of the frame and the grid around the camera, compute the heights and the light.
void jo_water_draw (jo_water *const w)
 Draw the water (after jo_3d_camera_look_at()).
void jo_water_draw_with (jo_water *const w, void(*objects)(void), void(*objects_on_slave)(void))
 Draw the water and the objects on it: the master CPU draws some objects while the slave CPU draws the water near the camera, then other objects (the time of the drawing on both CPUs: the slave CPU computes fewer waves, see the balance of jo_water_update()).
int jo_water_quad_side (const jo_water *const w, const int x, const int z)
 Side of the quads of the water drawn at a point (the finest level that covers it, see jo_water_config.levels): an object seen through the water (under it) is sorted nearer than the point where it is seen by about half of it (a quad is sorted at its center).
jo_fixed jo_water_height (const jo_water *const w, const int x, const int z)
 Height of the surface at a point (the waves, the splashes, the wave fronts at the time of jo_water_update()).
jo_fixed jo_water_drawn_height (const jo_water *const w, const int x, const int z)
 Height of the surface as it is drawn at a point (the vertices of the finest level that covers it, interpolated): cheap (no sine), for many points (along a line of sight); the waves (jo_water_wave_height()) outside of the levels.
jo_fixed jo_water_wave_height (const jo_water *const w, const int x, const int z)
 Height of the waves at a point, without the splashes and the wave fronts (faster than jo_water_height(): many points, for instance along a line of sight).
void jo_water_sample (const jo_water *const w, const int x, const int z, jo_water_point *const point)
 Height and slopes of the surface at a point: for an object on the water (its height, its tilt).
void jo_water_floating_init (jo_water_floating *const f, const int x, const int z, const int height, const int half, const int sink)
 Start an object above the water (it falls, see jo_water_float()).
void jo_water_float (jo_water *const w, jo_water_floating *const f)
 Move a floating object (once per frame, after jo_water_update()): it falls (gravity), splashes in the water (a ring of waves as high as its speed, see jo_water_drop()), then floats: a damped spring toward the surface under it, tilted with the slope of the surface (jo_water_sample()).
void jo_water_set_waves (jo_water *const w, const jo_water_wave *const waves, const int count)
 Change the swell (a calm sea, a storm, the wind turns).
void jo_water_set_swell (jo_water *const w, const jo_fixed scale)
 Strength of the swell: the heights of the waves x scale (a storm that grows, a calm that comes).
void jo_water_drop (jo_water *const w, const int x, const int z, const int height)
 An object falls in the water: a ring of waves goes away from the point (near the camera only).
void jo_water_wave_front (jo_water *const w, const int x, const int z, const jo_angle direction, const int height, const int width)
 A straight wave (2 crests, the second one the highest) that goes from a point in a direction: it grows, then fades out (a half sine over config.front_life frames; near the camera only).
void jo_water_foam (jo_water *const w, const int x, const int z, const int radius, const int life)
 Foam on the water (a trail, a wake, a splash): a disc of the foam grid (cells of 8 units around the camera, 1024 units: the foam out of it is lost), white at once, it fades out in life frames (the foam already there and longer is kept). The quads near the camera get the foam texture, more of it with more foam.
void jo_water_set_depth_map (jo_water *const w, const unsigned char *const map, const int size, const int shift, const int x, const int z)
 The depth of the water around (a map of bytes: 0 the shore, 255 deep): the shallow water is lighter (config.shore), the waves break on the shore (config.surf).
int jo_water_foam_at (const jo_water *const w, const int x, const int z)
 Foam at a point (0 to 255, see jo_water_foam()).
void jo_water_set_sun (jo_water *const w, const jo_angle azimuth, const jo_angle elevation)
 Position of the sun (the light, the glints, the spot).
void jo_water_set_textured (jo_water *const w, const bool textured)
 The foam texture or not (see jo_water_config.textured).
const jo_water_config * jo_water_get_config (const jo_water *const w)
 The configuration of the water (read only: the look can be changed with jo_water_set_look()).
jo_color jo_water_seen_color (const jo_water *const w, const jo_color object, const int amount)
 The color of the water seen from above (its color with the light of config.shallow: the face of a wave toward the camera), 5 to 21 steps per channel (a gouraud of 16 +/- 5 stays in 0 to 31): the color of an object under the water is mixed with it.
void jo_water_set_look (jo_water *const w, const jo_water_config *const look)
 Change the look (the colors and the light: color, shallow, deep, sky, slope_light_min/max, glint, spot, spot_distance, caustics, reflection, foam_white, foam_color, shore, shallow_depth, surf, bottom, bottom_depth, see_through, grain of the configuration).
int jo_water_add_model (jo_water *const w, jo_3d_model *const model, const int amount, const int far, jo_water_object **const objects)
 Put a model under the water: an object per group of the model (OBJ o or g: a rock, the foot of a pillar, a part of a wreck; the whole model if it has no group). Its colors become its colors seen through the water: RGB colors, colors of the palette, textures of 16 colors (a color lookup table of 32 bytes each, the pixels are not copied) and RGB textures (copied); its gouraud shading stays, not lit (the light of the sun under the water is diffuse).
jo_water_object * jo_water_add_mesh (jo_water *const w, jo_3d_mesh *const mesh, const int first, const int count, const int amount, const int far)
 Put polygons of a mesh under the water (see jo_water_add_model()): a mesh made by the program, its points changed in any frame (see jo_water_reshape()).
void jo_water_place (jo_water_object *const o, const int x, const int y, const int z, const jo_angle heading)
 Place the space of an object (the space of the points of its mesh): the world by default.
void jo_water_show (jo_water_object *const o, const bool shown, const unsigned int hidden)
 Show or hide an object, hide some of its polygons.
void jo_water_reshape (jo_water_object *const o)
 The points of the mesh of an object changed: its size and its depth again (after jo_water_show(): only the polygons drawn).
void jo_water_set_far (jo_water_object *const o, const int far)
 Change the distance where an object is not drawn any more (units: |dx| + |dz|).
void jo_water_add_above (jo_water *const w, const int x, const int y, const int z, const int radius, const int key_offset)
 An object above the water in front of which the objects under the water stay (a jet ski, a buoy, a boat): an object under the water that it covers on the screen is sorted behind it. Call it each frame before jo_water_draw_with() (forgotten after it).
jo_water_dip * jo_water_add_dip (jo_water *const w, jo_3d_mesh *const mesh, const int levels, const short *const amounts, const jo_fixed *const depths, const int palette_offset)
 Prepare a floating object: its polygons under the surface take their colors seen through the water, deeper: more of the water (see jo_water_dip_mesh()); its own attributes are kept for the polygons above the jo_water.
void jo_water_dip_mesh (jo_water_dip *const d, const jo_fixed surface, const jo_angle pitch, const jo_angle roll)
 Set the colors of the polygons of a floating object from the depth of their middles under the surface (call it before it is drawn).

Detailed Description

Jo Engine water: a sea with waves around the camera (see below), objects seen through it, floating hulls.

Author
Johannes Fetz
Remarks
With the 3D and the 2 CPUs (JO_COMPILE_WITH_3D_MODULE, the dual CPU support: on by default); in the program only when the game uses it (the link drops what is not called: its built-in patterns too, see tools/make_water_patterns.py)
Bug
No known bugs.

Data Structure Documentation

◆ jo_water_wave

struct jo_water_wave

A wave of the swell (a sine along a direction).

Data Fields
int direction
jo_fixed height
int length
int period

◆ jo_water_level

struct jo_water_level

A level of the grid.

Data Fields
int cell
int side

◆ jo_water_steps

struct jo_water_steps

Gouraud steps per channel (16: the color as it is).

Data Fields
signed char b
signed char g
signed char r

◆ jo_water_config

struct jo_water_config

Configuration of the water (jo_water_default_config(), then change what you need).

Data Fields
int ahead
int bottom
int bottom_depth
int caustics
jo_color color
jo_water_steps deep
int fade
jo_color foam_color
int foam_white
int front_length
int front_life
int front_speed
int glint
bool grain
int level_count
const jo_water_level * levels
int min_cells_per_wave
const char * patterns_file
int reflection
int see_through
jo_water_steps shallow
int shallow_depth
jo_water_steps shore
int skirt
int sky
int slave_levels
int slope_light_max
int slope_light_min
int splash_length
int splash_life
int splash_speed
int spot
int spot_distance
int surf
bool textured
int update_cell
int wave_count
const jo_water_wave * waves

◆ jo_water_point

struct jo_water_point

Height and slopes of the surface at a point (see jo_water_sample()).

Data Fields
jo_fixed height
jo_fixed slope_x
jo_fixed slope_z

◆ jo_water_floating

struct jo_water_floating

An object that falls in the water and floats on the waves (a crate, a barrel, a buoy): see jo_water_float().

Data Fields
int half
bool in_water
int sink
jo_angle tilt_x
jo_angle tilt_z
jo_fixed vy
int x
jo_fixed y
int z

Macro Definition Documentation

◆ JO_WATER_DIP_LEVELS

#define JO_WATER_DIP_LEVELS

Depth levels of a jo_water_dip at most.

◆ JO_WATER_MAX_ABOVE

#define JO_WATER_MAX_ABOVE

Objects above the water given in a frame at most (see jo_water_add_above()).

◆ JO_WATER_MAX_CELLS

#define JO_WATER_MAX_CELLS

Quads on a side of a level at most.

◆ JO_WATER_MAX_LEVELS

#define JO_WATER_MAX_LEVELS

Levels at most.

◆ JO_WATER_MAX_OBJECTS

#define JO_WATER_MAX_OBJECTS

Objects under the water at most.

◆ JO_WATER_MAX_WAVES

#define JO_WATER_MAX_WAVES

Waves at most in the swell.

Typedef Documentation

◆ jo_water

typedef struct s_jo_water jo_water

The water (see jo_water_create()).

◆ jo_water_dip

typedef struct s_jo_water_dip jo_water_dip

An object on the water whose polygons under the surface are seen through the water (the hull of a boat, of a jet ski: see jo_water_add_dip()).

◆ jo_water_object

typedef struct s_jo_water_object jo_water_object

An object under the water (see jo_water_add_model()).

Enumeration Type Documentation

◆ jo_water_look_kind

The standard looks of the water (its color and the light of its waves, see jo_water_config_look()).

Enumerator
JO_WATER_LOOK_DEFAULT 
JO_WATER_LOOK_MINT_LAGOON 
JO_WATER_LOOK_TROPICAL_TEAL 
JO_WATER_LOOK_MERMAID_BLUE 
JO_WATER_LOOK_OCEAN_BLUE 
JO_WATER_LOOK_FRENCH_BLUE 
JO_WATER_LOOK_DEEP_CONTRAST 
JO_WATER_LOOK_BRIGHT_TURQUOISE 
JO_WATER_LOOK_CARIBBEAN 
JO_WATER_LOOK_DEEP_PACIFIC 
JO_WATER_LOOK_SUNNY_BEACH 
JO_WATER_LOOK_COUNT 

◆ jo_water_swell_kind

The standard swells (see jo_water_swell()): waves of 130 to 700 units, for quads of 16 to 64 units near the camera (jo_water_config.levels: a wave is drawn on the levels with min_cells_per_wave quads per wavelength).

Enumerator
JO_WATER_SWELL_GENTLE 
JO_WATER_SWELL_CHOPPY 
JO_WATER_SWELL_STORM 
JO_WATER_SWELL_COUNT 

Function Documentation

◆ __water_set_look()

__jo_force_inline void __water_set_look ( jo_water_config *const config,
const jo_color color,
const signed char shallow_r,
const signed char shallow_g,
const signed char shallow_b,
const signed char deep_r,
const signed char deep_g,
const signed char deep_b,
const int sky,
const int slope_light_min,
const int slope_light_max,
const int glint )
static

Set the values of a look (see jo_water_config_look()).

◆ __water_set_wave()

__jo_force_inline void __water_set_wave ( jo_water_wave *const wave,
const int length,
const int direction,
const jo_fixed height,
const int period )
static

Set a wave (see jo_water_swell()).

◆ jo_water_add_above()

void jo_water_add_above ( jo_water *const w,
const int x,
const int y,
const int z,
const int radius,
const int key_offset )

An object above the water in front of which the objects under the water stay (a jet ski, a buoy, a boat): an object under the water that it covers on the screen is sorted behind it. Call it each frame before jo_water_draw_with() (forgotten after it).

Parameters
wWater (jo_water_create())
xIts center (units)
yIts center (units, y down)
zIts center (units)
radiusIts size (units)
key_offsetIts farthest sort key from the depth of its center (units: its depth bias, its size)

◆ jo_water_add_dip()

jo_water_dip * jo_water_add_dip ( jo_water *const w,
jo_3d_mesh *const mesh,
const int levels,
const short *const amounts,
const jo_fixed *const depths,
const int palette_offset )

Prepare a floating object: its polygons under the surface take their colors seen through the water, deeper: more of the water (see jo_water_dip_mesh()); its own attributes are kept for the polygons above the jo_water.

Parameters
wWater (jo_water_create())
meshMesh (its polygons as drawn above the water)
levelsDepth levels (JO_WATER_DIP_LEVELS at most)
amountsOf the color of the water at each level (/ 256)
depthsUnder the surface where each level starts (jo_fixed units of the mesh, the first one usually 0)
palette_offsetAdded to the colors of the palette before they are read (a mesh lit by the palette light: its colors are its darkest shade, see jo_3d_set_palette_light(): + shade x stride, the shade seen under the water)
Returns
JO_NULL if out of memory

◆ jo_water_add_mesh()

jo_water_object * jo_water_add_mesh ( jo_water *const w,
jo_3d_mesh *const mesh,
const int first,
const int count,
const int amount,
const int far )

Put polygons of a mesh under the water (see jo_water_add_model()): a mesh made by the program, its points changed in any frame (see jo_water_reshape()).

Parameters
wWater (jo_water_create())
meshMesh
firstFirst polygon of the object
countPolygons
amountOf the color of the water (/ 256)
farNot drawn farther from the camera (units: |dx| + |dz|)
Returns
JO_NULL if too many objects or out of memory

◆ jo_water_add_model()

int jo_water_add_model ( jo_water *const w,
jo_3d_model *const model,
const int amount,
const int far,
jo_water_object **const objects )

Put a model under the water: an object per group of the model (OBJ o or g: a rock, the foot of a pillar, a part of a wreck; the whole model if it has no group). Its colors become its colors seen through the water: RGB colors, colors of the palette, textures of 16 colors (a color lookup table of 32 bytes each, the pixels are not copied) and RGB textures (copied); its gouraud shading stays, not lit (the light of the sun under the water is diffuse).

Parameters
wWater (jo_water_create())
modelModel (jo_3d_load_model(); its points in the world, or in the space of each object: see jo_water_place())
amountOf the color of the water seen from above in its colors (/ 256: 0 its own colors)
farNot drawn farther from the camera (units: |dx| + |dz|)
objectsThe objects, a group each (output, JO_NULL: not needed)
Returns
The number of objects, -1 if too many (JO_WATER_MAX_OBJECTS) or out of memory
Remarks
The mesh of the model is changed: draw it only through the jo_water

◆ jo_water_blend_with_bottom()

__jo_force_inline void jo_water_blend_with_bottom ( const int blend)
static

The water seen through: the VDP2 mixes the RGB pixels of the sprites (the water, the objects under it, see jo_water_add_model()) with the screen behind them (the bottom of the sea: RBG0 for instance); the pixels of the palette stay opaque (the objects above the water: their colors in the color RAM with the MSB at 0).

Parameters
blendOf the bottom: 0 (the water only) to 31 (almost only the bottom), see jo_water_look_blend()
Remarks
jo_vdp2_set_sprite_blend_ratios() after it for other ratios of palette pixels (its ratio 0: blend)

◆ jo_water_config_look()

__jo_force_inline void jo_water_config_look ( jo_water_config *const config,
const jo_water_look_kind look )
static

Set a standard look in a configuration: color, shallow, deep, sky, slope_light_min, slope_light_max, glint (the rest as it is; for a water already made: then jo_water_set_look()).

Parameters
configConfiguration (jo_water_default_config() first)
lookThe look

◆ jo_water_create()

jo_water * jo_water_create ( const jo_water_config *const config)

Create the water: load the textures, create the grid.

Parameters
configConfiguration (copied)
Returns
JO_NULL if the configuration is wrong (a message on the screen), a texture is missing or out of memory
Remarks
One water at a time (the jobs of the slave CPU)

◆ jo_water_default_config()

void jo_water_default_config ( jo_water_config *const config)

A configuration that works: 4 levels (quads of 8, 16, 32, 64 units), the swell JO_WATER_SWELL_CHOPPY, the look JO_WATER_LOOK_DEFAULT.

Parameters
configConfiguration (output)

◆ jo_water_dip_mesh()

void jo_water_dip_mesh ( jo_water_dip *const d,
const jo_fixed surface,
const jo_angle pitch,
const jo_angle roll )

Set the colors of the polygons of a floating object from the depth of their middles under the surface (call it before it is drawn).

Parameters
dFloating object (jo_water_add_dip())
surfaceThe surface in the space of the mesh (jo_fixed units, y down: the height of the object - the height of the water)
pitchIts pitch (jo_angle: turned around x after its roll, as drawn)
rollIts roll (jo_angle: turned around z first)

◆ jo_water_draw()

void jo_water_draw ( jo_water *const w)

Draw the water (after jo_3d_camera_look_at()).

◆ jo_water_draw_with()

void jo_water_draw_with ( jo_water *const w,
void(* objects )(void),
void(* objects_on_slave )(void) )

Draw the water and the objects on it: the master CPU draws some objects while the slave CPU draws the water near the camera, then other objects (the time of the drawing on both CPUs: the slave CPU computes fewer waves, see the balance of jo_water_update()).

Parameters
wWater (jo_water_create())
objectsDraws objects on the master CPU (jo_3d_mesh_draw()...), JO_NULL: none
objects_on_slaveDraws objects on the slave CPU after the water (jo_3d_slave_mesh_draw()..., the matrix of the camera; the slave CPU uses the light set before jo_water_draw_with()), JO_NULL: none

◆ jo_water_drawn_height()

jo_fixed jo_water_drawn_height ( const jo_water *const w,
const int x,
const int z )

Height of the surface as it is drawn at a point (the vertices of the finest level that covers it, interpolated): cheap (no sine), for many points (along a line of sight); the waves (jo_water_wave_height()) outside of the levels.

Parameters
wWater (jo_water_create())
xPosition (units)
zPosition (units)
Returns
Height (jo_fixed units, > 0 above the calm sea)
Remarks
After jo_water_update(); only the vertices in the view are updated (see the span culling): a point out of the view of the camera may give an old height

◆ jo_water_drop()

void jo_water_drop ( jo_water *const w,
const int x,
const int z,
const int height )

An object falls in the water: a ring of waves goes away from the point (near the camera only).

Parameters
wWater (jo_water_create())
xPosition (units)
zPosition (units)
heightHeight of the first wave (units)

◆ jo_water_float()

void jo_water_float ( jo_water *const w,
jo_water_floating *const f )

Move a floating object (once per frame, after jo_water_update()): it falls (gravity), splashes in the water (a ring of waves as high as its speed, see jo_water_drop()), then floats: a damped spring toward the surface under it, tilted with the slope of the surface (jo_water_sample()).

Parameters
wWater (jo_water_create())
fObject
Remarks
Draw it at (x, -y, z) (y down), rotated by tilt_x, then tilt_z

◆ jo_water_floating_init()

void jo_water_floating_init ( jo_water_floating *const f,
const int x,
const int z,
const int height,
const int half,
const int sink )

Start an object above the water (it falls, see jo_water_float()).

Parameters
fObject
xPosition (units)
zPosition (units)
heightHeight of its middle above the calm sea (units)
halfHalf its height (units)
sinkIt floats this much in the water (units)

◆ jo_water_foam()

void jo_water_foam ( jo_water *const w,
const int x,
const int z,
const int radius,
const int life )

Foam on the water (a trail, a wake, a splash): a disc of the foam grid (cells of 8 units around the camera, 1024 units: the foam out of it is lost), white at once, it fades out in life frames (the foam already there and longer is kept). The quads near the camera get the foam texture, more of it with more foam.

Parameters
wWater (jo_water_create())
xCenter (units)
zCenter (units)
radiusUnits (8 at least: a cell)
lifeFrames (60 per second, 1020 at most); the edge of the disc lives half as long (a soft edge)

◆ jo_water_foam_at()

int jo_water_foam_at ( const jo_water *const w,
const int x,
const int z )

Foam at a point (0 to 255, see jo_water_foam()).

◆ jo_water_get_config()

const jo_water_config * jo_water_get_config ( const jo_water *const w)

The configuration of the water (read only: the look can be changed with jo_water_set_look()).

◆ jo_water_height()

jo_fixed jo_water_height ( const jo_water *const w,
const int x,
const int z )

Height of the surface at a point (the waves, the splashes, the wave fronts at the time of jo_water_update()).

Parameters
wWater (jo_water_create())
xPosition (units)
zPosition (units)
Returns
Height (jo_fixed units, > 0 above the calm sea)

◆ jo_water_look_blend()

__jo_force_inline int jo_water_look_blend ( const jo_water_look_kind look)
static

The mix of the water with the bottom of the sea that goes with a standard look (see jo_water_blend_with_bottom()).

Parameters
lookThe look
Returns
Of the bottom: 0 (the water only) to 31 (almost only the bottom)

◆ jo_water_place()

void jo_water_place ( jo_water_object *const o,
const int x,
const int y,
const int z,
const jo_angle heading )

Place the space of an object (the space of the points of its mesh): the world by default.

Parameters
oObject (jo_water_add_model(), jo_water_add_mesh())
xPosition (units)
yPosition (units, y down)
zPosition (units)
headingTurned around y (jo_angle, as jo_3d_rotate_matrix_angle_y())

◆ jo_water_quad_side()

int jo_water_quad_side ( const jo_water *const w,
const int x,
const int z )

Side of the quads of the water drawn at a point (the finest level that covers it, see jo_water_config.levels): an object seen through the water (under it) is sorted nearer than the point where it is seen by about half of it (a quad is sorted at its center).

Parameters
wWater (jo_water_create())
xPosition (units)
zPosition (units)
Returns
Side (units); the side of the last level outside of the levels

◆ jo_water_reshape()

void jo_water_reshape ( jo_water_object *const o)

The points of the mesh of an object changed: its size and its depth again (after jo_water_show(): only the polygons drawn).

◆ jo_water_sample()

void jo_water_sample ( const jo_water *const w,
const int x,
const int z,
jo_water_point *const point )

Height and slopes of the surface at a point: for an object on the water (its height, its tilt).

Parameters
wWater (jo_water_create())
xPosition (units)
zPosition (units)
pointHeight and slopes (output)

◆ jo_water_seen_color()

jo_color jo_water_seen_color ( const jo_water *const w,
const jo_color object,
const int amount )

The color of the water seen from above (its color with the light of config.shallow: the face of a wave toward the camera), 5 to 21 steps per channel (a gouraud of 16 +/- 5 stays in 0 to 31): the color of an object under the water is mixed with it.

Parameters
wWater (jo_water_create())
objectThe color of the object
amountOf the water (/ 256)

◆ jo_water_set_depth_map()

void jo_water_set_depth_map ( jo_water *const w,
const unsigned char *const map,
const int size,
const int shift,
const int x,
const int z )

The depth of the water around (a map of bytes: 0 the shore, 255 deep): the shallow water is lighter (config.shore), the waves break on the shore (config.surf).

Parameters
wWater (jo_water_create())
mapsize x size bytes, the row z then the column x (JO_NULL: no map, deep everywhere)
sizeCells on a side (a power of 2)
shiftA cell is 1 << shift units
xCorner of the map (units)
zCorner of the map (units)
Remarks
Out of the map: deep

◆ jo_water_set_far()

void jo_water_set_far ( jo_water_object *const o,
const int far )

Change the distance where an object is not drawn any more (units: |dx| + |dz|).

◆ jo_water_set_look()

void jo_water_set_look ( jo_water *const w,
const jo_water_config *const look )

Change the look (the colors and the light: color, shallow, deep, sky, slope_light_min/max, glint, spot, spot_distance, caustics, reflection, foam_white, foam_color, shore, shallow_depth, surf, bottom, bottom_depth, see_through, grain of the configuration).

◆ jo_water_set_sun()

void jo_water_set_sun ( jo_water *const w,
const jo_angle azimuth,
const jo_angle elevation )

Position of the sun (the light, the glints, the spot).

Parameters
wWater (jo_water_create())
azimuthDirection (jo_angle, 0 = toward +z)
elevationHeight above the horizon (jo_angle)

◆ jo_water_set_swell()

void jo_water_set_swell ( jo_water *const w,
const jo_fixed scale )

Strength of the swell: the heights of the waves x scale (a storm that grows, a calm that comes).

Parameters
wWater (jo_water_create())
scalejo_fixed (JO_FIXED_1: the heights of the waves as they are)

◆ jo_water_set_textured()

void jo_water_set_textured ( jo_water *const w,
const bool textured )

The foam texture or not (see jo_water_config.textured).

◆ jo_water_set_waves()

void jo_water_set_waves ( jo_water *const w,
const jo_water_wave *const waves,
const int count )

Change the swell (a calm sea, a storm, the wind turns).

Parameters
wWater (jo_water_create())
wavesWaves (copied)
countJO_WATER_MAX_WAVES at most

◆ jo_water_show()

void jo_water_show ( jo_water_object *const o,
const bool shown,
const unsigned int hidden )

Show or hide an object, hide some of its polygons.

Parameters
oObject (jo_water_add_model(), jo_water_add_mesh())
shownDrawn (when it is in the view and near enough)
hiddenPolygons not drawn: bit k for the polygon k of the object (the first 32)

◆ jo_water_swell()

__jo_force_inline int jo_water_swell ( jo_water_wave *const waves,
const jo_water_swell_kind swell )
static

A standard swell (its directions not along the grid of the water).

Parameters
wavesThe waves (output: JO_WATER_MAX_WAVES; jo_water_create() and jo_water_set_waves() copy them)
swellThe swell
Returns
The number of waves

◆ jo_water_update()

void jo_water_update ( jo_water *const w,
const int frame,
const int x,
const int y,
const int z,
const jo_angle heading )

Move the waves to the time of the frame and the grid around the camera, compute the heights and the light.

Parameters
wWater (jo_water_create())
frameTime (frames, 60 per second: jo_core_get_vblank_count(), the waves move at the same speed at any frame rate)
xCamera position (units)
yCamera position (units, y down)
zCamera position (units)
headingDirection of the camera (jo_angle, 0 = toward +z)

◆ jo_water_wave_front()

void jo_water_wave_front ( jo_water *const w,
const int x,
const int z,
const jo_angle direction,
const int height,
const int width )

A straight wave (2 crests, the second one the highest) that goes from a point in a direction: it grows, then fades out (a half sine over config.front_life frames; near the camera only).

Parameters
wWater (jo_water_create())
xStart (units)
zStart (units)
directionDirection (jo_angle, 0 = toward +z)
heightHeight of the crests (units)
widthWidth of the wave (units)

◆ jo_water_wave_height()

jo_fixed jo_water_wave_height ( const jo_water *const w,
const int x,
const int z )

Height of the waves at a point, without the splashes and the wave fronts (faster than jo_water_height(): many points, for instance along a line of sight).

Parameters
wWater (jo_water_create())
xPosition (units)
zPosition (units)
Returns
Height (jo_fixed units, > 0 above the calm sea)