added Simple Spline Morping + Blired Spline Star Bouncing Effects

This commit is contained in:
Sylvain PILLOT 2023-11-12 21:59:24 +01:00
parent f3d581bcf5
commit 2e147137a9
19 changed files with 690 additions and 17 deletions

View File

@ -19,6 +19,7 @@ set(SOURCES
src/utilities/utilities.cpp
src/utilities/vector2D.cpp
src/utilities/3Dtransform.cpp
src/utilities/trajectory.cpp
src/effects/plasma.cpp
src/effects/morph.cpp
@ -28,15 +29,18 @@ set(SOURCES
src/effects/morphfire.cpp
src/effects/linemorph.cpp
src/effects/rotozoom.cpp
src/effects/spline.cpp
src/effects/splineblur.cpp
)
set(ASSETS_cg
assets-cg/fontmatrix.png
assets-cg/fontlabel.png
assets-cg/bglens.png
assets-cg/tile.png
assets-cg/OptionBox.png
assets-cg/optionbox.png
)
fxconv_declare_assets(${ASSETS_cg} WITH_METADATA)

View File

@ -4,6 +4,8 @@ To Add a Spline Morphing Effect with Fire
To Add a High Velocity Blur Effect
[WIP] To Add a RainDrops Effect
[Done = OK] Check if the G90+E is powerful enough for Rotozoom
Check if the G90+E is powerful enough for Tunnel Effect

Binary file not shown.

Before

Width:  |  Height:  |  Size: 558 B

View File

@ -0,0 +1,34 @@
fontmatrix.png:
name: font_matrix
type: font
charset: print
grid.size: 9x14
fontlabel.png:
type: font
name: font_label
charset: print
grid.size: 10x13
grid.padding: 0
grid.border: 0
proportional: true
bglens.png:
type: bopti-image
profile: p8
name: bglens
tile.png:
type: bopti-image
profile: p8
name: tilerotozoom
mosaics.png:
type: bopti-image
profile: p8
name: mosaics
optionbox.png:
type: bopti-image
profile: p8_rgb565a
name: optionbox

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -23,7 +23,7 @@ tile.png:
profile: p8
name: tilerotozoom
OptionBox.png:
optionbox.png:
type: bopti-image
profile: p8_rgb565a
name: optionbox

BIN
assets-cg/optionbox.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 597 B

2
clean
View File

@ -1,2 +1,4 @@
rm -r build-cg/
rm -r build-cg-push/
rm -r build-fx/
rm *.g3a

View File

@ -4,7 +4,7 @@
#define MAXHEIGHT 224
#define MORE_RAM 0
#define MORE_RAM 1

View File

@ -0,0 +1,91 @@
#ifndef EFFECTS_H
#define EFFECTS_H
#include "../config.h"
#include <gint/display.h>
#include <gint/image.h>
/* EFFECT #1 : PLASMA EFFECT */
char *plasma_text( void );
void plasma_init( bopti_image_t *screen );
void plasma_update( bopti_image_t *screen, float dt );
void plasma_render( bopti_image_t *screen );
void plasma_deinit( bopti_image_t *screen );
/* EFFECT #2 : MORPHING EFFECT : FROM SPHERE TO TORUS */
char *morph_text( void );
void morph_init( bopti_image_t *screen );
void morph_update( bopti_image_t *screen, float dt );
void morph_render( bopti_image_t *screen );
void morph_deinit( bopti_image_t *screen );
/* EFFECT #3 : MATRIX EFFECT */
char *matrix_text( void );
void matrix_init( bopti_image_t *screen );
void matrix_update( bopti_image_t *screen, float dt );
void matrix_render( bopti_image_t *screen );
void matrix_deinit( bopti_image_t *screen );
/* EFFECT #4 : LENS EFFECT */
char *lens_text( void );
void lens_init( bopti_image_t *screen );
void lens_update( bopti_image_t *screen, float dt );
void lens_render( bopti_image_t *screen );
void lens_deinit( bopti_image_t *screen );
/* EFFECT #5 : CUBEFIRE EFFECT */
char *firecube_text( void );
void firecube_init( bopti_image_t *screen );
void firecube_update( bopti_image_t *screen, float dt );
void firecube_render( bopti_image_t *screen );
void firecube_deinit( bopti_image_t *screen );
void Blur( bopti_image_t *screen );
void drawline(bopti_image_t *screen, int x1, int y1, int x2, int y2, uint8_t color);
/* EFFECT #6 : MORPHING EFFECT WITH FIRE : FROM SPHERE TO TORUS */
char *morphfire_text( void );
void morphfire_init( bopti_image_t *screen );
void morphfire_update( bopti_image_t *screen, float dt );
void morphfire_render( bopti_image_t *screen );
void morphfire_deinit( bopti_image_t *screen );
/* EFFECT #7 : MORPHING EFFECT : BOUNCING LINE ON SCREEN */
char *linemorph_text( void );
void linemorph_init( bopti_image_t *screen );
void linemorph_update( bopti_image_t *screen, float dt );
void linemorph_render( bopti_image_t *screen );
void linemorph_deinit( bopti_image_t *screen );
/* EFFECT #8 : ROTOZOOM EFFECT */
char *rotozoom_text( void );
void rotozoom_init( bopti_image_t *screen );
void rotozoom_update( bopti_image_t *screen, float dt );
void rotozoom_render( bopti_image_t *screen );
void rotozoom_deinit( bopti_image_t *screen );
/* EFFECT #9 : spline */
char *spline_text( void );
void spline_init( bopti_image_t *screen );
void spline_update( bopti_image_t *screen, float dt );
void spline_render( bopti_image_t *screen );
void spline_deinit( bopti_image_t *screen );
#endif

View File

@ -0,0 +1,145 @@
#include "effects.h"
#include <num/num.h>
#include "../utilities/fast_trig.h"
#include <cstring>
#include <gint/rtc.h>
#include <gint/kmalloc.h>
extern bopti_image_t mosaics;
static const int MAX_ARRAY = DWIDTH * MAXHEIGHT;
static const short amplitudes[4] = { -250, -425, -350, -650};
static short *wavemap;
static short *old_wavemap;
static short *p_old;
static short *p_new;
short *address_new, *address_old, *temp;
short height, xdiff;
int8_t *pscreen, *pimage;
void raindrops_init( bopti_image_t *screen )
{
wavemap = (short *) kmalloc( DWIDTH * MAXHEIGHT * sizeof( short ), "extram" );
old_wavemap = (short *) kmalloc( DWIDTH * MAXHEIGHT* sizeof( short ), "extram" );
p_old = old_wavemap;
p_new = wavemap;
image_copy_palette( &mosaics, screen, -1 );
for (int i = 0; i < MAX_ARRAY; ++i)
{
wavemap[i] = 0;
old_wavemap[i] = 0;
}
}
void start_drop()
{
uint32_t v,w;
static const uint16_t b = DWIDTH - 10;
static const uint16_t c = DWIDTH * 10;
static const uint32_t d = (DWIDTH * MAXHEIGHT) - (DWIDTH * 10);
static uint8_t amp_index = 0;
/* borders are invalid so keep trying till valid value*/
do
{
v = rand() % MAX_ARRAY;
w = v % DWIDTH;
}
while (w < 10 || w > b || v < c || v > d);
wavemap[v] = amplitudes[amp_index++];
amp_index &= 4;
}
void raindrops_update( bopti_image_t *screen, [[Maybe_unused]] float dt )
{
uint16_t t;
start_drop();
t = DWIDTH + 1;
address_new = p_new + t;
address_old = p_old + t;
for (int i = 1; i < MAXHEIGHT - 1; ++i)
{
for (int j = 1; j < DWIDTH - 1; ++j)
{
height = 0;
height += *(address_new + DWIDTH);
height += *(address_new - 1);
height += *(address_new + 1);
height += *(address_new - DWIDTH);
height >>= 1;
height -= *address_old;
height -= height >> 5;
*address_old = height;
address_new++;
address_old++;
}
address_new += 2; /* next scanline starting at pos 1 */
address_old += 2;
}
t = screen->stride + 1;
address_old = p_old + t;
pscreen = (int8_t*)screen->data + t;
pimage = (int8_t*)mosaics.data + t;
/* draw waves */
for (int i = 1; i < MAXHEIGHT - 1; ++i)
{
for (int j = 1; j < DWIDTH - 1; ++j)
{
xdiff = *(address_old + 1) - *(address_old);
*pscreen = *(pimage + xdiff);
address_old++;
pscreen++;
pimage++;
}
address_old += 2;
pscreen += 2; /* next scanline starting at pos 1 */
pimage += 2;
}
/* swap wave tables */
temp = p_new;
p_new = p_old;
p_old = temp;
}
void raindrops_render( bopti_image_t *screen )
{
dimage(0,0,screen);
}
void raindrops_deinit( bopti_image_t *screen )
{
free( wavemap );
free( old_wavemap );
}
char raindrops_TextToRender[100] = "Rain Drops on Mosaic Tiles > _\0";
char *raindrops_text( void )
{
return raindrops_TextToRender;
}

View File

@ -60,6 +60,7 @@ void morphfire_init( bopti_image_t *screen );
void morphfire_update( bopti_image_t *screen, float dt );
void morphfire_render( bopti_image_t *screen );
void morphfire_deinit( bopti_image_t *screen );
void pixel( bopti_image_t *screen, uint16_t sx, uint16_t sy, int8_t color );
/* EFFECT #7 : MORPHING EFFECT : BOUNCING LINE ON SCREEN */
@ -79,4 +80,24 @@ void rotozoom_update( bopti_image_t *screen, float dt );
void rotozoom_render( bopti_image_t *screen );
void rotozoom_deinit( bopti_image_t *screen );
/* EFFECT #9 : BLURED SPLINE EFFECT */
char *splineblur_text( void );
void splineblur_init( bopti_image_t *screen );
void splineblur_update( bopti_image_t *screen, float dt );
void splineblur_render( bopti_image_t *screen );
void splineblur_deinit( bopti_image_t *screen );
void Blur2( bopti_image_t *screen );
/* EFFECT #10 : MOVING SPLINE EFFECT */
char *spline_text( void );
void spline_init( bopti_image_t *screen );
void spline_update( bopti_image_t *screen, float dt );
void spline_render( bopti_image_t *screen );
void spline_deinit( bopti_image_t *screen );
#endif

View File

@ -97,7 +97,7 @@ void drawline(bopti_image_t *screen, int x1, int y1, int x2, int y2, uint8_t col
dx = (dx >= 0 ? dx : -dx);
dy = (dy >= 0 ? dy : -dy);
dest[x1+y1*screen->stride] = color;
pixel(screen, x1, y1, color);
if(dx >= dy)
{
@ -109,7 +109,7 @@ void drawline(bopti_image_t *screen, int x1, int y1, int x2, int y2, uint8_t col
x += sx;
cumul += dy;
if(cumul > dx) cumul -= dx, y += sy;
dest[x+y*screen->stride] = color;
pixel(screen, x, y, color);
}
}
else
@ -120,11 +120,11 @@ void drawline(bopti_image_t *screen, int x1, int y1, int x2, int y2, uint8_t col
y += sy;
cumul += dx;
if(cumul > dy) cumul -= dy, x += sx;
dest[x+y*screen->stride] = color;
pixel(screen, x, y, color);
}
}
dest[x2+y2*screen->stride] = color;
pixel(screen, x2, y2, color);
}

