Jump to content

Rotate the camera around the object


Kotov72rus
 Share

Recommended Posts

Hello.

Show you how to rotate the camera around the object?

 

Tried to fix this code:

//Camera looking
Player.mx=Curve(MouseX()-GraphicsWidth()/2,Player.mx,6);
Player.my=Curve(MouseY()-GraphicsHeight()/2,Player.my,6);
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);			
Player.camrotation.X=Player.camrotation.X+Player.my/10.0;
Player.camrotation.Y=Player.camrotation.Y-Player.mx/10.0;
RotateEntity(Camera,Player.camrotation);

 

but nothing sad.png

Link to comment
Share on other sites

you need a pivot.

 

create the pivot with CreatePivot(character)

parent the pivot to the character

parent the camera to the pivot

 

it looks like you have everything else right, just need a pivot.

 

I assume this is a third person cam, so make sure the camera position is far from the character it's self.

Link to comment
Share on other sites

Works biggrin.png

 

#pragma once
#include "engine.h"
#include "string"
using namespace std;

const int COLLISION_NONE = 0;
const int COLLISION_PROP = 1;
const int COLLISION_SCENE = 2;
const int COLLISION_CHARACTER = 3;
const int COLLISION_TRIGGER = 4;
const int COLLISION_AILINEOFSIGHT = 5;

class TPlayer
{
private:
public:
flt X,Y,Z;
TCamera Camera;
TMesh mesh;
TEntity CameraPivot;
float mx;
float my;
TVec3 camrotation;
TController Controller;
TMesh PlayerMesh;
float move;
float strafe;
float Angle;
void CreatePlayer(flt X, flt Y, flt Z);
void Update();
};

TPlayer Player; //Global class

void TPlayer::CreatePlayer(flt X, flt Y, flt Z)
{
Player.X = X;
Player.Y = Y;
Player.Z = Z;

//Create player
Controller = CreateController(2,0.3,0.5,45.01);
EntityType(Controller,COLLISION_CHARACTER);
PositionEntity(Controller,Vec3(X,Y,Z));
SetBodyDamping(Controller,0.0);
SetWorldGravity(Vec3(0,-10,0));
SetBodyMass(Controller,50);

//Set look camera position
PositionEntity(Camera,Vec3(0,1,-4));

//Camera pivot
CameraPivot=CreatePivot();
EntityParent(Camera, CameraPivot);

//Load player mesh
PlayerMesh = LoadMesh("abstract::crawler.gmf");
EntityType(PlayerMesh,COLLISION_CHARACTER);
RotateEntity(PlayerMesh,Vec3(0,-180,0));

HideMouse();
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

Angle = -180;
}

void TPlayer::Update()
{
//Camera look
mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);
my=Curve(MouseY()-GraphicsHeight()/2,my,6);
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
camrotation.Y=camrotation.Y-mx/9.0;
camrotation.X=camrotation.X+my/9.0;

//Limit the viewing angle in the vertical
camrotation.X=min(camrotation.X,60); //Look Up
camrotation.X=max(camrotation.X,-10); //Look Down

//Rotate Camera
RotateEntity(CameraPivot,camrotation);
//Position Camera
PositionEntity(CameraPivot,EntityPosition(Controller));

//Player movement
move=(KeyDown(KEY_W)-KeyDown(KEY_S))*4;
strafe=(KeyDown(KEY_D)-KeyDown(KEY_A))*4;
//Set controller input
UpdateController(Controller,camrotation.Y,move,strafe,0,45);

//Player mesh position and rotation
PositionEntity(PlayerMesh,EntityPosition(Controller));
RotateEntity(PlayerMesh,Vec3(0,camrotation.Y+Angle,0));
}

 

Add to main:

#include "Player.h"
Player.Camera = GetLayerCamera(GetFrameworkLayer(0));
Player.CreatePlayer(0,9,0);

 

Add to main loop:

Player.Update();

 

http://youtu.be/YCm9-y1E7kI

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...