Hello guys.
I'm just tried to make 3rd person view.
and, i did it.
But there is a serious flaw.
It is the collisions of camera.;; I just want to make camera which have collisions.
Can you help me please? ㅠㅠ
Here is a picture and my code.
#include "engine.h"
int main(int argc, char** argv)
{
Initialize(1);
//Create a graphics context
Graphics(800,600);
SetAppTitle("Project A");
RegisterAbstractPath("C:\Program Files\Leadwerks Engine SDK");
//Create a world
if (!CreateWorld()) {
MessageBoxA(0,"Error","Failed to create world.",0);
goto exitapp;
}
CreateFramework();
//옵션
SetBloom(1);
SetHDR(1);
SetSSAO(1);
SetGodRays(1);
AFilter() ;
TFilter() ;
float move=0.0;
float strafe=0.0;
TVec3 camrotation=Vec3(0);
TVec3 playerrotation=Vec3(0);
float mx=0;
float my=0;
int sequence=3; //애니메이션 단계
float framebegin,frameend,frame; //애니메이션 시작,끝 프레임
//맵 로드
TEntity map = LoadScene("abstract::test.sbx");
//플레이어 생성, 충돌, 무게등등
TController player=CreateController(1.8,0.3,0.5,45.45);
PositionEntity(player,Vec3(-5,4,22));
EntityType(player,1);
SetBodyDamping(player,0.0);
SetWorldGravity(Vec3(0,-20,0));
SetBodyMass(player,1);
//중심 생성
TPivot pivot = CreatePivot(player);
//카메라 생성
TEntity cam= CreateCamera(pivot);
EntityType(cam,1,true);
CameraClearColor(cam,Vec4(255,255,255,255));
PositionEntity(cam,Vec3(0,2,-3));
//모델 로드,회전
TMesh test = LoadMesh("abstract::crawler.gmf");
RotateEntity(test,Vec3(0,180,0));
//마우스 위치
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
DebugPhysics(0);
//Main loop
while(!KeyHit(KEY_ESCAPE))
{
//백터 값들.
TVec3 testrotation = EntityRotation(test);
TVec3 playerpos=EntityPosition(player);
playerrotation=EntityRotation(player);
//카메라 시선
mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);
my=Curve(MouseY()-GraphicsHeight()/2,my,6);
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
camrotation.X=camrotation.X+my/10.0;
camrotation.Y=camrotation.Y-mx/10.0;
//플레이어 움직임
move=(KeyDown(KEY_W)-KeyDown(KEY_S))*4.5;
strafe=(KeyDown(KEY_D)-KeyDown(KEY_A))*4.5;
//점프
float jump=0.0;
if (KeyHit(KEY_SPACE)) {
if (!ControllerAirborne(player)) {
jump=6.0;
}
}
//카메라 x축 제한
if(camrotation.X>23)
camrotation.X=23;
else if(camrotation.X<-32)
camrotation.X=-32;
//컨트롤러 업데이트
UpdateController(player,camrotation.Y,move,strafe,jump,40);
//모델 위치,회전
PositionEntity(test,Vec3(playerpos.X,playerpos.Y,playerpos.Z));
RotateEntity(test,Vec3(testrotation.X,testrotation.Y,testrotation.Z));
//모델 애니메이션
if(KeyDown(KEY_W) || KeyDown(KEY_D) || KeyDown(KEY_A) || KeyDown(KEY_S) || KeyDown(KEY_SPACE) || ControllerAirborne(player))
{
RotateEntity(test,Vec3(playerrotation.X,camrotation.Y+180,playerrotation.Z));
}
if(KeyDown(KEY_W)||KeyDown(KEY_S)||KeyDown(KEY_A)||KeyDown(KEY_D))
{
sequence=1;
}
else
{
sequence=3;
}
switch(sequence)
{
case 1:
framebegin=131,frameend=171;
break;
case 2:
framebegin=70,frameend=130;
break;
case 3:
framebegin=0,frameend=68;
break;
}
frame=AppTime()/29.0;
frame=fmodf(frame,frameend-framebegin)+framebegin;
Animate(test,frame,1.0,0,true);
//와이어프레임
if(KeyDown(KEY_Q))
{
DebugPhysics(1);
}
UpdateFramework();
RotateEntity(pivot,camrotation,1);
RenderFramework();
SetBlend(BLEND_ALPHA);
SetBlend(BLEND_NONE);
Flip(0);
}
exitapp:
return Terminate();
}