View File

@ -131,6 +131,8 @@ void morphfire_update( bopti_image_t *screen, [[Maybe_unused]] float dt )
void pixel( bopti_image_t *screen, uint16_t sx, uint16_t sy, int8_t color )
{
if (sx<0 || sx>DWIDTH || sy<0 || sy> MAXHEIGHT ) return;
int8_t *image = (int8_t *)screen->data;
image[ sx + sy * screen->stride ] = color;

114
src/effects/spline.cpp Normal file
View File

@ -0,0 +1,114 @@
#include "effects.h"
#include <num/num.h>
#include "../utilities/fast_trig.h"
#include <cstring>
#include <gint/rtc.h>
#include "../utilities/trajectory.h"
Trajectory MySpline;
#define MAXPT 10
libnum::num32 xPointsOrigin[MAXPT];
libnum::num32 yPointsOrigin[MAXPT];
libnum::num32 xPointsVel[MAXPT];
libnum::num32 yPointsVel[MAXPT];
static int current_morph_frame;
int random_between( int lower, int upper )
{
int number = (rand() % (upper - lower + 1)) + lower;
return number;
}
void spline_init( bopti_image_t *screen )
{
for( int i=0; i<MAXPT; i++ )
{
xPointsOrigin[i] = libnum::num32( DWIDTH/2 );
yPointsOrigin[i] = libnum::num32( MAXHEIGHT/2 );
xPointsVel[i] = libnum::num32( random_between( -2, 2 ) ) / libnum::num32(5);
yPointsVel[i] = libnum::num32( random_between( -2, 2 ) ) / libnum::num32(5);
}
for( int u=0; u<MAXPT; u++ )
{
Vector2D *p = new Vector2D( xPointsOrigin[u], yPointsOrigin[u] );
MySpline.AddPoint( p );
}
for(int u = 0; u<64; u++)
{
screen->palette[u] = C_RGB( 0, 0, 0 );
screen->palette[u+64] = C_RGB( 0, 0, u/2 );
screen->palette[u+128] = C_RGB( 0, u/2, 31 );
screen->palette[u+192] = C_RGB( u/2, 31, 31 );
}
}
void spline_update( bopti_image_t *screen, [[Maybe_unused]] float dt )
{
MySpline.RemovePoints();
for( int u=0; u<MAXPT; u++ )
{
xPointsOrigin[u] += xPointsVel[u];
if (xPointsOrigin[u]<libnum::num32(10)) xPointsOrigin[u] = 10, xPointsVel[u] = -xPointsVel[u];
else if (xPointsOrigin[u]>=libnum::num32(DWIDTH-10)) xPointsOrigin[u] = DWIDTH-11, xPointsVel[u] = -xPointsVel[u];
yPointsOrigin[u] += yPointsVel[u];
if (yPointsOrigin[u]<libnum::num32(10)) yPointsOrigin[u] = 10, yPointsVel[u] = -yPointsVel[u];
else if (yPointsOrigin[u]>=libnum::num32(MAXHEIGHT-10)) yPointsOrigin[u] = MAXHEIGHT-11, yPointsVel[u] = -yPointsVel[u];
Vector2D *p = new Vector2D( xPointsOrigin[u], yPointsOrigin[u] );
MySpline.AddPoint( p );
}
}
void spline_render( bopti_image_t *screen )
{
image_fill( screen, -128 );
float accumulatedTime = 0.0f;
libnum::num32 x0, y0, x1, y1, x2, y2;
MySpline.CalculatePosition( &accumulatedTime, 0.0f, 0.0f, true, &x0, &y0 );
for( int u=0; u<MAXPT*10; u++ )
{
MySpline.CalculatePosition( &accumulatedTime, 0.0f, 1.0f, true, &x1, &y1 );
accumulatedTime = (float) u * 0.1f;
MySpline.CalculatePosition( &accumulatedTime, 0.0f, 1.0f, true, &x2, &y2 );
drawline( screen, (int) x1, (int) y1, (int) x2, (int) y2, 127 );
}
drawline( screen, (int) x2, (int) y2, (int) x0, (int) y0, 127 );
dimage( 0, 0, screen );
}
void spline_deinit( bopti_image_t *screen )
{
MySpline.RemovePoints();
}
char spline_TextToRender[100] = "Spline Distorsion > _\0";
char *spline_text( void )
{
return spline_TextToRender;
}

137
src/effects/splineblur.cpp Normal file
View File

@ -0,0 +1,137 @@
#include "effects.h"
#include <num/num.h>
#include "../utilities/fast_trig.h"
#include <cstring>
#include <gint/rtc.h>
#include "../utilities/trajectory.h"
Trajectory MySplineBlured;
#define MAXPOINT 12
int scalespline = 0, rotate = 0;
void splineblur_init( bopti_image_t *screen )
{
libnum::num32 scalenum = libnum::num32(1)+ FastCosInt(scalespline);
rotate = 0;
for( int u=0; u<MAXPOINT; u++ )
{
int angle = u*30;
Vector2D *p = new Vector2D( libnum::num32( DWIDTH/2 ) + scalenum*FastCosInt(angle+rotate)*libnum::num32(50),
libnum::num32( MAXHEIGHT/2 ) + scalenum*FastSinInt(angle+rotate)*libnum::num32(50) );
MySplineBlured.AddPoint( p );
Vector2D *p2 = new Vector2D( libnum::num32( DWIDTH/2 ) + (libnum::num32(2)-scalenum)*FastCosInt(angle+15+rotate)*libnum::num32(25),
libnum::num32( MAXHEIGHT/2 ) + (libnum::num32(2)-scalenum)*FastSinInt(angle+15+rotate)*libnum::num32(25) );
MySplineBlured.AddPoint( p2 );
}
for(int u = 0; u<32; u++)
{
screen->palette[u] = C_RGB( 0, 0, 0 );
screen->palette[u+32] = C_RGB( 0, 0, 0 );
screen->palette[u+64] = C_RGB( 0, 0, 0 );
screen->palette[u+96] = C_RGB( 0, 0, 0 );
screen->palette[u+128] = C_RGB( 0, 0, 0 );
screen->palette[u+160] = C_RGB( u, 0, 0 );
screen->palette[u+192] = C_RGB( 31, u, 0 );
screen->palette[u+224] = C_RGB( 31, 31, u );
}
image_fill( screen, -128 );
}
void splineblur_update( bopti_image_t *screen, [[Maybe_unused]] float dt )
{
MySplineBlured.RemovePoints();
scalespline += 1;
rotate += 1;
scalespline = scalespline % 360;
rotate = rotate % 360;
libnum::num32 scalenum = libnum::num32(1) + FastCosInt(scalespline);
for( int u=0; u<MAXPOINT; u++ )
{
int angle = u*30;
Vector2D *p = new Vector2D( libnum::num32( DWIDTH/2 ) + scalenum*FastCosInt(angle+rotate)*libnum::num32(50),
libnum::num32( MAXHEIGHT/2 ) + scalenum*FastSinInt(angle+rotate)*libnum::num32(50) );
MySplineBlured.AddPoint( p );
Vector2D *p2 = new Vector2D( libnum::num32( DWIDTH/2 ) + (libnum::num32(2)-scalenum)*FastCosInt(angle+15+rotate)*libnum::num32(25),
libnum::num32( MAXHEIGHT/2 ) + (libnum::num32(2)-scalenum)*FastSinInt(angle+15+rotate)*libnum::num32(25) );
MySplineBlured.AddPoint( p2 );
}
}
void Blur2( bopti_image_t *screen )
{
int8_t *dest = (int8_t *)screen->data;
int16_t temp;
uint32_t offset = screen->stride; // pixel(x,y)
for( int index = 2; index < MAXHEIGHT-2; index++ )
{
for( int x = 2; x < screen->width - 2; x++ )
{
temp = dest[ offset + x - 1 ] + // pixel(x-1,y)
dest[ offset + x + 1 ] + // pixel(x+1,y)
dest[ offset + x + screen->stride ] + // pixel(x,y+1)
dest[ offset + x - screen->stride ]; // pixel(x,y-1)
dest[offset + x] = temp >> 2;
}
offset += screen->stride;
}
}
void splineblur_render( bopti_image_t *screen )
{
float accumulatedTime = 0.0f;
libnum::num32 x1, y1, x2, y2;
for( int u=0; u<MAXPOINT*2*10; u++ )
{
MySplineBlured.CalculatePosition( &accumulatedTime, 0.0f, 1.0f, true, &x1, &y1 );
accumulatedTime = (float) u * 0.1f;
MySplineBlured.CalculatePosition( &accumulatedTime, 0.0f, 1.0f, true, &x2, &y2 );
drawline( screen, (int) x1, (int) y1, (int) x2, (int) y2, 127 );
}
Blur2( screen );
dimage( 0, 0, screen );
}
void splineblur_deinit( bopti_image_t *screen )
{
MySplineBlured.RemovePoints();
}
char splineblur_TextToRender[100] = "Spline Distorsion > _\0";
char *splineblur_text( void )
{
return splineblur_TextToRender;
}

View File

@ -19,22 +19,21 @@
#include "utilities/extrakeyboard.h"
#include "utilities/utilities.h"
#include "effects/effects.h"
#include <string>
#define TOTAL_NB_EFFECT 8
#define TOTAL_NB_EFFECT 10
typedef void (*PtrToFunc)( bopti_image_t * );
typedef void (*PtrToFuncDt)( bopti_image_t *, float );
typedef char* (*PtrTextFunc)( void );
PtrTextFunc Effect_Text[] = { &rotozoom_text, &linemorph_text, &plasma_text, &morph_text, &lens_text, &firecube_text, &matrix_text, &morphfire_text };
PtrToFunc Effects_Init[] = { &rotozoom_init, &linemorph_init, &plasma_init, &morph_init, &lens_init, &firecube_init, &matrix_init, &morphfire_init };
PtrToFuncDt Effects_Update[] = { &rotozoom_update, &linemorph_update, &plasma_update, &morph_update, &lens_update, &firecube_update, &matrix_update, &morphfire_update };
PtrToFunc Effects_Render[] = { &rotozoom_render, &linemorph_render, &plasma_render, &morph_render, &lens_render, &firecube_render, &matrix_render, &morphfire_render };
PtrToFunc Effects_DeInit[] = { &rotozoom_deinit, &linemorph_deinit, &plasma_deinit, &morph_deinit, &lens_deinit, &firecube_deinit, &matrix_deinit, &morphfire_deinit };
PtrTextFunc Effect_Text[] = { &spline_text, &splineblur_text, &linemorph_text, &rotozoom_text, &plasma_text, &morph_text, &lens_text, &firecube_text, &matrix_text, &morphfire_text };
PtrToFunc Effects_Init[] = { &spline_init, &splineblur_init, &linemorph_init, &rotozoom_init, &plasma_init, &morph_init, &lens_init, &firecube_init, &matrix_init, &morphfire_init };
PtrToFuncDt Effects_Update[] = { &spline_update, &splineblur_update, &linemorph_update, &rotozoom_update, &plasma_update, &morph_update, &lens_update, &firecube_update, &matrix_update, &morphfire_update };
PtrToFunc Effects_Render[] = { &spline_render, &splineblur_render, &linemorph_render, &rotozoom_render, &plasma_render, &morph_render, &lens_render, &firecube_render, &matrix_render, &morphfire_render };
PtrToFunc Effects_DeInit[] = { &spline_deinit, &splineblur_deinit, &linemorph_deinit, &rotozoom_deinit, &plasma_deinit, &morph_deinit, &lens_deinit, &firecube_deinit, &matrix_deinit, &morphfire_deinit };
int current_effect = 0;
@ -57,7 +56,7 @@ bool skip_intro = false;
bool screenshot = false;
bool record = false;
bool showFPS = false;
bool showName = true;
bool showName = false;
bool showOption = false;
bool EffectLoop = true;
@ -361,7 +360,7 @@ int main(void)
int EntryClockLevel;
EntryClockLevel = clock_get_speed();
clock_set_speed( CLOCK_SPEED_F4 );
clock_set_speed( CLOCK_SPEED_F5 );
srand( rtc_ticks() );
@ -459,11 +458,14 @@ int main(void)
while (exitToOS==false);
Close();
image_free( screen );
prof_quit();
clock_set_speed( EntryClockLevel );
image_free( screen );
#if(MORE_RAM)
if (canWeAllocateMoreRam) FreeMoreRAM( );

View File

@ -0,0 +1,89 @@
#include <algorithm>
#include "../config.h"
#include "trajectory.h"
Trajectory::Trajectory( )
{
}
Trajectory::~Trajectory( )
{
for( auto& p : ControlPoints )
delete( p );
ControlPoints.clear();
}
void Trajectory::RemovePoints( )
{
for( auto& p : ControlPoints )
delete( p );
ControlPoints.clear();
}
void Trajectory::AddPoint( Vector2D *p )
{
ControlPoints.push_back( p );
}
void Trajectory::AddPointAtBegining( Vector2D *p )
{
ControlPoints.insert( ControlPoints.begin(), p );
}
int8_t Trajectory::CalculatePosition( float *accumulatedTime, float time, uint16_t speed, bool looped, libnum::num *xreturn, libnum::num *yreturn )
{
*accumulatedTime += speed * time / 2000000.0f;
if( !looped && (*accumulatedTime>ControlPoints.size()))
return -1;
if (*accumulatedTime>ControlPoints.size())
*accumulatedTime -= ControlPoints.size();
if (*accumulatedTime<0)
*accumulatedTime += ControlPoints.size();
libnum::num t = libnum::num( *accumulatedTime - (int) *accumulatedTime );
int p0, p1, p2, p3;
if (!looped)
{
p1 = std::min( (int) *accumulatedTime + 1, (int) (ControlPoints.size()-1));
p2 = std::min( p1 + 1, (int) (ControlPoints.size()-1));
p3 = std::min( p2 + 1, (int) (ControlPoints.size()-1));
p0 = std::min( p1 - 1, (int) (ControlPoints.size()-1));
}
else
{
p1 = (int) *accumulatedTime;
p2 = (p1 + 1) % ControlPoints.size();
p3 = (p2 + 1) % ControlPoints.size();
p0 = p1 >= 1 ? p1 - 1 : ControlPoints.size() - 1;
}
libnum::num tt = t * t;
libnum::num ttt = tt * t;
libnum::num q1 = -ttt + 2*tt - t;
libnum::num q2 = 3*ttt - 5*tt + libnum::num( 2 );
libnum::num q3 = -3*ttt + 4*tt + t;
libnum::num q4 = ttt - tt;
libnum::num tx = libnum::num( 0.5f ) * (ControlPoints[p0]->x * q1 + ControlPoints[p1]->x * q2 + ControlPoints[p2]->x * q3 + ControlPoints[p3]->x * q4);
libnum::num ty = libnum::num( 0.5f ) * (ControlPoints[p0]->y * q1 + ControlPoints[p1]->y * q2 + ControlPoints[p2]->y * q3 + ControlPoints[p3]->y * q4);
*xreturn = tx;
*yreturn = ty;
return 0;
}

View File

@ -0,0 +1,30 @@
#ifndef TRAJECTORY_H
#define TRAJECTORY_H
#include <cstdint>
#include <stdlib.h>
#include <num/num.h>
#include <vector>
#include "../utilities/vector2D.h"
class Trajectory
{
public:
Trajectory( );
~Trajectory( );
void AddPoint( Vector2D *p );
void AddPointAtBegining( Vector2D *p );
int8_t CalculatePosition( float *accumulatedTime, float time, uint16_t speed, bool looped, libnum::num *xreturn, libnum::num *yreturn );
void RemovePoints( );
std::vector <Vector2D*> ControlPoints;
bool isLoop;
};
#endif