one dimensional arrays, initialized at construction to proper length with std::transform applying per pixel effects and not more grid size passed to presets

git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@1045 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
psperl
2008-06-22 16:08:26 +00:00
parent e0c338866c
commit c15fda2321
11 changed files with 180 additions and 445 deletions

View File

@ -27,7 +27,7 @@ SET(projectM_SOURCES projectM.cpp FBO.cpp InitCond.cpp
Func.cpp Eval.cpp PerFrameEqn.cpp PerPointEqn.cpp fftsg.cpp KeyHandler.cpp
timer.cpp wipemalloc.cpp BuiltinFuncs.cpp BuiltinParams.cpp Renderer.cpp
PresetLoader.cpp PresetChooser.cpp PresetFrameIO.cpp PresetMerge.cpp
ConfigFile.cpp IdlePreset.cpp TextureManager.cpp TimeKeeper.cpp Transformation.cpp Filters.cpp Renderable.cpp Pipeline.cpp PerPixelMesh.cpp ${GLEW_SOURCES})
ConfigFile.cpp IdlePreset.cpp TextureManager.cpp TimeKeeper.cpp Filters.cpp Renderable.cpp Pipeline.cpp PerPixelMesh.cpp ${GLEW_SOURCES})
if (USE_DEVIL)
SET (projectM_SOURCES ${projectM_SOURCES})

View File

@ -1,44 +1,47 @@
#include <math.h>
#include <algorithm>
#include "PerPixelMesh.hpp"
PerPixelMesh::PerPixelMesh(int width, int height) : width(width), height(height),
x(width, std::vector<float>(height)),
y(width, std::vector<float>(height)),
x_tex(width, std::vector<float>(height)),
y_tex(width, std::vector<float>(height)),
x_identity(width, std::vector<float>(height)),
y_identity(width, std::vector<float>(height)),
rad_identity(width, std::vector<float>(height)),
theta_identity(width, std::vector<float>(height))
PerPixelMesh::PerPixelMesh(int width, int height) : width(width), height(height), size (width * height),
p(width * height, Point(0,0)),
p_original(width * height, Point(0,0)),
identity(width * height, PerPixelContext(0,0,0,0,0,0))
{
for (int i=0;i < width; i++ )
for (int j=0;j < height; j++ )
{
for (int j=0;j<height;j++)
for(int i=0;i<width;i++)
{
int index = j * width + i;
float xval=i/(float)(width-1);
float yval=-((j/(float)(height-1))-1);
x_tex[i][j] = xval;
y_tex[i][j] = yval;
x_identity[i][j]=( xval-.5)*2;
y_identity[i][j]=( yval-.5)*2;
p[index].x = xval;
p[index].y = yval;
//x_identity[i][j]=xval;
//y_identity[i][j]=yval;
p_original[index].x = xval;
p_original[index].y = yval;
x[i][j] = x_identity[i][j];
y[i][j] = y_identity[i][j];
identity[index].x= xval;
identity[index].y= yval;
rad_identity[i][j]=hypot ( ( xval-.5 ) *2, ( yval-.5 ) *2 ) * .7071067;
theta_identity[i][j]=atan2 ( ( yval-.5 ) *2 , ( xval-.5 ) *2 );
}
//identity[index].x= (xval-.5)*2;
//identity[index].y= (yval-.5)*2;
identity[index].i= i;
identity[index].j= j;
identity[index].rad=hypot ( ( xval-.5 ) *2, ( yval-.5 ) *2 ) * .7071067;
identity[index].theta=atan2 ( ( yval-.5 ) *2 , ( xval-.5 ) *2 );
}
}
void PerPixelMesh::Reset()
{
for (int i=0;i < width; i++ )
for (int j=0;j < height; j++ )
{
x[i][j]=x_identity[i][j];
y[i][j]=y_identity[i][j];
}
std::copy(p_original.begin(), p_original.end(), p.begin());
}
Point::Point(float x, float y)
: x(x), y(y) {}
PerPixelContext::PerPixelContext(float x, float y, float rad, float theta, int i, int j)
: x(x), y(y), rad(rad), theta(theta), i(i), j(j) {}

