Changes to sprite animation system

* Changed the names of some of the functions
* Added functions for setting and returning the projection matrix of the active camera
* Added a function for getting the 2D screen coordinates from a 3D vector
* Added documentation for all the new functions
This commit is contained in:
n00b
2024-10-18 23:12:42 -04:00
parent 8f372bdf19
commit 5762c171ae
58 changed files with 457 additions and 5 deletions

8
doc/files/canvasz.txt Normal file
View File

@@ -0,0 +1,8 @@
#title CanvasZ [RCBasic Doc]
#header function CanvasZ(c_num)
Returns the Canvas Z Order.
Note: Canvases with a higher Z order are drawn first and those with lower values will be drawn on top
#ref SetCanvasZ

View File

@@ -0,0 +1,10 @@
#title CreatePlaneMesh [RCBasic Doc]
#header Function CreatePlaneMesh( w, h, tileCount_w, tileCount_h )
Creates a flat plane
#list
#li w, h - The width and height of the plane
#li tileCount_w, TileCount_h - The number of subdivisions across and down the plane
#/list

View File

@@ -0,0 +1,9 @@
#title CreateSpriteAnimation [RCBasic Doc]
#header Function CreateSpriteAnimation(sprite, anim_length, speed)
Returns a new sprite animation id
#list ul
#li anim_length - number of frames in the animation
#li speed - frames per second for the animation
#/list

View File

@@ -0,0 +1,4 @@
#title CreateWaterActor [RCBasic Doc]
#header function CreateWaterActor( mesh, waveHeight, waveSpeed, waveLength )
Creates an actor with water properties set on a base mesh

View File

@@ -0,0 +1,4 @@
#title GetAN8SceneName$ [RCBasic Doc]
#header Function GetAN8SceneName$(an8_project, scene_num)
Returns the name of a scene in an an8 project

View File

@@ -0,0 +1,6 @@
#title GetNumAN8Scenes [RCBasic Doc]
#header Function GetNumAN8Scenes(an8_project)
Returns the number of scenes in an an8 project
#ref LoadAN8

View File

@@ -0,0 +1,12 @@
#title GetProjectionMatrix [RCBasic Doc]
#header Sub GetProjectionMatrix(matA)
Gets the camera projection matrix for the active canvas
Possible values for projection_type
#list ul
#li PROJECTION_TYPE_ORTHOGRAPHIC
#li PROJECTION_TYPE_PERSPECTIVE
#/list
#ref SetProjectionMatrix

View File

@@ -0,0 +1,6 @@
#title GetSpriteAnimation [RCBasic Doc]
#header Function GetSpriteAnimation(sprite)
Returns the current animation set on a sprite
#ref SetSpriteAnimation

View File

@@ -0,0 +1,4 @@
#title GetSpriteAnimationFrame [RCBasic Doc]
#header Function GetSpriteAnimationFrame(sprite, animation, anim_frame)
Returns the frame index in the image source that is set to anim_frame in a sprite's animation

View File

@@ -0,0 +1,4 @@
#title GetSpriteAnimationLength [RCBasic Doc]
#header Function GetSpriteAnimationLength(sprite, animation)
Returns the number of frames in a sprite animation

View File

@@ -0,0 +1,4 @@
#title GetSpriteAnimationSpeed [RCBasic Doc]
#header Function GetSpriteAnimationSpeed(sprite, animation)
Returns the frames per second of a sprite animation

View File

@@ -0,0 +1,4 @@
#title GetSpriteCurrentAnimationFrame [RCBasic Doc]
#header Function GetSpriteCurrentAnimationFrame(sprite)
Returns the current frame of a sprite's animation

View File

@@ -0,0 +1,4 @@
#title GetSpriteFrame [RCBasic Doc]
#header Function GetSpriteFrame(sprite)
Returns the current frame in a sprite's source that it's on in its animation

View File

@@ -0,0 +1,6 @@
#title GetSpritePosition [RCBasic Doc]
#header Sub GetSpritePosition(sprite, ByRef x, ByRef y)
Gets the position of a sprite on the canvas
#ref TranslateSprite SetSpritePosition

View File

@@ -0,0 +1,6 @@
#title GetSpriteRotation [RCBasic Doc]
#header Function GetSpriteRotation(sprite)
Returns the angle the sprite is rotated by
#ref SetSpriteRotation RotateSprite

View File

