About Store Forum Documentation Contact



Post Reply 
FPS Camera
Author Message
rogerg Offline
Member

Post: #1
FPS Camera
hi, I really like the engine so far, im slowly learning it.
I came across a problem. I looked at other threads on how to change the camera to a FPS (1st person view) camera and I am still a bit confused

I did:

Cam.setPosDir(player.cskel.getPoint("Head"));

and it gives me an error:

Error 1 error C2440: '<function-style-cast>' : cannot convert from 'Esenthel::OrientP' to 'Esenthel::Vec' c:\Documents and Settings\Roger\Desktop\EsenthelEngineSDK\Tutorials\Source\Advanced\4 - Demos, Game Basics\Game Basics\01 - Character.cpp 96 Tutorials

I know it needs a second parameter but I am trying to get this first one working, the parameter should be vec but the return type of setPosDir() seems to be OrientP. I hope I am not doing something very wrong. thanks for your help wink
12-16-2008 03:19 AM
Find all posts by this user Quote this message in a reply
craksy Offline
Member

Post: #2
Re: FPS Camera
i am not sure since i am pretty new, and confused by this thing but i think you need to put in a vector as a parameter..
maybe you could just make a new vec variable and update it like

V = player.cskel.getPoint("Head"));
Cam.setPosDir(V);
but maybe it will just give you the same error but with the variable... since your not actually changing the type.


as said: i dont know :S
just trying to help another user of this awsome engine grin
12-16-2008 04:28 AM
Find all posts by this user Quote this message in a reply
rogerg Offline
Member

Post: #3
Re: FPS Camera
hmm thanks for replying but that didnt seem to work, i even tried to force convert to a Vec and it still doesnt allow it.
12-16-2008 05:10 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
Re: FPS Camera
Hi,

getPoint gives you a OrientP which is a positioned orientation, it has positon+direction+perpendicular to direction vectors


OrientP &head=skel.getPoint("head");

now Cam.setPosDir requires position and direction

so you should call

Cam.setPosDir(head.pos, head.dir);

optionally you can call Cam.setPosDir(head.pos, head.dir, head.perp); to provide also perpendicular vector (which will provide head bobbing effect)

This is more or less described in tutorial "animation/skeleton points" where an item is attached to a hand
12-16-2008 12:59 PM
Find all posts by this user Quote this message in a reply
rogerg Offline
Member

Post: #5
Re: FPS Camera
Hello, thanks for your reply. I understand it a bit better now, but it still doesnt work. when I typed what you said it just switched to a default still camera.

what I have right now is:

Bool Init()
{
Text_ds.scale*=0.8;

Physics.create();

// create the world
Game::World.init()
.setType(Statics,OBJ_STATIC)
.setType(Players,OBJ_CHR ) // please note that here we'll use 'Players' memory container for 'OBJ_CHR' objects
.setItem(Items ,OBJ_ITEM ) // please note that here is called 'setItem' instead of 'setType', this is used for enabling built-in character<->item relations such as picking up and dropping items
.New("world/sample" );

OrientP &head=Players[0].cskel.getPoint("Head"); // some sort of array for storing player objects right?, i assume 0 is the player walking around because there are no other players.

//Cam.setSpherical(Vec(16,0,16),-PI_4,-0.5,0,10).set(); // set initial camera. commented out because im trying my own camera, I think this is right, not sure
Cam.setPosDir(head.pos, head.dir, head.perp).set(); //i added .set() i think this makes it as the active camera

return true;
}

this compiles without a problem, but it crashes when I launch the game. this is from World with Character tutorial.
I hope you can help me.
12-17-2008 08:51 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
Re: FPS Camera
setting the camera should be done each frame, not at the game initialization stage

move

"OrientP &head=Players[0].cskel.getPoint("Head"); // some sort of array for storing player objects right?, i assume 0 is the player walking around because there are no other players.

//Cam.setSpherical(Vec(16,0,16),-PI_4,-0.5,0,10).set(); // set initial camera. commented out because im trying my own camera, I think this is right, not sure
Cam.setPosDir(head.pos, head.dir, head.perp).set(); //i added .set() i think this makes it as the active camera"

this into the "Main" function

and always when you want to access Players[0] you need to check first if there is actually 0-th element
if(Players.elms()>1)
{
OrientP &head=Players[0].cskel.getPoint("Head"); // some sort of array for storing player objects right?, i assume 0 is the player walking around because there are no other players.

//Cam.setSpherical(Vec(16,0,16),-PI_4,-0.5,0,10).set(); // set initial camera. commented out because im trying my own camera, I think this is right, not sure
Cam.setPosDir(head.pos, head.dir, head.perp).set(); //i added .set() i think this makes it as the active camera
}

the crash is caused by accesssing a non existing object (at initialization Players has 0 elements)
12-17-2008 10:11 AM
Find all posts by this user Quote this message in a reply
rogerg Offline
Member

Post: #7
Re: FPS Camera
thanks a lot for reply, I did what you said and I seem to be getting closer to what I want to achieve but I seem to be having another issue.
If I remove the new if statement i created in the main function the program crashes, and if I keep it in it doesn't crash but it still doesn't change the camera so I think
the problem now is that there isnt a 0-th element in the Players[] array. I don't think the demo even creates a player, I am trying hard to understand how you can still control the character
even though it never creates any instances of the player like Player player. or player.create(). maybe you can look at the World with Character demo?
I am learning a lot from studying this engine, I hope to write my own someday smile
thanks very much.

update:

if(Players.elms()>0)
{
OrientP &head1=Players[0].cskel.getPoint("Head");
Cam.setPosDir(head1.pos, head1.dir, head1.perp).set();
}

I added 1 after head and for some strange reason it worked. however I can still see the outline of the nose where the camera is looking from.
12-17-2008 10:41 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #8
Re: FPS Camera
so it is working yes?
well head1 or head shouldnt make a difference

you're seeing the outline because the head is still rendered,
what you want to do is disable head rendering when in FPP mode, you can override Chr::draw method

and before calling the default draw, hide the "head" part of the mesh

something like this:

void Chr::draw()
{
if(View==VIEW_FPP && Renderer()!=RM_SHD_MAP && mesh)mesh->hide("head"); // hide
__super::draw();
if(View==VIEW_FPP && Renderer()!=RM_SHD_MAP && mesh)mesh->show("head"); // unhide
}

guess I'll write a tutorial about FPP camera
12-17-2008 12:59 PM
Find all posts by this user Quote this message in a reply
rogerg Offline
Member

Post: #9
Re: FPS Camera
yes! it works now, thanks so much for your help. I can finaly begin working on the level
12-17-2008 02:04 PM
Find all posts by this user Quote this message in a reply
Post Reply