View File

@ -3,25 +3,43 @@
#include <vector>
struct Point
{
float x;
float y;
Point(float x, float y);
};
struct PerPixelContext
{
float x;
float y;
float rad;
float theta;
int i;
int j;
PerPixelContext(float x, float y, float rad, float theta, int i, int j);
};
class PerPixelMesh
{
public:
int width;
int height;
int size;
std::vector< std::vector <float> > x;
std::vector< std::vector <float> > y;
std::vector< std::vector <float> > x_tex;
std::vector< std::vector <float> > y_tex;
std::vector< std::vector <float> > x_identity;
std::vector< std::vector <float> > y_identity;
std::vector< std::vector <float> > rad_identity;
std::vector< std::vector <float> > theta_identity;
std::vector<Point> p;
std::vector<Point> p_original;
std::vector<PerPixelContext> identity;
PerPixelMesh(int width, int height);
void Reset();
};
#endif

View File

@ -6,5 +6,7 @@
*/
#include "Pipeline.hpp"
Pipeline::Pipeline(int mesh_x, int mesh_y): mesh_x(mesh_x), mesh_y(mesh_y) {}
Pipeline::Pipeline() {}
void Pipeline::Render(){}
Point Pipeline::PerPixel(Point p, PerPixelContext context)
{return p;}

View File

@ -2,7 +2,7 @@
#define Pipeline_HPP
#include <vector>
#include "Transformation.hpp"
#include "PerPixelMesh.hpp"
#include "Renderable.hpp"
#include "Filters.hpp"
@ -12,9 +12,6 @@ public:
int fps;
int mesh_x;
int mesh_y;
float time;
float bass;
float mid;
@ -32,12 +29,12 @@ public:
float videoEchoZoom;
float videoEchoOrientation;
std::vector<PerPixelTransform*> perPixelTransforms;
std::vector<RenderItem*> drawables;
std::vector<RenderItem*> compositeDrawables;
Pipeline(int mesh_x, int mesh_y);
Pipeline();
virtual void Render();
virtual Point PerPixel(Point p, PerPixelContext context);
};
#endif

View File

