RE: Unexpected tilt to character
Ok i check your code to and you must make your own animation for character and overwrite it. I change a bit your code and made some animations. But to make it 100% corectly you have to change more and try add character in WE and play it. When i try use world make in WE i have error with skeleton so maybe you have to chenge char skeleton.
You have to change your code like here:
Quote:struct Player : Game::Chr // extend character class by defining a player class based on the character
{
void setAnim();
virtual Bool update(); // here we'll update the player (please note that this is a virtual method)
};
/******************************************************************************/
void Player::setAnim()
{
sac.stand=&cskel.getSkelAnim("obj/chr/test/stand.anim");
sac.run=&cskel.getSkelAnim("obj/chr/test/walk.anim");
}
And Init:
Quote:Bool Init()
{
Physics.create();
ground .create(Box(15,1,15,Vec(0,-2,0)),0);
// Matrix matrix; matrix.setScalePos(5.8,Vec(0,0,0));
Matrix matrix; matrix.setScalePos(5.8,Vec(0,0,0));
player.create(0.45, 1.8, matrix, *Meshs("obj/chr/test/man.mesh"), *Skeletons("obj/chr/test/man.skel")); // create player by radius, height, matrix, mesh and skeleton
player.setAnim();
return true;
}
Code with world create in WE:
Code:
/******************************************************************************/
#include "stdafx.h"
#include "../../../../../data/enum/_enums.h"
/******************************************************************************
Here we'll present how to properly use different camera modes
/******************************************************************************/
// Define viewing modes:
enum VIEW_MODE // Viewing Mode
{
VIEW_FPP, // First Person
VIEW_TPP, // Third Person
VIEW_ISO, // Isometric
VIEW_NUM, // number of view modes
};
UInt View; // current VIEW_MODE
/******************************************************************************/
struct Player : Game::Chr
{
Vec ctrl_pos;
void create(Game::ObjParams &obj);
virtual Bool update();
virtual void draw(); // extend drawing to disable head rendering in FPP mode
virtual void save(File &f);
virtual Bool load(File &f);
};
/******************************************************************************/
Game::ObjMemx<Game::Static> Statics; // container for static objects
Game::ObjMemx<Game::Item > Items ; // container for item objects
Game::ObjMemx< Player> Players; // container for player objects
/******************************************************************************/
void Player::create(Game::ObjParams &obj)
{
__super::create(obj); // call default creation
sac.walk=&cskel.getSkelAnim("obj/chr/test/walk.anim");
sac.stand=&cskel.getSkelAnim("obj/chr/test/stand.anim");
}
Bool Player::update()
{
if(action)
{
if(Kb.b(KB_W) || Kb.b(KB_S) || Kb.b(KB_A) || Kb.b(KB_D) || Kb.b(KB_Q) || Kb.b(KB_E))actionBreak();
}
if(!action)
{
// turn & move
input.anglei.x=Kb.b(KB_Q)-Kb.b(KB_E);
input.anglei.y=Kb.b(KB_T)-Kb.b(KB_G);
input.diri .x=Kb.b(KB_D)-Kb.b(KB_A);
input.diri .z=Kb.b(KB_W)-Kb.b(KB_S);
input.diri .y=Kb.b(KB_SPACE)-Kb.b(KB_LSHIFT);
// dodge, crouch, walk, jump
input.dodge = Kb.bd(KB_D)-Kb.bd(KB_A);
input.crouch= Kb.b (KB_LSHIFT);
input.walk = Kb.b (KB_LCTRL );
input.jump =(Kb.bp(KB_SPACE ) ? 3.5 : 0);
// mouse turn
if(View!=VIEW_ISO) // don't use mouse turning when in Isometric mode
{
Flt max=DegToRad(900)*Tm.d(),
dx =Ms.dir_ds.x*1.7,
dy =Ms.dir_ds.y*1.7*Ms.inv();
angle.x-=Mid(dx,-max,max);
angle.y+=Mid(dy,-max,max);
}
// ready stance change
ready^=Kb.bp(KB_R);
}
ctrl_pos=ctrl.actor.pos();
return __super::update();
}
void Player::draw()
{
Bool disable_head_draw=(View==VIEW_FPP && Renderer()!=RM_SHD_MAP && mesh); // disable drawing head when we're in FPP mode and we're not in shadowing mode (if this isn't included player will cast head-less shadows)
if(disable_head_draw)mesh->hide("head"); // hide "head" mesh part in 'mesh'
__super::draw(); // call default drawing
if(disable_head_draw)mesh->show("head"); // un-hide "head" mesh part, so other objects which use the same mesh will have the head rendered properly
}
void Player::save(File &f)
{
__super::save(f);
f<<ctrl_pos;
}
Bool Player::load(File &f)
{
if(__super::load(f))
{
f>>ctrl_pos;
return true;
}
return false;
}
/******************************************************************************/
void InitPre()
{
App.name("Camera Modes");
App.flag=APP_MS_EXCLUSIVE|APP_FULL_TOGGLE;
IOPath("../data");
Paks.add("engine.pak");
D.full(true).sync(true).ambPower(0.3).hpRt(true);
}
/******************************************************************************/
Bool Init()
{
Physics.create();
Sky .set ();
Sun &sun=Suns.New(); sun.set(*Images("gfx/sky/sun.gfx")).light_color=1-D.ambColor(); sun.rays.mode=SUN_RAYS_HIGH;
// create the world
Game::World.init()
.setObjType(Statics,OBJ_STATIC)
.setObjType(Players,OBJ_PLAYER)
.setObjItem(Items ,OBJ_ITEM )
.New("world/sample.world");
return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Update()
{
if(Kb.bp(KB_ESC))return false;
Game::World.update(Cam.at);
// set next camera mode when Tab pressed
if(Kb.bp(KB_TAB))
{
View=(View+1)%VIEW_NUM;
if(View==VIEW_ISO) // when set to isometric view
{
Cam.dist = 10; // set bigger camera distance at start
Cam.pitch=-PI_4; // set starting camera pitch angle
}
}
// setup the camera
if(Players.elms()) // if we have at least one player
{
// set camera depending on current view mode
switch(View)
{
case VIEW_FPP:
{
OrientP &head=Players[0].cskel.getPoint("head"); // obtain player "head" skeleton point (this was created in Mesh Editor)
Cam.setPosDir(head.pos,head.dir,head.perp); // set camera from 'head' position, direction and perpendicular to direction
}break;
case VIEW_TPP:
{
Cam.dist=Max(1.0f,Cam.dist*ScaleFactor(Ms.wheel()*-0.1)); // update camera distance according to mouse wheel
Cam.setSpherical(Players[0].ctrl_pos+Vec(0,0.5,0), Players[0].angle.x, Players[0].angle.y, 0, Cam.dist); // set spherical camera looking at player position with given player angles
}break;
default: // VIEW_ISO
{
Cam.yaw -=Ms.ds.x; // update camera yaw angle according to mouse smooth delta x
Cam.pitch+=Ms.ds.y; // update camera pitch angle according to mouse smooth delta y
Clamp(Cam.pitch,-PI_2,0); // clamp to possible camera pitch angle
Cam.dist =Max(1.0f,Cam.dist*ScaleFactor(Ms.wheel()*-0.1)); // update camera distance according to mouse wheel
Cam.setSpherical(Players[0].pos(), Cam.yaw, Cam.pitch, 0, Cam.dist); // set spherical camera looking at player using camera angles
}break;
}
// after setting camera position and angles:
Cam.updateVelocities().set(); // update camera velocities and activate it
}
else // when no player on the scene
{
CamHandle(0.1,100,CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT)); // default camera handling actions
}
return true;
}
/******************************************************************************/
void Render()
{
Game::World.draw();
}
void Draw()
{
Renderer(Render);
D.text (0,0.9,"Press Tab to switch camera modes");
}
/******************************************************************************/
And my animation but anim walk is make wrong you have to change, also obj file to add char to WE. Add this to chr in data->obj:
http://www.speedyshare.com/files/19468964/Test.rar
(This post was last modified: 11-25-2009 03:29 PM by Seba.)
|