About Store Forum Documentation Contact



Post Reply 
character input?
Author Message
craksy Offline
Member

Post: #1
character input?
ok i was playing around with the character tutorial, and started wondering of some stuff:

1. even though you dont set a skeleton for the mesh, it animates fine, and in the character.h it says default=NULL... how can it animate without skeleton? :S
2. this line: input.diri .z=Kb.b(KB_W)-Kb.b(KB_S); makes the character walk towards the direction he's facing... i thaught it would require both x, and z values to calculate that, but its set to just diri.z?
i mean in 2D it requires both x, and y values to calculate, like in this example (example from flash actionscript):
Code:
x += Math.sin (_rotation * Math.PI / 180) * speed;
y += Math.cos (_rotation * Math.PI / 180) * -speed;
//using sine, and cosine, to calulate, which way object it facing
3. does this input fuction only work with standart animations? since it doesnt ask for any animation folder path?
4. i have never seen such thing as a virtual function... what difference does it do excactly? (i know this is more, general C++, knowlege than engine reletated... which i also think you should have a forum for?)

this time i really tried to look through the tutorials, and header files, before asking, but i couldnt really find aswers to all my question (i had a lot more question before i took a look at character.h -.-')
hope you can help me!
in advance: Thanks
12-19-2008 01:45 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
Re: character input?
1. "virtual void create(ObjParams &obj ); // create from object parameters, if no animation skeleton is given, it will be loaded from mesh file name (but with extension changed to ".skel")"

2. yes thats right,
but all the calculations are handled by the Chr class according to player looking angles, you just specify if you want to move forward or backwards

3. by default it uses the default animations, you can replace them (check tutorial "character default animations") or modify by custom animations (check tutorial "character animations")

4. I'll put it into documentation "programming" section


thanks
12-19-2008 01:57 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #3
Re: character input?
just a quick question(didnt want to make another thread for a single question):

what excactly are the difference between the render, and the draw function? :/
12-19-2008 03:26 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #4
Re: character input?
I've added virtual functions topic to the documentation (will be in the next SDK)

Draw function is required by the Engine, it handles main drawing, inside it should be called Rendering (3d graphics), and after that drawing simple 2d graphics.

In other words Render should handle only 3d graphics

while Draw should call Render and after it perform optional 2d graphics
12-19-2008 03:29 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #5
Re: character input?
Quote:I've added virtual functions topic to the documentation (will be in the next SDK)
cool grin
Quote:In other words Render should handle only 3d graphics

while Draw should call Render and after it perform optional 2d graphics

so its not an actual need, but more for organizing the code?
12-19-2008 03:41 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #6
Re: character input?
Actually separating Render from Draw is needed because Render will be called internally several times, while Draw will be only called once per frame draw

BTW: I've updated the tutorial "matrix" to provide some more info about them
12-19-2008 03:57 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #7
Re: character input?
ok
cool! ill check it out right away grin
12-19-2008 04:14 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #8
Re: character input?
i have been playing a little bit around, with the character thingy, and i got a few problems...
first heres my code so far:
Code:
/******************************************************************************/
#include "stdafx.h"
#include "../data/enum/_enums.h"
/******************************************************************************/
struct Player:Game::Chr
{
   virtual Bool update();
};
/******************************************************************************/
Game::ObjMemx<Player> Players;
/******************************************************************************/
Bool Player::update(){
    input.anglei.x=Kb.b(KB_A)-Kb.b(KB_D);
    input.diri.z=Kb.b(KB_W);
    input.diri.y=Kb.b(KB_SPACE);
return __super::update();
}
/******************************************************************************/
Actor ground;
Player player;
/******************************************************************************/
void InitPre()
{
   App.name="Test project";
   App.flag=APP_FULL_TOGGLE | APP_MS_EXCLUSIVE;
   PakAdd("data/engine.pak");
   IOPath="../data/";
  
   Cam.dist=5;
}
/******************************************************************************/
Bool Init()
{
   Physics.create();
   Game::World.init().setType(Players,OBJ_CHR).New("world/sample");
   player.create(Vec(0, 1, 0), 1.7, "../data/obj/chr/skeleton/0.mesh");
   return true;
  
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Main()
{
  if(Kb.bp(KB_ESC))return false;
  Physics.sim().get();
  player.update();
  Game::World.update(Cam.at);

  if(Ms.b(1)){
    Cam.yaw -= Ms.d.x;
    Cam.pitch +=Ms.d.y;
    
  }
  Cam.at = player.ctrl.actor.pos()+Vec(0,1,0);
  Cam.dist -=Ms.wheel*0.2;
  Cam.dist = 5;
  Cam.setSpherical(Cam.at, Cam.yaw, Cam.pitch, 0, Cam.dist);
  Cam.updateVelocities();
  Cam.set();

   return true;
}
/******************************************************************************/
void Render()
{
    Game::World.draw();

   switch(Renderer())
   {
      case RM_LIGHT:
         LightDir(1,!Vec(1,-1,1)).add();
      break;
   }
   player.draw();
   ground.draw();
}

void Draw()
{
    D.clear();
    Renderer(Render);
    
}
/******************************************************************************/

and heres the problems i ran into:

1. for some reason there is also a controlable human mesh, which appears at the center of the ground (skeleton spawns on one of the corners)
some of the code, is copied from tutorials, and some of it i wrote myself, but i dont see anything that should create, or draw the human :S
2. when i walk around with my char, its like he is shaking... not much, but its kinda anoying :/
3. the line Cam.at = player.ctrl.actor.pos()+Vec(0,1,0); i had to copy from a tutorial... first of i tried stuff like Cam.at = player.pos(); and such, but it didnt work... what excactly does the .ctrl.actor thingy change?
4. i didnt really understand this:
Code:
case RM_LIGHT:
         LightDir(1,!Vec(1,-1,1)).add();
break;
first of i tried to play around with some different light settings, but i couldnt make it light up the whole scene, so i decided to copy it from the "character and world" tutorial... but i kinda bugs me that i dont know what it actually does :oops:

hope you can help me out smile

thanks in advance smile
12-20-2008 04:52 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #9
Re: character input?
1.
If you're using Game::World you shouldn't create the character manually via ' player.create(Vec(0, 1, 0), 1.7, "../data/obj/chr/skeleton/0.mesh");'
but place a character object in the World Editor, in that way it will be automatically created in World.New("world/sample");, updated in World.update, and drawn in World.draw

2.
Physics.sim().get();
player.update();
Game::World.update(Cam.at);

World.update automatically updates the physics so in you're codes you're updating physics twice which may cause stuttering (unsmoothnes)

3. I believe Chr.pos() should work ok, when you first remove the manual 'player' and let it be handled by world

4. LightDir(1,!Vec(1,-1,1)).add();
this adds a directional light at normalized direction (1,-1,1) (! means normalization - setting vector length to 1, because every direction vector needs to be set normalized)
12-20-2008 08:16 PM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #10
Re: character input?
Quote:If you're using Game::World you shouldn't create the character manually via ' player.create(Vec(0, 1, 0), 1.7, "../data/obj/chr/skeleton/0.mesh");'
but place a character object in the World Editor, in that way it will be automatically created in World.New("world/sample");, updated in World.update, and drawn in World.draw

i thaught that, it could be the problem, but i wasnt sure, since i didnt work much with the world editor (didnt know that characters could be added to the world file)
but now i just have a problem with the cam...
as far as i understanded the 'Game::Chr' should work exactly like the 'Player' but it doesnt seem to work like before :/
i still have the 'Player' extention of the Chr struct but i supposed that it was needed since the 'Player::update' function also controled the character from the world file?
anyway, it seems to be ignoring the line Cam.at = Game::Chr().pos(); completely... i also tried stuff like Cam.at = Game::Chr().ctrl.actor.pos(); but nothing seems to work :S

did i misunderstand something?

EDIT:
i just noticed that i use extremely many unnecessary commas, but has become a sorta habbit to me :/
i hope its readable anyway?
12-20-2008 11:48 PM
Find all posts by this user Quote this message in a reply
Grabonito Offline
Member

Post: #11
Re: character input?
My patent :

Code:
Cam.setSpherical(player.ctrl.actor.pos()+Vec(0,4,-5)-1,0,player.angle.y-0.33,0,Cam.dist*ScaleMul(Ms.wheel*1)).updateVelocities().set();
12-21-2008 12:14 AM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #12
Re: character input?
it looks like the cam settings for the character tutorial, but thats not what i need...
i need a cam which updates its position acording to Cam.at, using the Game::chr since i removed the 'Player' from the code.
12-21-2008 12:37 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #13
Re: character input?
how does your code look like now?
12-21-2008 10:19 AM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #14
Re: character input?
Code:
/******************************************************************************/
#include "stdafx.h"
#include "../data/enum/_enums.h"
/******************************************************************************/
struct Player:Game::Chr
{
   virtual Bool update();
};
/******************************************************************************/
Game::ObjMemx<Player> Players;
/******************************************************************************/
Bool Player::update(){
    input.anglei.x=Kb.b(KB_A)-Kb.b(KB_D);
    input.diri.z=Kb.b(KB_W);
    
return __super::update();
}
/******************************************************************************/
void InitPre()
{
   App.name="Test project";
   App.flag=APP_FULL_TOGGLE | APP_MS_EXCLUSIVE;
   PakAdd("data/engine.pak");
   IOPath="../data/";
}
/******************************************************************************/
Bool Init()
{
   Physics.create();
   Game::World.init().setType(Players,OBJ_CHR).New("world/sample");
   return true;
  
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Main()
{
  if(Kb.bp(KB_ESC))return false;
  Game::World.update(Cam.at);

  if(Ms.b(1)){
    Cam.yaw -= Ms.d.x;
    Cam.pitch +=Ms.d.y;
    
  }
  Cam.at = Game::Chr().pos();
  Cam.dist -=Ms.wheel*0.2;
  Cam.dist = 5;
  Cam.setSpherical(Cam.at, Cam.yaw, Cam.pitch, 0, Cam.dist);
  Cam.updateVelocities();
  Cam.set();

   return true;
}
/******************************************************************************/
void Render()
{
    Game::World.draw();

   switch(Renderer())
   {
      case RM_LIGHT:
         LightDir(1,!Vec(1,-1,1)).add();
      break;
   }
}

void Draw()
{
    D.clear();
    Renderer(Render);
    
}
/******************************************************************************/
12-21-2008 01:21 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #15
Re: character input?
you shouldn't use

Cam.at=Game::Chr().pos();

but use

if(Players.elms())
{
Cam.at=Players[0].pos(); // which refers to position of 0-th character
}

and for this code:
D.clear();
Renderer(Render);

when using Renderer - D.clear isn't required so keep only

Renderer(Render);
12-21-2008 02:10 PM
Find all posts by this user Quote this message in a reply
Post Reply