@@ -0,0 +1,6 @@
#title GetSpriteScale [RCBasic Doc]
#header Sub GetSpriteScale(sprite, ByRef x, ByRef y)
Gets the scale of a sprite
#ref ScaleSprite SetSpriteScale

View File

@@ -0,0 +1,6 @@
#title GetSpriteSize [RCBasic Doc]
#header Sub GetSpriteSize(sprite, ByRef w, ByRef h)
Gets the size of a sprite's frames
#ref CreateSprite

View File

@@ -0,0 +1,6 @@
#title GetSpriteSource [RCBasic Doc]
#header Function GetSpriteSource(sprite)
Returns the source image the sprite renders its frames from
#ref SetSpriteSource CreateSprite

View File

@@ -0,0 +1,15 @@
#title GetSpriteType [RCBasic Doc]
#header Function GetSpriteType(sprite)
Returns the collison body type of a sprite.
By default, sprites are dynamic when they are created.
Possible types returned
#list ul
#li SPRITE_TYPE_STATIC
#li SPRITE_TYPE_KINEMATIC
#li SPRITE_TYPE_DYNAMIC
#/list
#ref SetSpriteType

View File

@@ -0,0 +1,4 @@
#title GetWorldToViewportPosition [RCBasic Doc]
#header Sub GetWorldToViewportPosition(x, y, z, ByRef x, ByRef y)
Get the 2D coordinates for the given 3D position on the active canvas

6
doc/files/loadan8.txt Normal file
View File

@@ -0,0 +1,6 @@
#title LoadAN8 [RCBasic Doc]
#header Function LoadAN8( an8_file$ )
Loads an an8 project and returns an id that can be used in LoadMeshFromAN8()
#ref LoadMeshFromAN8

View File

@@ -0,0 +1,8 @@
#title LoadMeshFromAN8 [RCBasic Doc]
#header Function LoadMeshFromAN8(an8_project, an8_scene$)
Loads the figures in an anim8or scene as a mesh
Note: This only loads figures from a scene and it loads meshes not anim8or objects
#ref LoadAN8 LoadMesh LoadMeshFromArchive

View File

@@ -0,0 +1,6 @@
#title NumSpriteAnimationLoops [RCBasic Doc]
#header Function NumSpriteAnimationLoops(sprite)
Returns the number of animation loops the actor has set
#ref SetSpriteAnimationLoops SetSpriteAnimation

8
doc/files/preupdate.txt Normal file
View File

@@ -0,0 +1,8 @@
#title PreUpdate [RCBasic Doc]
#header Sub PreUpdate( )
Processes physics for sprites and actors.
This is useful if you need to know the post solve positions and rotations prior to drawing them.
#ref Update

View File

@@ -0,0 +1,6 @@
#title RotateSprite [RCBasic Doc]
#header Sub RotateSprite(sprite, angle)
Sets the angle the sprite is rotated by relative to its current rotation
#ref SetSpriteRotation GetSpriteRotation

View File

@@ -0,0 +1,6 @@
#title ScaleSprite [RCBasic Doc]
#header Sub ScaleSprite(sprite, x, y)
Sets the scale of a sprite relative to its current scale
#ref SetSpriteScale GetSpriteScale

View File

@@ -0,0 +1,12 @@
#title SetCameraProjectionMatrix [RCBasic Doc]
#header Sub SetCameraProjectionMatrix(matA, projection_type)
Sets the camera projection matrix for the active canvas
Possible values for projection_type
#list ul
#li PROJECTION_TYPE_ORTHOGRAPHIC
#li PROJECTION_TYPE_PERSPECTIVE
#/list
#ref GetCameraProjectionMatrix

View File

@@ -3,6 +3,6 @@
Sets the Canvas Z Order. Sets the Canvas Z Order.
Note: Canvases with a lower Z order are drawn first and those with higher values will be drawn on top Note: Canvases with a higher Z order are drawn first and those with lower values will be drawn on top
#ref SetCanvasZ #ref SetCanvasZ

View File

@@ -0,0 +1,12 @@
#title SetProjectionMatrix [RCBasic Doc]
#header Sub SetProjectionMatrix(matA, projection_type)
Sets the camera projection matrix for the active canvas
Possible values for projection_type
#list ul
#li PROJECTION_TYPE_ORTHOGRAPHIC
#li PROJECTION_TYPE_PERSPECTIVE
#/list
#ref GetProjectionMatrix

View File

@@ -0,0 +1,8 @@
#title SetSpriteAnimation [RCBasic Doc]
#header Sub SetSpriteAnimation(sprite, animation)
Sets the current animation for a sprite
Note: Once an animation is set, it will automatically start
#ref GetSpriteAnimation

