やってみました。
※ソースを少し修正しました。動作は変わっていないと思います。
//- 以下、サンプル (SimpleModel.mqoを使用) -//
#include "DxLib.h"
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
ChangeWindowMode( TRUE );
if( DxLib_Init() < 0 )
return -1 ;
int ModelHandle = MV1LoadModel( "SimpleModel.mqo" );
float CamV = 0.0f, CamH = 0.0f, CamR = 800.0f;
const float MinV = -PHI_F / 180.0f * 72.5f, MaxV = PHI_F / 180.0f * 72.5f;
const float MinH = 0.0f, MaxH = PHI_F * 2.0f;
const float MinR = 200.0f, MaxR = 2000.0f;
const float AngleRate = PHI_F / 180.0f, ZoomRate = 10.0f;
MATRIX RotV, RotH;
VECTOR CamPos = VGet( 0.0f, 0.0f, -CamR ), FocusPos = VGet( 0.0f, 0.0f, 0.0f );
int NewX = 0, NewY = 0, NewBtn = 0, OldX = 0, OldY = 0, OldBtn = 0;
int MoveX = 0, MoveY = 0, MoveZ = 0;
SetDrawScreen( DX_SCREEN_BACK );
while ( ProcessMessage( ) == 0 && !CheckHitKey( KEY_INPUT_ESCAPE ) )
{
ClearDrawScreen( );
// スペースキーで初期化
if ( CheckHitKey( KEY_INPUT_SPACE ) ) {
CamV = 0.0f;
CamH = 0.0f;
CamR = 800.0f;
}
// マウス入力の取得
MoveX = MoveY = 0;
MoveZ = -GetMouseWheelRotVol( );
if ( (NewBtn = GetMouseInput( )) & MOUSE_INPUT_LEFT ) {
GetMousePoint( &NewX, &NewY );
if ( OldBtn & MOUSE_INPUT_LEFT ) {
MoveX = NewX - OldX;
MoveY = NewY - OldY;
}
OldX = NewX; OldY = NewY;
}
OldBtn = NewBtn;
// マウスの情報からカメラの情報に変換
CamV += MoveY * AngleRate;
CamH += MoveX * AngleRate;
CamR += MoveZ * ZoomRate;
// 補正
if ( CamV > MaxV ) CamV = MaxV;
if ( CamV < MinV ) CamV = MinV;
if ( CamH > MaxH ) CamH -= MaxH;
if ( CamH < MinH ) CamH += MaxH;
if ( CamR > MaxR ) CamR = MaxR;
if ( CamR < MinR ) CamR = MinR;
// カメラの設定
RotV = MGetRotX( CamV );
RotH = MGetRotY( CamH );
CamPos = VTransform( VTransform( VGet( 0.0f, 0.0f, -CamR ), RotV ), RotH );
SetCameraPositionAndTarget_UpVecY( CamPos, FocusPos );
DrawLine3D( VGet( 0.0f, 0.0f, 0.0f ), VGet( 1000.0f, 0.0f, 0.0f ), GetColor( 255, 0, 0 ) );
DrawLine3D( VGet( 0.0f, 0.0f, 0.0f ), VGet( 0.0f, 1000.0f, 0.0f ), GetColor( 0, 255, 0 ) );
DrawLine3D( VGet( 0.0f, 0.0f, 0.0f ), VGet( 0.0f, 0.0f, 1000.0f ), GetColor( 0, 0, 255 ) );
MV1DrawModel( ModelHandle );
ScreenFlip( );
}
DxLib_End( );
return 0;
}