やってみましたが、できていないかもしれません・・・。
基本的には「DXライブラリ サンプルプログラム」の「32.3Dアクション基本」とあまり変わらないと思います。
(視点を動かさずにカメラの位置だけ平行移動させるのかもとも思ったのですが、とりあえず視点ごと平行移動しています)
※少し修正
//- 以下、テストコード ("SimpleModel.mqo" を使用) -//
#include "DxLib.h"
#include <math.h>
struct CAMERA_INFO {
VECTOR position; // Relative to Target
VECTOR target;
VECTOR head;
};
void init_camera( CAMERA_INFO& camera ) {
camera.position = VGet( 0.0f, 0.0f, -800.0f );
camera.target = VGet( 0.0f, 0.0f, 0.0f );
camera.head = VGet( 0.0f, 1.0f, 0.0f );
}
int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
const float rot_rate = PHI_F * 2.0f / 60.0f;
const float move_rate = 5.0f;
ChangeWindowMode( TRUE );
SetWindowText( "DxLib:" DXLIB_VERSION_STR );
if ( DxLib_Init( ) == -1 ) return -1;
int white = GetColor( 255, 255, 255 );
int mh = MV1LoadModel( "SimpleModel.mqo" );
SetDrawScreen( DX_SCREEN_BACK );
CAMERA_INFO camera;
init_camera( camera );
MATRIX matrixtemp;
while ( ProcessMessage( ) == 0 && CheckHitKey( KEY_INPUT_ESCAPE ) == 0 ) {
ClearDrawScreen( );
if ( CheckHitKey( KEY_INPUT_SPACE ) ) {
init_camera( camera );
}
else if ( CheckHitKey( KEY_INPUT_LSHIFT ) ) {
if ( CheckHitKey( KEY_INPUT_UP ) ) {
camera.target = VAdd( camera.target, VScale( VNorm( camera.head ), move_rate ) );
}
if ( CheckHitKey( KEY_INPUT_DOWN ) ) {
camera.target = VAdd( camera.target, VScale( VNorm( camera.head ), -move_rate ) );
}
if ( CheckHitKey( KEY_INPUT_LEFT ) ) {
camera.target = VAdd( camera.target, VScale( VNorm( VCross( camera.position, camera.head ) ), -move_rate ) );
}
if ( CheckHitKey( KEY_INPUT_RIGHT ) ) {
camera.target = VAdd( camera.target, VScale( VNorm( VCross( camera.position, camera.head ) ), move_rate ) );
}
if ( CheckHitKey( KEY_INPUT_Z ) ) {
camera.target = VAdd( camera.target, VScale( VNorm( camera.position ), -move_rate ) );
}
if ( CheckHitKey( KEY_INPUT_X ) ) {
camera.target = VAdd( camera.target, VScale( VNorm( camera.position ), move_rate ) );
}
}
else if ( CheckHitKey( KEY_INPUT_RSHIFT ) ) {
if ( CheckHitKey( KEY_INPUT_UP ) ) {
if ( VSize( camera.position ) > 300.0f ) {
camera.position = VAdd( camera.position, VScale( VNorm( camera.position ), -move_rate ) );
}
}
if ( CheckHitKey( KEY_INPUT_DOWN ) ) {
if ( VSize( camera.position ) < 2000.0f ) {
camera.position = VAdd( camera.position, VScale( VNorm( camera.position ), move_rate ) );
}
}
}
else {
if ( CheckHitKey( KEY_INPUT_UP ) ) {
matrixtemp = MGetRotAxis( VCross( camera.position, camera.head ), rot_rate );
camera.position = VTransform( camera.position, matrixtemp );
camera.head = VTransform( camera.head, matrixtemp );
}
if ( CheckHitKey( KEY_INPUT_DOWN ) ) {
matrixtemp = MGetRotAxis( VCross( camera.position, camera.head ), -rot_rate );
camera.position = VTransform( camera.position, matrixtemp );
camera.head = VTransform( camera.head, matrixtemp );
}
if ( CheckHitKey( KEY_INPUT_LEFT ) ) {
matrixtemp = MGetRotAxis( camera.head, rot_rate );
camera.position = VTransform( camera.position, matrixtemp );
camera.head = VTransform( camera.head, matrixtemp ); // いらない?
}
if ( CheckHitKey( KEY_INPUT_RIGHT ) ) {
matrixtemp = MGetRotAxis( camera.head, -rot_rate );
camera.position = VTransform( camera.position, matrixtemp );
camera.head = VTransform( camera.head, matrixtemp ); // いらない?
}
if ( CheckHitKey( KEY_INPUT_Z ) ) {
matrixtemp = MGetRotAxis( camera.position, -rot_rate );
camera.position = VTransform( camera.position, matrixtemp ); // いらない?
camera.head = VTransform( camera.head, matrixtemp );
}
if ( CheckHitKey( KEY_INPUT_X ) ) {
matrixtemp = MGetRotAxis( camera.position, rot_rate );
camera.position = VTransform( camera.position, matrixtemp ); // いらない?
camera.head = VTransform( camera.head, matrixtemp );
}
}
SetCameraPositionAndTargetAndUpVec( VAdd( camera.target, camera.position ), camera.target, camera.head );
DrawPixel3D( camera.target, white );
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( mh );
DrawFormatString( 0, 0, white, "position x=%f y=%f z=%f size=%f", camera.position.x, camera.position.y, camera.position.z, VSize( camera.position ) );
DrawFormatString( 0, 20, white, "target x=%f y=%f z=%f size=%f", camera.target.x, camera.target.y, camera.target.z, VSize( camera.target ) );
DrawFormatString( 0, 40, white, "head x=%f y=%f z=%f size=%f", camera.head.x, camera.head.y, camera.head.z, VSize( camera.head ) );
ScreenFlip( );
}
DxLib_End( );
return 0;
}