View File

@@ -0,0 +1,6 @@
#title SetSpriteAnimationFrame [RCBasic Doc]
#header Sub SetSpriteAnimationFrame(sprite, animation, anim_frame, frame)
Sets a frame in a sprite animation
#ref GetSpriteAnimationFrame

View File

@@ -0,0 +1,6 @@
#title SetSpriteAnimationLength [RCBasic Doc]
#header Sub SetSpriteAnimationLength(sprite, animation, anim_length)
Sets the number of frames in a sprite animation
#ref GetSpriteAnimationLength

View File

@@ -0,0 +1,6 @@
#title SetSpriteAnimationLoops [RCBasic Doc]
#header Sub SetSpriteAnimationLoops(sprite, num_loops)
Sets the number of animation loops for the sprite
#ref NumSpriteAnimationLoops

View File

@@ -0,0 +1,4 @@
#title SetSpriteAnimationSpeed [RCBasic Doc]
#header Sub SetSpriteAnimationSpeed(sprite, animation, speed)
Sets the speed in frames per second for a sprite animation

View File

@@ -0,0 +1,4 @@
#title SetSpriteFrame [RCBasic Doc]
#header Sub SetSpriteFrame(sprite, frame)
Sets a sprite to a frame in its frame sheet

View File

@@ -0,0 +1,7 @@
#title SetSpriteRotation [RCBasic Doc]
#header Sub SetSpriteRotation(sprite, angle)
Sets the angle the sprite is rotated by
#ref GetSpriteRotation RotateSprite

View File

@@ -0,0 +1,6 @@
#title SetSpriteScale [RCBasic Doc]
#header Sub SetSpriteScale(sprite, x, y)
Sets the scale of a sprite
#ref ScaleSprite GetSpriteScale

View File

@@ -0,0 +1,7 @@
#title SetSpriteSolid [RCBasic Doc]
#header Sub SetSpriteSolid(sprite, flag)
Sets whether a sprite has physics and collision response enabled
#ref SpriteIsSolid

View File

@@ -0,0 +1,8 @@
#title SetSpriteSource [RCBasic Doc]
#header Sub SetSpriteSource(sprite, img)
Changes the image source for a sprite frame sheet
Note: This needs to be the same size as the current image source or you will have rendering issues
#ref GetSpriteSource

View File

@@ -0,0 +1,12 @@
#title SetSpriteType [RCBasic Doc]
#header Sub SetSpriteType(sprite, sprite_type)
Sets the type of collision body a sprite has
#list ul
#li SPRITE_TYPE_STATIC
#li SPRITE_TYPE_KINEMATIC
#li SPRITE_TYPE_DYNAMIC
#/list
#ref GetSpriteType

View File

@@ -0,0 +1,6 @@
#title SetSpriteVisible [RCBasic Doc]
#header Sub SetSpriteVisible(sprite, flag)
Sets whether the sprite is visible
#ref SpriteIsVisible

9
doc/files/setspritez.txt Normal file
View File

@@ -0,0 +1,9 @@
#title SetSpriteZ [RCBasic Doc]
#header Sub SetSpriteZ(sprite, z)
Sets the drawing priority for sprites.
Note: Sprites with a higher Z order are drawn first and those with lower values will be drawn on top
#ref SpriteZ

View File

@@ -0,0 +1,7 @@
#title SpriteHeight [RCBasic Doc]
#header Function SpriteHeight(sprite)
Returns the frame height of a sprite
#ref SpriteWidth GetSpriteSize

View File

@@ -0,0 +1,6 @@
#title SpriteIsSolid [RCBasic Doc]
#header Function SpriteIsSolid(sprite)
Returns true if a sprite is has physics and collision response enabled
#ref SetSpriteSolid

View File

@@ -0,0 +1,6 @@
#title SpriteIsVisible [RCBasic Doc]
#header Function SpriteIsVisible(sprite)
Returns whether the sprite is visible
#ref SetSpriteVisible

View File

@@ -0,0 +1,6 @@
#title SpriteWidth [RCBasic Doc]
#header Function SpriteWidth(sprite)
Returns the frame width of a sprite
#ref SpriteHeight GetSpriteSize

7
doc/files/spritex.txt Normal file
View File

@@ -0,0 +1,7 @@
#title SpriteX [RCBasic Doc]
#header Function SpriteX(sprite)
Returns the X position of a sprite on a canvas
#ref SpriteY SetSpritePosition GetSpritePosition

