I copied CCWave3D to modify and make a new action CCFlag3D with the left border always still (is attached to a goalpost).
CCFlag3D.h
#pragma once
//#include "c:\macshare\cocos2d-2.1rc0-x-2.1.3\cocos2dx\actions\ccactiongrid.h"
//#include "cocos2d.h"
#include "actions\CCActionGrid.h"
NS_CC_BEGIN
class CCFlag3D : public CCGrid3DAction
{
public:
CCFlag3D(void);
~CCFlag3D(void);
inline float getAmplitude(void) { return m_fAmplitude; }
inline void setAmplitude(float fAmplitude) { m_fAmplitude = fAmplitude; }
inline float getAmplitudeRate(void) { return m_fAmplitudeRate; }
inline void setAmplitudeRate(float fAmplitudeRate) { m_fAmplitudeRate = fAmplitudeRate; }
/** initializes an action with duration, grid size, waves and amplitude */
bool initWithDuration(float duration, const CCSize& gridSize, unsigned int waves, float amplitude);
virtual CCObject* copyWithZone(CCZone* pZone);
virtual void update(float time);
static CCFlag3D* create(float duration, const CCSize& gridSize, unsigned int waves, float amplitude);
protected:
unsigned int m_nWaves;
float m_fAmplitude;
float m_fAmplitudeRate;
};
NS_CC_END
CCFlag3D.cpp
#include "CFlag3D.h"
#include "actions/CCActionGrid3D.h"
#include "support/CCPointExtension.h"
#include "CCDirector.h"
#include "cocoa/CCZone.h"
#include
NS_CC_BEGIN
CCFlag3D::CCFlag3D(void)
{
}
CCFlag3D::~CCFlag3D(void)
{
}
CCFlag3D* CCFlag3D::create(float duration, const CCSize& gridSize, unsigned int waves, float amplitude)
{
CCFlag3D *pAction = new CCFlag3D();
if (pAction)
{
if (pAction->initWithDuration(duration, gridSize, waves, amplitude))
{
pAction->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pAction);
}
}
return pAction;
}
bool CCFlag3D::initWithDuration(float duration, const CCSize& gridSize, unsigned int waves, float amplitude)
{
if (CCGrid3DAction::initWithDuration(duration, gridSize))
{
m_nWaves = waves;
m_fAmplitude = amplitude;
m_fAmplitudeRate = 1.0f;
return true;
}
return false;
}
CCObject* CCFlag3D::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCFlag3D* pCopy = NULL;
if(pZone && pZone->m_pCopyObject)
{
//in case of being called at sub class
pCopy = (CCFlag3D*)(pZone->m_pCopyObject);
}
else
{
pCopy = new CCFlag3D();
pZone = pNewZone = new CCZone(pCopy);
}
CCGrid3DAction::copyWithZone(pZone);
pCopy->initWithDuration(m_fDuration, m_sGridSize, m_nWaves, m_fAmplitude);
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
void CCFlag3D::update(float time)
{
int i, j;
for (i = 0; i < m_sGridSize.width + 1; ++i)
{
for (j = 0; j < m_sGridSize.height + 1; ++j)
{
ccVertex3F v = originalVertex(ccp(i ,j));
v.z = (cosf((float)M_PI * 2 /m_sGridSize.width *i));//<<<<<<<<<<<<<<<<<----the only change
//CCLOG("v.z offset is %f\n", (sinf((float)M_PI * time * m_nWaves * 2 + (v.y+v.x) * .01f) * m_fAmplitude * m_fAmplitudeRate));
setVertex(ccp(i, j), v);
}
ccVertex3F v = originalVertex(ccp(i ,0));
CCLOG("x %f y %f z %f",v.x,v.y,v.z);
}
CCLOG("v");
}
NS_CC_END
CCLog shows coordinates from 0 to 960 that is the whole screen width and not the sprite width, I thought that when I choose for example m_sGridSize=30, the sprite were tiled in 30 pieces in width, but if the sprite is…suppose 480, it is divided into 15 pieces leaving the other 15 useless:
x 0.000000 y 0.000000 z 0.000000
x 0.000000 y 0.000000 z 0.000000
x 32.000000 y 0.000000 z 0.000000
x 64.000000 y 0.000000 z 0.000000
x 96.000000 y 0.000000 z 0.000000
x 128.000000 y 0.000000 z 0.000000
x 160.000000 y 0.000000 z 0.000000
x 192.000000 y 0.000000 z 0.000000
x 224.000000 y 0.000000 z 0.000000
x 256.000000 y 0.000000 z 0.000000
x 288.000000 y 0.000000 z 0.000000
x 320.000000 y 0.000000 z 0.000000
x 352.000000 y 0.000000 z 0.000000
x 384.000000 y 0.000000 z 0.000000
x 416.000000 y 0.000000 z 0.000000
x 448.000000 y 0.000000 z 0.000000
x 480.000000 y 0.000000 z 0.000000
x 512.000000 y 0.000000 z 0.000000
x 544.000000 y 0.000000 z 0.000000
x 576.000000 y 0.000000 z 0.000000
x 608.000000 y 0.000000 z 0.000000
x 640.000000 y 0.000000 z 0.000000
x 672.000000 y 0.000000 z 0.000000
x 704.000000 y 0.000000 z 0.000000
x 736.000000 y 0.000000 z 0.000000
x 768.000000 y 0.000000 z 0.000000
x 800.000000 y 0.000000 z 0.000000
x 832.000000 y 0.000000 z 0.000000
x 864.000000 y 0.000000 z 0.000000
x 896.000000 y 0.000000 z 0.000000
x 928.000000 y 0.000000 z 0.000000
x 960.000000 y 0.000000 z 0.000000
it is a bug? or it is made so?
thanks