1 registered members (TipmyPip),
18,449
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Can tell me what is wrong with this c_move?
#251618
02/14/09 06:07
02/14/09 06:07
|
Joined: Jan 2009
Posts: 38
Anonymous2009
OP
Newbie
|
OP
Newbie
Joined: Jan 2009
Posts: 38
|
This is a portion of codes made of C++ using Lite-C engine. What is supposed to happen is a camera attached to an entity, and WASD move the entity, thus the camera. No problem in compiling, but "Empty pointer in a function" is shown when run. #define MOUSE_SENSITIVITY 10.0 // set mouse sensitivity
#define CAMERA_SPEED 10.0 // set camera speed
ENTITY* soldier;
void FPS_camera(ENTITY* soldier)
{
VECTOR vMove = {_VAR(0), _VAR(0), _VAR(0)};
VECTOR vForce = {_VAR(0), _VAR(0), _VAR(0)}; // temp variables for moving and rotating the camera
// update camera rotation variables based on mouse input, and multiply by mouse sensitivity
vForce.x = _VAR(-1 * MOUSE_SENSITIVITY * _FLOAT(v(mouse_force).x) * FLOATV(time_frame)); // set pan angle variable
vForce.y = _VAR(MOUSE_SENSITIVITY * _FLOAT(v(mouse_force).y) * FLOATV(time_frame)); // set tilt angle variable
// update camera position variables based on keyboard input W, A, S, D, home, end keys
vMove.x = _VAR(CAMERA_SPEED * (FLOATV(key_w) - FLOATV(key_s)) * FLOATV(time_frame)); // set forward variable
vMove.y = _VAR(CAMERA_SPEED * (FLOATV(key_a) - FLOATV(key_d)) * FLOATV(time_frame)); // set sideways variable
vMove.z = _VAR(CAMERA_SPEED * (FLOATV(key_home) - FLOATV(key_end)) * FLOATV(time_frame)); // set upward variable
// update the camera's rotation and position
vec_add((VECTOR*)&v(camera).pan, &vForce); // rotate camera based on vForce variable
vec_rotate(&vMove, (ANGLE*)&v(camera).pan); // rotate vMove variable in direction of camera
c_move(soldier, (VECTOR*)&vMove, NULL, GLIDE); // entity, relative dist, global dist, mode
v(camera).x = soldier->x;
v(camera).y = soldier->y;
v(camera).z = _VAR(70);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
engine_init();
v(camera).pan = _VAR(90);
vec_set((VECTOR*)&v(camera).x, _vec(0, 0, 70));
v(camera).arc = _VAR(NORMAL_FOV);
soldier = ent_create("soldier.mdl", _vec(0, 0, 70), NULL);
phent_settype(soldier,_VAR(PH_RIGID),_VAR(PH_BOX));
phent_setmass(soldier,_VAR(1.0),_VAR(PH_BOX));
phent_setfriction(soldier,_VAR(90.0));
phent_setelasticity(soldier,_VAR(0.0),_VAR(100.0));
phent_setdamping(soldier,_VAR(30.0),_VAR(30.0));
... BLAH BLAH BLAH ...
while(engine_frame())
{
FPS_camera(soldier);
}
engine_close();
return 0;
}
Last edited by Anonymous2009; 02/16/09 03:29.
|
|
|
Re: Can tell me what is wrong with this c_move?
[Re: Anonymous2009]
#251672
02/14/09 15:06
02/14/09 15:06
|
Joined: Jan 2009
Posts: 38
Anonymous2009
OP
Newbie
|
OP
Newbie
Joined: Jan 2009
Posts: 38
|
Figured the problem is the third argument in the c_move, both NULL and (0,0,0) give me the same problem. And if I put a dummy non-zero value (eg. (1,1,1)), there will be no error, but I can't move. Any suggestion?
Last edited by Anonymous2009; 02/15/09 03:26.
|
|
|
Re: Can tell me what is wrong with this c_move?
[Re: Anonymous2009]
#251689
02/14/09 16:18
02/14/09 16:18
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I dunno anything about the C++ implementation, but I'll give my opinion on the lite-c portion.
The third argument should be NULLVECTOR [vector(0,0,0)] in the way your using it. Just make sure that vMove is getting some data in it. If it is, try making the c_move be "IGNORE_ME|IGNORE_YOU|GLIDE" and see if it gets you moving, you feet may be 'stuck' in the ground.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Can tell me what is wrong with this c_move?
[Re: Anonymous2009]
#251828
02/15/09 09:32
02/15/09 09:32
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Then use vector(0,0,0) then, its the same thing.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Can tell me what is wrong with this c_move?
[Re: Anonymous2009]
#251926
02/15/09 16:36
02/15/09 16:36
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I was looking at the problem all wrong anyway. Im not going to be able to help much cause its the C++ side that has the problem. You are getting a null pointer error because the SOLDIER entity is never getting filled by an entity, you'll need another function to perform an ent_create() to create the entity and assign it to the soldier pointer, BEFORE calling the FPS_camera function. I would also suggest the changing the end of FPR_camera to the following, otherwise you'll get a crash if the soldier pointer is empty for too long. if(soldier)
{
c_move(soldier, (VECTOR*)&vMove, NULL, GLIDE); // entity, relative dist, global dist, mode
v(camera).x = soldier->x;
v(camera).y = soldier->y;
v(camera).z = _VAR(70);
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|