@ -7,6 +7,7 @@
#include "KeyHandler.hpp"
#include "TextureManager.hpp"
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
@ -30,7 +31,7 @@ Renderer::Renderer(int width, int height, int gx, int gy, int texsize, BeatDetec
this->drawtitle=0;
this->title = "Unknown";
//this->title = "Unknown";
/** Other stuff... */
this->correction = true;
@ -113,7 +114,7 @@ void Renderer::ResetTextures()
void Renderer::RenderFrame(Pipeline* pipeline)
{
currentPipe = pipeline;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
@ -439,39 +440,42 @@ void Renderer::Interpolation(Pipeline *pipeline)
glEnable(GL_TEXTURE_2D);
int size = mesh.height;
float p[size*2][2];
float t[size*2][2];
int size = mesh.width * 2;
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
float p[size][2];
float t[size][2];
glVertexPointer(2,GL_FLOAT,0,p);
glTexCoordPointer(2,GL_FLOAT,0,t);
mesh.Reset();
std::transform(mesh.p.begin(), mesh.p.end(), mesh.identity.begin(), mesh.p.begin(), &Renderer::PerPixel);
/*
for (vector<PerPixelTransform*>::iterator pos = pipeline->perPixelTransforms.begin(); pos != pipeline->perPixelTransforms.end(); ++pos)
(*pos)->Calculate(&mesh);
for (int x=0;x<mesh.width - 1;x++)
*/
for (int j=0;j<mesh.height - 1;j++)
{
for(int y=0;y<mesh.height;y++)
{
t[y*2][0] = mesh.x[x][y];
t[y*2][1] = mesh.y[x][y];
for(int i=0;i<mesh.width;i++)
{
int index = j * mesh.width + i;
int index2 = (j+1) * mesh.width + i;
p[y*2][0] = mesh.x_tex[x][y];
p[y*2][1] = mesh.y_tex[x][y];
t[i*2][0] = mesh.p[index].x;
t[i*2][1] = mesh.p[index].y;
p[i*2][0] = mesh.identity[index].x;
p[i*2][1] = mesh.identity[index].y;
t[(y*2)+1][0] = mesh.x[x+1][y];
t[(y*2)+1][1] = mesh.y[x+1][y];
p[(y*2)+1][0] = mesh.x_tex[x+1][y];
p[(y*2)+1][1] = mesh.y_tex[x+1][y];
}
glDrawArrays(GL_TRIANGLE_STRIP,0,size*2);
t[(i*2)+1][0] = mesh.p[index2].x;
t[(i*2)+1][1] = mesh.p[index2].y;
p[(i*2)+1][0] = mesh.identity[index2].x;
p[(i*2)+1][1] = mesh.identity[index2].y;
}
glDrawArrays(GL_TRIANGLE_STRIP,0,size);
}
glDisable(GL_TEXTURE_2D);
@ -479,6 +483,11 @@ void Renderer::Interpolation(Pipeline *pipeline)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
Pipeline* Renderer::currentPipe;
Point Renderer::PerPixel(Point p, PerPixelContext context)
{
return currentPipe->PerPixel(p,context);
}
Renderer::~Renderer()
{
@ -765,7 +774,7 @@ void Renderer::draw_shapes(PresetOutputs *presetOutputs)
{
float radius;
float xval, yval;
float t;
@ -780,7 +789,7 @@ void Renderer::draw_shapes(PresetOutputs *presetOutputs)
// printf("drawing shape %f\n", (*pos)->ang);
(*pos)->y=-(( (*pos)->y)-1);
radius=.5;
(*pos)->radius= (*pos)->radius*(.707*.707*.707*1.04);
//Additive Drawing or Overwrite
if ( (*pos)->additive==0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

View File

@ -55,12 +55,14 @@ public:
int totalframes;
float realfps;
std::string title;
int drawtitle;
int texsize;
PerPixelMesh mesh;
Renderer( int width, int height, int gx, int gy, int texsize, BeatDetect *beatDetect, std::string presetURL, std::string title_fontURL, std::string menu_fontURL);
~Renderer();
void RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInputs);
@ -87,7 +89,7 @@ private:
RenderTarget *renderTarget;
BeatDetect *beatDetect;
TextureManager *textureManager;
static Pipeline* currentPipe;
//per pixel equation variables
std::string m_presetName;
@ -118,6 +120,7 @@ private:
void CompositeOutput(Pipeline* pipeline);
void Interpolation(Pipeline* pipeline);
static Point PerPixel(Point p, PerPixelContext context);
void Interpolation(PresetOutputs *presetOutputs, PresetInputs *presetInputs);

View File

@ -8,6 +8,7 @@
#include "Pipeline.hpp"
#include "math.h"
#include "MilkdropCompatability.hpp"
#include "Transformation.hpp"
#include <stdlib.h>
@ -15,15 +16,9 @@ class RovastarDriftingChaos : public Pipeline
{
public:
Delta delta;
PerPixelZoom zoom;
Rotation rotate;
Shape shape1, shape2, shape3;
RovastarDriftingChaos(int mesh_x, int mesh_y) : Pipeline(mesh_x, mesh_y),
delta(mesh_x,mesh_y,0,0),
rotate(mesh_x,mesh_y,0.5,0.5,0),
zoom(mesh_x, mesh_y, 1, 1)
RovastarDriftingChaos() : Pipeline()
{
screenDecay = 1.0;
textureWrap = 0;
@ -36,11 +31,6 @@ public:
drawables.push_back(&shape2);
drawables.push_back(&shape3);
perPixelTransforms.push_back(&zoom);
perPixelTransforms.push_back(&delta);
perPixelTransforms.push_back(&rotate);
shape1.sides = 3;
shape1.radius=0.550000;
shape1.a = 0.1;
@ -71,6 +61,7 @@ public:
}
float xamptarg, q8, oldq8, q7, xpos, ypos,xdir, xspeed, xamp, yamp, yamptarg,yspeed,ydir;
float dx, dy, angle;
virtual void Render()
{
@ -84,7 +75,7 @@ public:
float xaccel = xdir*xamp - xpos - xspeed*0.055*below(abs(xpos),xamp);
xspeed += xdir*xamp - xpos - xspeed*0.055*below(abs(xpos),xamp);
xpos = xpos + 0.001*xspeed;
delta.dx = xpos*0.005;
dx = xpos*0.005;
yamptarg = if_milk(equal(frame%15,0),min(0.3*volume*treb_att,0.5),yamptarg);
yamp += 0.5*(yamptarg-yamp);
ydir = if_milk(above(abs(ypos),yamp),-sign(ypos),if_milk(below(abs(yspeed),0.1),2*above(ypos,0)-1,ydir));
@ -93,8 +84,8 @@ public:
yspeed += ydir*yamp - ypos - yspeed*0.055*below(abs(ypos),yamp);
ypos = ypos + 0.001*yspeed;
delta.dy = ypos*0.005;
rotate.angle = 10*(delta.dx-delta.dy);
dy = ypos*0.005;
angle = 10*(dx-dy);
q8 =oldq8+ 0.0003*(powf(1+1.2*bass+0.4*bass_att+0.1*treb+0.1*treb_att+0.1*mid+0.1*mid_att,6)/fps);
oldq8 = q8;
@ -130,16 +121,14 @@ public:
shape3.g2 = 0.5 + 0.5*cos(q8*0.556+ 1);
shape3.b2 = 0.5 + 0.5*sin(q8*0.638 + 3);
for (int x = 0; x < mesh_x; x++)
for (int y = 0; y < mesh_y; y++)
{
float xval=x/(float)(mesh_x-1);
float yval=-((y/(float)(mesh_y-1))-1);
float rad=hypot ( ( xval-.5 ) *2, ( yval-.5 ) *2 ) * .7071067;
zoom.zoom[x][y] = 1+0.05*rad;
}
}
virtual Point PerPixel(Point p, PerPixelContext context)
{
Transforms::Zoom(p,context,1+0.05*context.rad,1);
Transforms::Transform(p,context,dx,dy);
Transforms::Rotate(p,context,angle,0.5,0.5);
return p;
}
};

View File

@ -7,6 +7,7 @@
#include "Pipeline.hpp"
#include "math.h"
#include "Transformation.hpp"
#include <stdlib.h>
@ -14,25 +15,19 @@ class RovastarFranticFractopia : public Pipeline
{
public:
PerPixelDelta delta;
Zoom zoom;
Border border;
MotionVectors vectors;
float dx, dy;
float q4, q5, q6;
float movement;
RovastarFranticFractopia(int mesh_x, int mesh_y) : Pipeline(mesh_x, mesh_y),
delta(mesh_x,mesh_y,0,0),
zoom(mesh_x, mesh_y, 0.98, 1.503744)
RovastarFranticFractopia() : Pipeline()
{
drawables.push_back(&vectors);
drawables.push_back(&border);
perPixelTransforms.push_back(&zoom);
perPixelTransforms.push_back(&delta);
screenDecay = 1.0;
@ -67,7 +62,6 @@ public:
virtual void Render()
{
movement += 0.5*(((bass+bass_att + 0.075*pow((bass+0.6*bass_att+0.2*treb_att),3)))/(float)fps);
if (movement > 10000.0)
movement = 0.0;
@ -82,20 +76,21 @@ public:
vectors.y_offset = 0.03*sin(movement*0.34);
vectors.x_offset = 0.035*(sin(movement*0.217)+cos(movement*0.413)+sin(movement*0.311));
float dx =0.01*sin(movement*5);
float dy =0.0005*(bass+bass_att);
dx =0.01*sin(movement*5);
dy =0.0005*(bass+bass_att);
for (int x = 0; x < mesh_x; x++)
for (int y = 0; y < mesh_y; y++)
{
float xval=x/(float)(mesh_x-1);
float yval=-((y/(float)(mesh_y-1))-1);
}
float myy = yval-(0.250025);
float myx = xval-0.5;
delta.dx[x][y] = dx + 2*(2*myx*myy);
delta.dy[x][y] = dy + 2*((myy*myy) - (myx*myx));
}
virtual Point PerPixel(Point p, PerPixelContext context)
{
float myy = context.y-(0.250025);
float myx = context.x-0.5;
Transforms::Zoom(p,context,0.98,1.503744);
p.x = p.x - (dx + 2*(2*myx*myy));
p.y = p.y - (dy + 2*((myy*myy) - (myx*myx)));
return p;
}
};

View File

@ -1,220 +0,0 @@
#include "Transformation.hpp"
#include <vector>
#include <math.h>
#include <stdio.h>
using namespace std;
PerPixelTransform::PerPixelTransform(int width, int height) :
width(width), height(height) {}
Warp::Warp(int width, int height, float warp, float speed, float scale) :
PerPixelTransform(width, height),
speed(speed),scale(scale), warp(warp){}
PerPixelWarp::PerPixelWarp(int width, int height, float warp, float speed, float scale) :
PerPixelTransform(width, height),
speed(speed),scale(scale),
warp(width,vector<float>(height,warp)){}
Scale::Scale(int width, int height, float cx, float cy, float sx, float sy) :
PerPixelTransform(width, height),
cx(cx), cy(cy), sx(sx), sy(sy){}
PerPixelScale::PerPixelScale(int width, int height, float cx, float cy, float sx, float sy) :
PerPixelTransform(width, height),
cx(width,vector<float>(height,cx)),
cy(width,vector<float>(height,cy)),
sx(width,vector<float>(height,sx)),
sy(width,vector<float>(height,sy)){}
Rotation::Rotation(int width, int height, float cx, float cy, float angle) :
PerPixelTransform(width, height),
cx(cx), cy(cy), angle(angle){}
PerPixelRotation::PerPixelRotation(int width, int height, float cx, float cy, float angle) :
PerPixelTransform(width, height),
cx(width,vector<float>(height,cx)), cy(width,vector<float>(height,cy)), angle(width,vector<float>(height,angle)){}
Delta::Delta(int width, int height, float dx, float dy) :
PerPixelTransform(width, height),
dx(dx), dy(dy){}
void Calculate (PerPixelMesh* mesh);
PerPixelDelta::PerPixelDelta(int width, int height, float dx, float dy) :
PerPixelTransform(width, height),
dx(width,vector<float>(height,dx)), dy(width,vector<float>(height,dy)){}
void Calculate (PerPixelMesh* mesh);
Zoom::Zoom(int width, int height, float zoom, float zoomExponent) :
PerPixelTransform(width, height),
zoom(zoom), zoomExponent(zoomExponent){}
PerPixelZoom::PerPixelZoom(int width, int height, float zoom, float zoomExponent) :
PerPixelTransform(width, height),
zoom(width,vector<float>(height,zoom)), zoomExponent(width,vector<float>(height,zoomExponent)){}
void Warp::Calculate(PerPixelMesh* mesh)
{
float fWarpTime = time * speed;
float fWarpScaleInv = 1.0f / scale;
float f[4];
f[0] = 11.68f + 4.0f*cosf(fWarpTime*1.413f + 10);
f[1] = 8.77f + 3.0f*cosf(fWarpTime*1.113f + 7);
f[2] = 10.54f + 3.0f*cosf(fWarpTime*1.233f + 3);
f[3] = 11.49f + 4.0f*cosf(fWarpTime*0.933f + 5);
for (int i=0;i<width;i++)
{
for(int j=0;j<height;j++)
{
mesh->x[i][j] += warp*0.0035f*sinf(fWarpTime*0.333f + fWarpScaleInv*(mesh->x_identity[i][j]*f[0] - mesh->y_identity[i][j]*f[3]));
mesh->y[i][j] += warp*0.0035f*cosf(fWarpTime*0.375f - fWarpScaleInv*(mesh->x_identity[i][j]*f[2] + mesh->y_identity[i][j]*f[1]));
mesh->x[i][j] += warp*0.0035f*cosf(fWarpTime*0.753f - fWarpScaleInv*(mesh->x_identity[i][j]*f[1] - mesh->y_identity[i][j]*f[2]));
mesh->y[i][j] += warp*0.0035f*sinf(fWarpTime*0.825f + fWarpScaleInv*(mesh->x_identity[i][j]*f[0] + mesh->y_identity[i][j]*f[3]));
}
}
}
void PerPixelWarp::Calculate(PerPixelMesh* mesh)
{
float fWarpTime = time * speed;
float fWarpScaleInv = 1.0f / scale;
float f[4];
f[0] = 11.68f + 4.0f*cosf(fWarpTime*1.413f + 10);
f[1] = 8.77f + 3.0f*cosf(fWarpTime*1.113f + 7);
f[2] = 10.54f + 3.0f*cosf(fWarpTime*1.233f + 3);
f[3] = 11.49f + 4.0f*cosf(fWarpTime*0.933f + 5);
for (int i=0;i<width;i++)
{
for(int j=0;j<height;j++)
{
mesh->x[i][j] += warp[i][j]*0.0035f*sinf(fWarpTime*0.333f + fWarpScaleInv*(mesh->x_identity[i][j]*f[0] - mesh->y_identity[i][j]*f[3]));
mesh->y[i][j] += warp[i][j]*0.0035f*cosf(fWarpTime*0.375f - fWarpScaleInv*(mesh->x_identity[i][j]*f[2] + mesh->y_identity[i][j]*f[1]));
mesh->x[i][j] += warp[i][j]*0.0035f*cosf(fWarpTime*0.753f - fWarpScaleInv*(mesh->x_identity[i][j]*f[1] - mesh->y_identity[i][j]*f[2]));
mesh->y[i][j] += warp[i][j]*0.0035f*sinf(fWarpTime*0.825f + fWarpScaleInv*(mesh->x_identity[i][j]*f[0] + mesh->y_identity[i][j]*f[3]));
}
}
}
void PerPixelScale::Calculate(PerPixelMesh* mesh)
{
for (int i=0;i<width;i++)
{
for(int j=0;j<height;j++)
{
mesh->x[i][j] = ( mesh->x[i][j] - cx[i][j])/sx[i][j] + cx[i][j];
mesh->y[i][j] = ( mesh->y[i][j] - cy[i][j])/sy[i][j] + cy[i][j];
}
}
}
void Scale::Calculate(PerPixelMesh* mesh)
{
for (int i=0;i<width;i++)
{
for(int j=0;j<height;j++)
{
mesh->x[i][j] = ( mesh->x[i][j] - cx)/sx + cx;
mesh->y[i][j] = ( mesh->y[i][j] - cy)/sy + cy;
}
}
}
void Zoom::Calculate(PerPixelMesh* mesh)
{
for (int i=0;i<width;i++)
{
for(int j=0;j<height;j++)
{
float fZoom2 = powf( zoom, powf( zoomExponent, mesh->rad_identity[i][j]*2.0f - 1.0f));
float fZoom2Inv = 1.0f/fZoom2;
mesh->x[i][j]= mesh->x[i][j]*0.5f*fZoom2Inv + 0.5f;
mesh->y[i][j]= mesh->y[i][j]*0.5f*fZoom2Inv + 0.5f;
}
}
}
void PerPixelZoom::Calculate(PerPixelMesh* mesh)
{
for (int i=0;i<width;i++)
{
for(int j=0;j<height;j++)
{
float fZoom2 = powf( zoom[i][j], powf( zoomExponent[i][j], mesh->rad_identity[i][j]*2.0f - 1.0f));
float fZoom2Inv = 1.0f/fZoom2;
mesh->x[i][j]= mesh->x[i][j]*0.5f*fZoom2Inv + 0.5f;
mesh->y[i][j]= mesh->y[i][j]*0.5f*fZoom2Inv + 0.5f;
}
}
}
void Rotation::Calculate(PerPixelMesh* mesh)
{
for (int i=0;i<width;i++)
{
for(int j=0;j<height;j++)
{
float u2 = mesh->x[i][j] - cx;
float v2 = mesh->y[i][j] - cy;
float cos_rot = cosf(angle);
float sin_rot = sinf(angle);
mesh->x[i][j] = u2*cos_rot - v2*sin_rot + cx;
mesh->y[i][j] = u2*sin_rot + v2*cos_rot + cy;
}
}
}
void PerPixelRotation::Calculate(PerPixelMesh* mesh)
{
for (int i=0;i < width;i++)
{
for(int j=0;j<height;j++)
{
float u2 = mesh->x[i][j] - cx[i][j];
float v2 = mesh->y[i][j] - cy[i][j];
float cos_rot = cosf(angle[i][j]);
float sin_rot = sinf(angle[i][j]);
mesh->x[i][j] = u2*cos_rot - v2*sin_rot + cx[i][j];
mesh->y[i][j] = u2*sin_rot + v2*cos_rot + cy[i][j];
}
}
}
void Delta::Calculate(PerPixelMesh* mesh)
{
for (int i=0;i < width;i++)
{
for(int j=0;j<height;j++)
{
mesh->x[i][j] -= dx;
mesh->y[i][j] -= dy;
}
}
}
void PerPixelDelta::Calculate(PerPixelMesh* mesh)
{
for (int i=0;i < width;i++)
{
for(int j=0;j<height;j++)
{
mesh->x[i][j] -= dx[i][j];
mesh->y[i][j] -= dy[i][j];
}
}
}

View File

@ -2,126 +2,65 @@
#define Transformation_HPP
#include "PerPixelMesh.hpp"
#include <vector>
#include <math.h>
class PerPixelTransform
class Transforms
{
public:
int width;
int height;
PerPixelTransform(int width, int height);
virtual void Calculate(PerPixelMesh* mesh) = 0;
};
inline static void Zoom(Point &p, PerPixelContext &context, float zoom, float zoomExponent)
{
float fZoom2 = powf( zoom, powf( zoomExponent, context.rad*2.0f - 1.0f));
float fZoom2Inv = 1.0f/fZoom2;
p.x -= 0.5;
p.y -= 0.5;
p.x *= fZoom2Inv;
p.y *= fZoom2Inv;
p.x += 0.5;
p.y += 0.5;
}
class Warp : public PerPixelTransform
{
public:
float warp;
float speed;
float scale;
float time;
inline static void Transform(Point &p, PerPixelContext &context, float dx, float dy)
{
p.x -= dx;
p.y -= dy;
}
Warp(int width, int height, float warp, float speed, float scale);
void Calculate(PerPixelMesh* mesh);
};
inline static void Scale(Point &p, PerPixelContext &context, float sy, float sx, float cx, float cy)
{
p.x = (p.x - cx)/sx + cx;
p.y = (p.y - cy)/sy + cy;
}
class PerPixelWarp : public PerPixelTransform
{
public:
std::vector< std::vector<float> > warp;
float speed;
float scale;
float time;
inline static void Rotate(Point &p, PerPixelContext &context, float angle, float cx, float cy)
{
float u2 = p.x - cx;
float v2 = p.y - cy;
PerPixelWarp(int width, int height, float warp, float speed, float scale);
void Calculate(PerPixelMesh* mesh);
};
float cos_rot = cosf(angle);
float sin_rot = sinf(angle);
class Scale : public PerPixelTransform
{
public:
float cx;
float cy;
float sx;
float sy;
p.x = u2*cos_rot - v2*sin_rot + cx;
p.y = u2*sin_rot + v2*cos_rot + cy;
}
Scale(int width, int height, float cx, float cy, float sx, float sy);
void Calculate(PerPixelMesh* mesh);
};
inline static void Warp(Point &p, PerPixelContext &context, float time, float speed, float scale, float warp)
{
float fWarpTime = time * speed;
float fWarpScaleInv = 1.0f / scale;
float f[4];
f[0] = 11.68f + 4.0f*cosf(fWarpTime*1.413f + 10);
f[1] = 8.77f + 3.0f*cosf(fWarpTime*1.113f + 7);
f[2] = 10.54f + 3.0f*cosf(fWarpTime*1.233f + 3);
f[3] = 11.49f + 4.0f*cosf(fWarpTime*0.933f + 5);
class PerPixelScale : public PerPixelTransform
{
public:
std::vector< std::vector<float> > cx;
std::vector< std::vector<float> > cy;
std::vector< std::vector<float> > sx;
std::vector< std::vector<float> > sy;
p.x += warp*0.0035f*sinf(fWarpTime*0.333f + fWarpScaleInv*(context.x*f[0] - context.y*f[3]));
p.y += warp*0.0035f*cosf(fWarpTime*0.375f - fWarpScaleInv*(context.x*f[2] + context.y*f[1]));
p.x += warp*0.0035f*cosf(fWarpTime*0.753f - fWarpScaleInv*(context.x*f[1] - context.y*f[2]));
p.y += warp*0.0035f*sinf(fWarpTime*0.825f + fWarpScaleInv*(context.x*f[0] + context.y*f[3]));
}
PerPixelScale(int width, int height, float cx, float cy, float sx, float sy);
void Calculate(PerPixelMesh* mesh);
};
class Rotation : public PerPixelTransform
{
public:
float cx;
float cy;
float angle;
Rotation(int width, int height, float cx, float cy, float angle);
void Calculate(PerPixelMesh* mesh);
};
class PerPixelRotation : public PerPixelTransform
{
public:
std::vector< std::vector<float> > cx;
std::vector< std::vector<float> > cy;
std::vector< std::vector<float> > angle;
PerPixelRotation(int width, int height, float cx, float cy, float angle);
void Calculate(PerPixelMesh* mesh);
};
class Delta : public PerPixelTransform
{
public:
float dx;
float dy;
Delta(int width, int height, float dx, float dy);
void Calculate (PerPixelMesh* mesh);
};
class PerPixelDelta : public PerPixelTransform
{
public:
std::vector< std::vector<float> > dx;
std::vector< std::vector<float> > dy;
PerPixelDelta(int width, int height, float dx, float dy);
virtual void Calculate (PerPixelMesh* mesh);
};
class Zoom : public PerPixelTransform
{
public:
float zoom;
float zoomExponent;
Zoom(int width, int height, float zoom, float zoomExponent);
void Calculate (PerPixelMesh* mesh);
};
class PerPixelZoom : public PerPixelTransform
{
public:
std::vector< std::vector<float> > zoom;
std::vector< std::vector<float> > zoomExponent;
PerPixelZoom(int width, int height, float zoom, float zoomExponent);
void Calculate (PerPixelMesh* mesh);
};
#endif