この回転と
[youtube][/youtube]
この回転です
[youtube][/youtube]
二つを融合させて自然に桜の花びらが舞い散るようにしたいのですが、どのような処理が必要になってくるのでしょうか?
現在以下のようにそれぞれコードを書いていますが、X,Y軸の推移のさせ方がさっぱりわからないです。
サンプルコードなどありましたらうれしいです。詳しい方お願いいたします。
時計回りに回転させているコード
► スポイラーを表示
#include "DxLib.h"
#include <math.h>
#define Rate_X 0.55
#define Rate_y 0.83
#define PI 3.14
class sakura{
private:
int nHandle; //画像ハンドル
int nImageSizeX; //画像Xサイズ
int nImageSizeY; //画像Yサイズ
float x[2]; //X軸の実座標
float y[2]; //Y軸の実座標
double locate[4][2];//実座標
int accx; //X加速度
int accy; //Y加速度
float nRotateX; //X軸の回転速度
float nRotateY; //Y軸の回転速度
bool bRotateX; //回転フラグ
bool bRotateY;
bool bRotateTime; //X,Yどちらに回転させるか
float nExRate; //画像の倍率
float nAngle; //角度
float Rate[4];
public:
sakura(); //コンストラクタ
void ShowImage(); //画像描写
void SetStatus(); //加速
void Rotate1(); //平面回転運動
};
//コンストラクタ
//初期パラメータの設定
sakura::sakura(){
RECT rc;
GetWindowCRect(&rc);
//画像情報の読み込み
nHandle = LoadGraph("画像//sakura.png");
GetGraphSize(nHandle,&nImageSizeX,&nImageSizeY);
//画像倍率の取得
nExRate = rand() % 100 * 0.01 + 0.3;
//倍画像率の調整
nImageSizeX *= nExRate;
nImageSizeY *= nExRate;
//出現位置の調整
if((rand() % 10) / 2 == 0){
//X軸の初期位置、Y軸は0
x[0] = 0;
y[0] =100;
}else{
//Y軸の初期位置、X軸は0
y[0] = 100;
x[0] = 100;
}
//X加速度の取得
accx = (rand() % 10) * sin(0.5) +1;
//Y加速度の取得
accy = rand() % 10 + 0.5 +1;
//X軸回転速度の取得
nRotateX = (float)GetRand(20) * 0.2;
//Y軸回転速度の取得
nRotateY = (float)GetRand(20) * 0.2;
nAngle = 1;
}
//描写関数
void sakura::ShowImage(){
DrawModiGraph(locate[0][0],locate[0][1], //左上
locate[1][0],locate[1][1] , //右上
locate[3][0],locate[3][1], //右下
locate[2][0],locate[2][1], //左下
nHandle,true);
return;
}
//平面回転運動
void sakura::Rotate1(){
float X,Y;
//画像の回転処理
X = -(nImageSizeX / 2) * cos( nAngle * PI / 180.0) - -(nImageSizeY / 2) * sin( nAngle * PI / 180.0);
Y = -(nImageSizeX / 2) * sin( nAngle * PI / 180.0) + -(nImageSizeY / 2) * cos( nAngle * PI / 180.0);
locate[0][0] = x[0] + X;
locate[0][1] = y[0] + Y;
X = (nImageSizeX /2) * cos( nAngle * PI / 180.0) - -(nImageSizeY / 2) * sin( nAngle * PI / 180.0);
Y = (nImageSizeX / 2) * sin( nAngle * PI / 180.0) + -(nImageSizeY / 2) * cos( nAngle * PI / 180.0);
locate[1][0] = x[0] + X;
locate[1][1] = y[0] + Y;
X = -(nImageSizeX /2) * cos( nAngle * PI / 180.0) - (nImageSizeY / 2) * sin( nAngle * PI / 180.0);
Y = -(nImageSizeX / 2) * sin( nAngle * PI / 180.0) + (nImageSizeY / 2) * cos( nAngle * PI / 180.0);
locate[2][0] = x[0] + X;
locate[2][1] = y[0] + Y;
X = (nImageSizeX /2) * cos( nAngle * PI / 180.0) - (nImageSizeY / 2) * sin( nAngle * PI / 180.0);
Y = (nImageSizeX / 2) * sin( nAngle * PI / 180.0) + (nImageSizeY / 2) * cos( nAngle * PI / 180.0);
locate[3][0] = x[0] + X;
locate[3][1] = y[0] + Y;
//角度の増加
nAngle++;
if(nAngle == 360){
nAngle = 0;
}
return;
}
//移動設定関数
void sakura::SetStatus(){
RECT rc;
//X,Y軸の加速
//x[0] += accx;
//y[0] += accy;
DrawFormatString(300,100,RGB(255,255,255),"座標 左上X[%f]Y[%f]",locate[0][0],locate[0][1]);
DrawFormatString(300,150,RGB(255,255,255),"座標 右上X[%f]Y[%f]",locate[1][0],locate[1][1]);
DrawFormatString(300,200,RGB(255,255,255),"座標 右下X[%f]Y[%f]",locate[3][0],locate[3][1]);
DrawFormatString(300,250,RGB(255,255,255),"座標 左下X[%f]Y[%f]",locate[2][0],locate[2][1]);
DrawFormatString(300,350,RGB(255,255,255),"フラグ %d",bRotateX);
DrawFormatString(300,400,RGB(255,255,255),"angle %f",nAngle);
return;
}
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE);
DxLib_Init();
SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定
int i = 0,n;
sakura sk[300];
// while(裏画面を表画面に反映, メッセージ処理, 画面クリア)
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 ){
//桜の描写タイミングを調整
if(i < 1){
if(rand() % 10 != 7){
i++;
}
}
for(n = 0;n < i; n++){
sk[n].ShowImage();
sk[n].SetStatus();
sk[n].Rotate1();
}
ScreenFlip(); //裏画面を表画面に反映
}
DxLib_End(); // DXライブラリ終了処理
return 0;
}
くるくる回転させているコード
► スポイラーを表示
#include "DxLib.h"
#include <math.h>
#define Rate_X 0.55
#define Rate_y 0.83
#define PI 3.14
class sakura{
private:
int nHandle; //画像ハンドル
int nImageSizeX; //画像Xサイズ
int nImageSizeY; //画像Yサイズ
float x[2]; //X軸の実座標
float y[2]; //Y軸の実座標
int accx; //X加速度
int accy; //Y加速度
float nRotateX; //X軸の回転速度
float nRotateY; //Y軸の回転速度
bool bRotateX; //回転フラグ
float nExRate; //画像の倍率
public:
sakura(); //コンストラクタ
void ShowImage(); //画像描写
void SetStatus(); //加速
};
//コンストラクタ
//初期パラメータの設定
sakura::sakura(){
RECT rc;
GetWindowCRect(&rc);
//画像情報の読み込み
nHandle = LoadGraph("画像//sakura.png");
GetGraphSize(nHandle,&nImageSizeX,&nImageSizeY);
//画像倍率の取得
nExRate = rand() % 100 * 0.01 + 0.3;
//倍画像率の調整
nImageSizeX *= nExRate;
nImageSizeY *= nExRate;
//出現位置の調整
if((rand() % 10) / 2 == 0){
//X軸の初期位置、Y軸は0
x[0] = 0;
x[1] = x[0] + nImageSizeX;
y[0] = 0;
y[1] = y[0] + nImageSizeY;
}else{
//Y軸の初期位置、X軸は0
y[0] = 0;
y[1] = y[0] + nImageSizeY;
x[0] = 0;
x[1] = x[0] + nImageSizeX;
}
//X加速度の取得
accx = (rand() % 10) * 0.5 +1;
//Y加速度の取得
accy = rand() % 10 + 0.5 +1;
//X軸回転速度の取得
nRotateX = (float)GetRand(20) * 0.2;
//Y軸回転速度の取得
nRotateY = (float)GetRand(20) * 0.2;
//回転フラグの取得
bRotateX = 0;
}
//描写関数
void sakura::ShowImage(){
DrawModiGraph(x[0],y[0],
x[1],y[0],
x[1],y[1],
x[0],y[1],nHandle,true);
return;
}
//移動設定関数
void sakura::SetStatus(){
RECT rc;
//X,Y軸の加速
//x[0] += accx;
//x[1] += accx;
//y[0] += accy;
//y[1] += accy;
//X軸に沿って画像を回転させる
x[0] += nRotateX;
x[1] -= nRotateX;
//if(nRotateX < 0.5){
//X軸に沿って画像を回転させる
//y[0] += nRotateY;
//y[1] -= nRotateY;
//}
//画像の回転方向の切り替え
if(x[0] - x[1] > nImageSizeX && bRotateX == 0){
bRotateX = 1;
nRotateX *= -1;
nRotateY *= -1;
}else if(x[1] - x[0] > nImageSizeX && bRotateX == 1){
bRotateX = 0;
nRotateX *= -1;
nRotateY *= -1;
}else{
}
//落下しきった花びらのリサイクル設定
GetWindowCRect(&rc);
if(y[1] + nImageSizeY > rc.bottom || x[1] + nImageSizeX > rc.right){
//出現位置の調整
if((rand() % 10) / 2 == 0){
//X軸の初期位置、Y軸は0
x[0] = (rand() % ((rc.right - rc.left) - 10)) / 2 + 200;
x[1] = x[0] + nImageSizeX;
y[0] = nImageSizeY * -1;
y[1] = y[0] + nImageSizeY;
}else{
//Y軸の初期位置、X軸は0
y[0] = (rand() % ((rc.right - rc.left) - 10)) / 2 - 200;
y[1] = y[0] + nImageSizeY;
x[0] = nImageSizeX * -1;
x[1] = x[0] + nImageSizeX;
}
}
DrawFormatString(300,100,RGB(255,255,255),"座標 左上X[%f]Y[%f]",x[0],y[0]);
DrawFormatString(300,150,RGB(255,255,255),"座標 右上X[%f]Y[%f]",x[1],y[0]);
DrawFormatString(300,200,RGB(255,255,255),"座標 右下X[%f]Y[%f]",x[1],y[1]);
DrawFormatString(300,250,RGB(255,255,255),"座標 左下X[%f]Y[%f]",x[0],y[1]);
DrawFormatString(300,350,RGB(255,255,255),"フラグ %d",bRotateX);
return;
}
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE);
DxLib_Init();
SetDrawScreen( DX_SCREEN_BACK ); //ウィンドウモード変更と初期化と裏画面設定
int i = 0,n;
sakura sk[200];
// while(裏画面を表画面に反映, メッセージ処理, 画面クリア)
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 ){
//桜の描写タイミングを調整
if(i <1){
if(rand() % 10 != 7){
i++;
}
}
for(n = 0;n < i; n++){
sk[n].ShowImage();
sk[n].SetStatus();
}
ScreenFlip(); //裏画面を表画面に反映
}
DxLib_End(); // DXライブラリ終了処理
return 0;
}