I have this code. but I get this error:

chariot1.cpp
c:\orbitertest\orbitersdk\samples\shuttlepb\chariot1.cpp(235) : warning C4700: local variable 'speedvec' used without having been initialized

I was told that the oapiGetFocusShipAirspeedVector(speedvec) initialized the speedvec. Not sure how to fix this.

What I am doing . Is to determine which direction a vessel is going. in the z direction.

An ideas

VECTOR3 *speedvec; // first we declare our vector
oapiGetFocusShipAirspeedVector(speedvec);//then we retrieve its x,y,z

if (GroundContact()==true && GetAirspeed() >13 && (speedvec->z>0))
{AddForce(_V(0,0,-5e3),_V(0,0,0));}

if (GroundContact()==true && GetAirspeed() >13 && (speedvec->z<0))
{AddForce(_V(0,0,5e3),_V(0,0,0));}

Recommended Answers

All 8 Replies

>>I was told that the oapiGetFocusShipAirspeedVector(speedvec) initialized the speedvec
Depends on how that function is prototyped, is the pointer being passed by value or by reference ? oapiGetFocusShipAirspeedVector(VECTOR3*) or like this oapiGetFocusShipAirspeedVector(VECTOR3*&) The compiler error leads me to believe it is passed by value. But I've also stumbled across times when the compiler was wrong, so its best to just initialize the pointer to 0 anyway.

i don't know anything about oapiGetFocusShipAirspeedVector, but the code is incorrect unless the pointer is passed by reference and the library allocates memory for VECTOR3. (this is very unlikely).

// incorrect unless the function is declared as
// return_type oapiGetFocusShipAirspeedVector(VECTOR3*&) ;
VECTOR3 *speedvec; // first we declare our vector
oapiGetFocusShipAirspeedVector(speedvec);//then we retrieve its x,y,z

otherwise, it should be either (you allocate memory for VECTOR3)

VECTOR3 speedvec; // first we declare our vector
oapiGetFocusShipAirspeedVector(&speedvec);//then we retrieve its x,y,z

or (the library allocates memory)

VECTOR3 *speedvec; // first we declare our vector
oapiGetFocusShipAirspeedVector(&speedvec);//then we retrieve its x,y,z

check the documentation.

here is the doc:
oapiGetFocusShipAirspeedVector
Returns the current focus vessel’s airspeed vector w.r.t. closest planet or moon in the
vessel’s local frame of reference.
Synopsis:
BOOL oapiGetFocusShipAirspeedVector (VECTOR3 *speedvec)
Parameters:
speedvec pointer to variable receiving airspeed vector [m/s in x,y,z]
Return value:
Error flag (FALSE on failure)

If I have this:

oapiGetFocusShipAirspeedVector(VECTOR3* &)

I get

chariot1.cpp
chariot1.cpp(235) : error C2059: syntax error : ')'

> speedvec pointer to variable receiving airspeed vector
you need to allocate memory to receive the result. use

VECTOR3 speedvec; // first we define our vector which will recieve the data
oapiGetFocusShipAirspeedVector(&speedvec);//then we retrieve its x,y,z

ok, here is what code i have:

VECTOR3 speedvec; // first we define our vector which will recieve the data
oapiGetFocusShipAirspeedVector(&speedvec);//then we retrieve its x,y,z

if (GroundContact()==true && GetAirspeed() >13 && (speedvec->z>0))
{AddForce(_V(0,0,-5e3),_V(0,0,0));}

if (GroundContact()==true && GetAirspeed() >13 && (speedvec->z<0))
{AddForce(_V(0,0,5e3),_V(0,0,0));}

but now I get these errors:

chariot1.cpp
chariot1.cpp(237) : error C2819: type 'VECTOR3' does not have an overloaded member 'operator ->'
c:\Orbitertest\Orbitersdk\include\OrbiterAPI.h(107) : see declaration of 'VECTOR3'
did you intend to use '.' instead?
chariot1.cpp(237) : error C2227: left of '->z' must point to class/struct/union
type is 'VECTOR3'
did you intend to use '.' instead?
chariot1.cpp(240) : error C2819: type 'VECTOR3' does not have an overloaded member 'operator ->'
c:\Orbitertest\Orbitersdk\include\OrbiterAPI.h(107) : see declaration of 'VECTOR3'
did you intend to use '.' instead?
chariot1.cpp(240) : error C2227: left of '->z' must point to class/struct/union
type is 'VECTOR3'
did you intend to use '.' instead?
> Terminated with exit code 2.

VECTOR3 speedvec; // first we define our vector which will recieve the data
oapiGetFocusShipAirspeedVector(&speedvec);//then we retrieve its x,y,z

if (GroundContact()==true && GetAirspeed() >13 && (speedvec[B].[/B]z>0))
{AddForce(_V(0,0,-5e3),_V(0,0,0));}

if (GroundContact()==true && GetAirspeed() >13 && (speedvec[B].[/B]z<0))
{AddForce(_V(0,0,5e3),_V(0,0,0));}

or

VECTOR3 _speedvec; // first we define our vector which will recieve the data
VECTOR3* speedvec = & _speedvec ;
oapiGetFocusShipAirspeedVector(speedvec);//then we retrieve its x,y,z

if (GroundContact()==true && GetAirspeed() >13 && (speedvec->z>0))
{AddForce(_V(0,0,-5e3),_V(0,0,0));}

if (GroundContact()==true && GetAirspeed() >13 && (speedvec->z<0))
{AddForce(_V(0,0,5e3),_V(0,0,0));}

Thanks, that worked. What was I doing wrong?

> What was I doing wrong?

VECTOR3 *speedvec; // first we declare our vector
oapiGetFocusShipAirspeedVector(speedvec);//then we retrieve its x,y,z

you only have a pointer to a VECTOR3, and it is uninitialized (contains some undefined value, not the address of a VECTOR3 object. the function oapiGetFocusShipAirspeedVector assumes that you have passed it the correct address of a VECTOR3 object and tries to fill up the VECTOR3 with values. the error is the same as in

double* ptr ; // uninitialized pointer, there is no double which it points to
*ptr = 8.9 ; // this is going to cause a lot of unpleasantness
char* pch ; // only a pointer, there is no array
strcpy( pch, "hello world" ) ; // this compiles, though you would wish later that it hadn't
// strcpy will try to fill up an array of chars starting at address pch
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.