6
doc/files/spritey.txt Normal file
View File

@@ -0,0 +1,6 @@
#title SpriteY [RCBasic Doc]
#header Function SpriteY(sprite)
Returns the Y position of a sprite on a canvas
#ref SpriteX SetSpritePosition GetSpritePosition

8
doc/files/spritez.txt Normal file
View File

@@ -0,0 +1,8 @@
#title SpriteZ [RCBasic Doc]
#header Function SpriteZ(sprite)
Returns the drawing priority for sprites.
Note: Sprites with a higher Z order are drawn first and those with lower values will be drawn on top
#ref SetSpriteZ

7
doc/files/textheight.txt Normal file
View File

@@ -0,0 +1,7 @@
#title TextHeight [RCBasic Doc]
#header function TextHeight(txt$)
The height of text rendered with the active font
#ref TextWidth GetTextSize

6
doc/files/textwidth.txt Normal file
View File

@@ -0,0 +1,6 @@
#title TextWidth [RCBasic Doc]
#header function TextWidth(txt$)
The width of text rendered with the active font
#ref TextHeight GetTextSize

View File

@@ -0,0 +1,8 @@
#title TranslateSprite [RCBasic Doc]
#header Sub TranslateSprite(sprite, x, y)
Move a sprite relative to its current position
Note: This function sets the position of a sprite without regards to physics properties so it will not trigger collision detection or collision response.
#ref SetSpritePosition GetSpritePosition

Binary file not shown.

View File

@@ -1238,6 +1238,10 @@ string rc_keywordToken(string sline)
return "<num>19"; return "<num>19";
else if(sline.compare("MD2_ANIMATION_BOOM")==0) else if(sline.compare("MD2_ANIMATION_BOOM")==0)
return "<num>20"; return "<num>20";
else if(sline.compare("PROJECTION_TYPE_ORTHOGRAPHIC")==0)
return "<num>0";
else if(sline.compare("PROJECTION_TYPE_PERSPECTIVE")==0)
return "<num>1";
else if(sline.compare("SPRITE_TYPE_STATIC")==0) else if(sline.compare("SPRITE_TYPE_STATIC")==0)
return "<num>0"; return "<num>0";
else if(sline.compare("SPRITE_TYPE_KINEMATIC")==0) else if(sline.compare("SPRITE_TYPE_KINEMATIC")==0)

View File

