#7
by ctyu » 6年前
コード:
#include <DxLib.h>
#include <math.h>
void rotate(float *x, float *y, const float ang, const float mx, const float my) {
const float ox = *x - mx, oy = *y - my;
*x = ox * cos(ang) + oy * sin(ang);
*y = -ox * sin(ang) + oy * cos(ang);
*x += mx;
*y += my;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
ChangeWindowMode(FALSE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
int Handle = MV1LoadModel("3Dsample/dat/Lat式ミク/Lat式ミクVer2.3_Normal.pmd");
float camera_x = 0.0 , camera_y = 10.0, camera_z = -20.0;
float target_x = 0.0, target_y = 10.0, target_z = 0.0;
float x = 0.0, y = 0.0, z = 0.0;
int mouse_x_check = 0, mouse_y_check = 0;
float camera_speed_x = 0.0;
float camera_speed_y = 0.0;
SetCameraNearFar(0.1, 10000.0);
SetCameraPositionAndTarget_UpVecY(VGet(camera_x, camera_y, camera_z), VGet(target_x, target_y, target_z));
while (!ScreenFlip() && !ProcessMessage() && !ClearDrawScreen()) {
GetMousePoint(&mouse_x_check, &mouse_y_check); //マウス座標の更新
if (0 < mouse_x_check) { //マウスの横移動の処理、マウスが右に移動したらカメラを右回転に設定
camera_speed_x = 0.1;
}
else {
if (0 > mouse_x_check) { //マウスが左に移動したらカメラを左回転に設定
camera_speed_x = -0.1;
}
else {
camera_speed_x = 0.0; //マウスが動いてなければカメラの横移動をキャンセル
}
}
if (10 > mouse_y_check && camera_y > 3) { //マウスの縦移動の処理、マウスが下に移動したらカメラを下回転に設定
camera_speed_y = 0.1;
}
else {
if (10 < mouse_y_check && camera_y < 28.0 ) { //マウスが上に移動したらカメラを上回転に設定
camera_speed_y = -0.1;
}
else {
camera_speed_y = 0.0; //マウスが動いてなければカメラの縦移動をキャンセル
}
}
SetMousePoint(0, 10); //マウス座標リセット
rotate(&camera_x, &camera_z, camera_speed_x, target_x, target_z); //カメラを回転
rotate(&camera_y, &camera_x, camera_speed_y, target_y, target_x); //カメラを回転
rotate(&camera_z, &camera_y, camera_speed_y, target_z, target_y); //カメラを回転
if (CheckHitKey(KEY_INPUT_A)) {
camera_x -= 0.1;
}
if (CheckHitKey(KEY_INPUT_D)) {
camera_x += 0.1;
}
if (CheckHitKey(KEY_INPUT_W)) {
camera_z += 0.1;
}
if (CheckHitKey(KEY_INPUT_S)) {
camera_z -= 0.1;
}
SetCameraPositionAndTarget_UpVecY(VGet(camera_x, camera_y, camera_z), VGet(target_x, target_y,target_z));
MV1SetPosition(Handle, VGet(x, y, z));
MV1DrawModel(Handle);
DrawFormatString(10, 10, GetColor(0, 255, 0), "x = %f y = %f z = %f speed = %f",camera_x,camera_y,camera_z,camera_speed_y);
}
DxLib_End();
return 0;
}
これでもだめでした
はやくも3Dゲームの制作をあきらめそうです...
どこをどうすればいいでしょうか?
[code]
#include <DxLib.h>
#include <math.h>
void rotate(float *x, float *y, const float ang, const float mx, const float my) {
const float ox = *x - mx, oy = *y - my;
*x = ox * cos(ang) + oy * sin(ang);
*y = -ox * sin(ang) + oy * cos(ang);
*x += mx;
*y += my;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
ChangeWindowMode(FALSE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
int Handle = MV1LoadModel("3Dsample/dat/Lat式ミク/Lat式ミクVer2.3_Normal.pmd");
float camera_x = 0.0 , camera_y = 10.0, camera_z = -20.0;
float target_x = 0.0, target_y = 10.0, target_z = 0.0;
float x = 0.0, y = 0.0, z = 0.0;
int mouse_x_check = 0, mouse_y_check = 0;
float camera_speed_x = 0.0;
float camera_speed_y = 0.0;
SetCameraNearFar(0.1, 10000.0);
SetCameraPositionAndTarget_UpVecY(VGet(camera_x, camera_y, camera_z), VGet(target_x, target_y, target_z));
while (!ScreenFlip() && !ProcessMessage() && !ClearDrawScreen()) {
GetMousePoint(&mouse_x_check, &mouse_y_check); //マウス座標の更新
if (0 < mouse_x_check) { //マウスの横移動の処理、マウスが右に移動したらカメラを右回転に設定
camera_speed_x = 0.1;
}
else {
if (0 > mouse_x_check) { //マウスが左に移動したらカメラを左回転に設定
camera_speed_x = -0.1;
}
else {
camera_speed_x = 0.0; //マウスが動いてなければカメラの横移動をキャンセル
}
}
if (10 > mouse_y_check && camera_y > 3) { //マウスの縦移動の処理、マウスが下に移動したらカメラを下回転に設定
camera_speed_y = 0.1;
}
else {
if (10 < mouse_y_check && camera_y < 28.0 ) { //マウスが上に移動したらカメラを上回転に設定
camera_speed_y = -0.1;
}
else {
camera_speed_y = 0.0; //マウスが動いてなければカメラの縦移動をキャンセル
}
}
SetMousePoint(0, 10); //マウス座標リセット
rotate(&camera_x, &camera_z, camera_speed_x, target_x, target_z); //カメラを回転
rotate(&camera_y, &camera_x, camera_speed_y, target_y, target_x); //カメラを回転
rotate(&camera_z, &camera_y, camera_speed_y, target_z, target_y); //カメラを回転
if (CheckHitKey(KEY_INPUT_A)) {
camera_x -= 0.1;
}
if (CheckHitKey(KEY_INPUT_D)) {
camera_x += 0.1;
}
if (CheckHitKey(KEY_INPUT_W)) {
camera_z += 0.1;
}
if (CheckHitKey(KEY_INPUT_S)) {
camera_z -= 0.1;
}
SetCameraPositionAndTarget_UpVecY(VGet(camera_x, camera_y, camera_z), VGet(target_x, target_y,target_z));
MV1SetPosition(Handle, VGet(x, y, z));
MV1DrawModel(Handle);
DrawFormatString(10, 10, GetColor(0, 255, 0), "x = %f y = %f z = %f speed = %f",camera_x,camera_y,camera_z,camera_speed_y);
}
DxLib_End();
return 0;
}
[/code]
これでもだめでした
はやくも3Dゲームの制作をあきらめそうです...
どこをどうすればいいでしょうか?