MeshEffect.hpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:2k
- #ifndef _MESH_EFFECT_H_
- #define _MESH_EFFECT_H_
- #include "../../JGE/include/JDistortionMesh.h"
- #define MESH_EFFECT1 0
- #define MESH_EFFECT2 1
- class MeshEffect
- {
- private:
- float mMax;
- JDistortionMesh* mDistortionMesh;
- float mAlpha;
- float mTime;
- int mMode;
- int mCols;
- int mRows;
- float mX;
- float mY;
- public:
- MeshEffect(JTexture* tex, float x, float y, float width, float height, int cols=16, int rows=16)
- {
- mDistortionMesh = new JDistortionMesh(tex, x, y, width, height, cols, rows);
- mMax = 32.0f;
- mTime = 0.0f;
- mMode = MESH_EFFECT1;
- mCols = cols;
- mRows = rows;
- }
- ~MeshEffect()
- {
- delete mDistortionMesh;
- }
- void SetMode(int mode)
- {
- mMode = mode;
- }
- void SetMax(float max)
- {
- mMax = max;
- }
- void SetAlpha(float alpha)
- {
- mAlpha = alpha;
- }
-
- void SetPosition(float x, float y)
- {
- mX = x;
- mY = y;
- }
- void Update(float dt)
- {
-
- int i, j, col;
- mTime += (dt/1000.0f);
-
- int alpha = (int)mAlpha;
- float xDis, yDis;
-
- switch(mMode)
- {
- case MESH_EFFECT1:
- for(i=1;i<mRows-1;i++)
- for(j=1;j<mCols-1;j++)
- {
- xDis = cosf(mTime*10+(i+j)/2)*5;
- yDis = sinf(mTime*10+(i+j)/2)*5;
- if (xDis >= 0.0f)
- {
- if (xDis > mMax)
- xDis = mMax;
- }
- else
- {
- if (xDis < -mMax)
- xDis = -mMax;
- }
- if (yDis >= 0.0f)
- {
-
- if (yDis > mMax)
- yDis = mMax;
- }
- else
- {
- if (yDis < -mMax)
- yDis = -mMax;
- }
- mDistortionMesh->SetDisplacement(j,i,xDis,yDis);
- mDistortionMesh->SetColor(j,i,ARGB(alpha,0,0,0));
- }
- break;
- case MESH_EFFECT2:
- for(i=0;i<mRows;i++)
- for(j=1;j<mCols-1;j++)
- {
- xDis = cosf(mTime*5+j/2)*15;
- if (xDis >= 0.0f)
- {
- if (xDis > mMax)
- xDis = mMax;
- }
- else
- {
- if (xDis < -mMax)
- xDis = -mMax;
- }
-
- mDistortionMesh->SetDisplacement(j,i,xDis,0);
- col=int((cosf(mTime*5+(i+j)/2)+1)*35);
- mDistortionMesh->SetColor(j,i,ARGB(alpha,col,col,col));
- }
- break;
- }
- }
- void Render()
- {
- mDistortionMesh->Render(mX, mY);
- }
- };
- #endif