@@ -1312,13 +1312,33 @@ int rc_cloneCanvas(int origin_canvas_id, int mode)
return canvas_id; return canvas_id;
} }
void rc_getWorldToViewportPosition(double x, double y, double z, double* vx, double* vy)
{
if(!VideoDriver)
return;
if(rc_active_canvas < 0 || rc_active_canvas >= rc_canvas.size())
return;
if(!rc_canvas[rc_active_canvas].texture)
return;
if(!rc_canvas[rc_active_canvas].camera.camera)
return;
irr::scene::ISceneCollisionManager* collman = SceneManager->getSceneCollisionManager();
irr::core::vector2di vpos = collman->getScreenCoordinatesFrom3DPosition(irr::core::vector3df(x, y, z), rc_canvas[rc_active_canvas].camera.camera);
*vx = vpos.X;
*vy = vpos.Y;
}
void rc_setClearColor(Uint32 color) void rc_setClearColor(Uint32 color)
{ {
rc_clear_color.set(color); rc_clear_color.set(color);
} }
Uint32 rc_rgba(Uint32 r, Uint32 g, Uint32 b, Uint32 a) Uint32 rc_rgba(Uint32 r, Uint32 g, Uint32 b, Uint32 a)
{ {
irr::video::SColor color(a, r, g, b); irr::video::SColor color(a, r, g, b);

View File

@@ -6717,6 +6717,37 @@ double rc_getCameraNearValue()
return rc_canvas[rc_active_canvas].camera.camera->getNearValue(); return rc_canvas[rc_active_canvas].camera.camera->getNearValue();
} }
void rc_setCameraProjectionMatrix(int proj_matrix, int proj_type)
{
if(!(rc_active_canvas > 0 && rc_active_canvas < rc_canvas.size()))
return;
if(proj_matrix < 0 || proj_matrix >= rc_matrix.size())
return;
if(!rc_matrix[proj_matrix].active)
return;
irr::core::matrix4 irr_mat = rc_convertToIrrMatrix(proj_matrix);
bool isOrtho = (proj_type == RC_PROJECTION_TYPE_ORTHOGRAPHIC);
rc_canvas[rc_active_canvas].camera.camera->setProjectionMatrix(irr_mat, isOrtho);
}
void rc_getCameraProjectionMatrix(int proj_matrix)
{
if(!(rc_active_canvas > 0 && rc_active_canvas < rc_canvas.size()))
return;
if(proj_matrix < 0 || proj_matrix >= rc_matrix.size())
return;
if(!rc_matrix[proj_matrix].active)
return;
irr::core::matrix4 pmat = rc_canvas[rc_active_canvas].camera.camera->getProjectionMatrix();
rc_convertFromIrrMatrix(pmat, proj_matrix);
}
void rc_addSceneSkyBox(int img_top, int img_bottom, int img_left, int img_right, int img_front, int img_back) void rc_addSceneSkyBox(int img_top, int img_bottom, int img_left, int img_right, int img_front, int img_back)
{ {

View File

@@ -316,6 +316,9 @@ struct rc_physicsWorld2D_obj
#define RC_CANVAS_TYPE_3D 1 #define RC_CANVAS_TYPE_3D 1
#define RC_CANVAS_TYPE_SPRITE 2 #define RC_CANVAS_TYPE_SPRITE 2
#define RC_PROJECTION_TYPE_ORTHOGRAPHIC 0
#define RC_PROJECTION_TYPE_PERSPECTIVE 1
struct rc_canvas_obj struct rc_canvas_obj
{ {
irr::video::ITexture* texture; irr::video::ITexture* texture;

View File

@@ -204,7 +204,7 @@ int rc_getSpriteAnimation(int spr_id)
return rc_sprite[spr_id].current_animation; return rc_sprite[spr_id].current_animation;
} }
int rc_getSpriteActiveAnimationFrame(int spr_id) int rc_getSpriteCurrentAnimationFrame(int spr_id)
{ {
if(spr_id < 0 || spr_id >= rc_sprite.size()) if(spr_id < 0 || spr_id >= rc_sprite.size())
return -1; return -1;
@@ -216,7 +216,7 @@ int rc_getSpriteActiveAnimationFrame(int spr_id)
return rc_sprite[spr_id].animation[current_animation].current_frame; return rc_sprite[spr_id].animation[current_animation].current_frame;
} }
void rc_loopSpriteAnimation(int spr_id, int num_loops) void rc_setSpriteAnimationLoops(int spr_id, int num_loops)
{ {
if(spr_id < 0 || spr_id >= rc_sprite.size()) if(spr_id < 0 || spr_id >= rc_sprite.size())
return; return;
@@ -391,6 +391,41 @@ void rc_deleteSprite(int spr_id)
} }
} }
void rc_setSpriteSource(int spr_id, int img_id)
{
if(spr_id < 0 || spr_id >= rc_sprite.size())
return;
if(!rc_sprite[spr_id].active)
return;
if(img_id < 0)
{
rc_sprite[spr_id].image_id = -1;
return;
}
if(img_id >= rc_image.size())
return;
if(!rc_image[img_id].image)
return;
rc_sprite[spr_id].image_id = img_id;
}
int rc_getSpriteSource(int spr_id)
{
if(spr_id < 0 || spr_id >= rc_sprite.size())
return -1;
if(!rc_sprite[spr_id].active)
return -1;
return rc_sprite[spr_id].image_id;
}
void rc_setSpriteType(int spr_id, int body_type) void rc_setSpriteType(int spr_id, int body_type)
{ {
if(spr_id < 0 || spr_id >= rc_sprite.size()) if(spr_id < 0 || spr_id >= rc_sprite.size())
@@ -402,6 +437,17 @@ void rc_setSpriteType(int spr_id, int body_type)
rc_sprite[spr_id].physics.body->SetType((b2BodyType) body_type); rc_sprite[spr_id].physics.body->SetType((b2BodyType) body_type);
} }
int rc_getSpriteType(int spr_id)
{
if(spr_id < 0 || spr_id >= rc_sprite.size())
return -1;
if(!rc_sprite[spr_id].active)
return -1;
return (int)rc_sprite[spr_id].physics.body->GetType();
}
void rc_setSpriteSolid(int spr_id, bool flag) void rc_setSpriteSolid(int spr_id, bool flag)
{ {
if(spr_id < 0 || spr_id >= rc_sprite.size()) if(spr_id < 0 || spr_id >= rc_sprite.size())