SimApi Convertor linearVec2zsVec

From SIMboxWiki
Jump to navigation Jump to search

Icon attributes.pngstatic void SimApi::Convertor::linearVec2zsVec(const LinearVec &linVec, zsVec3 &zsVec)


    Converts linear vector to graphic engine vector.


    linVec - In parameter, linear vector (of type LinearVec)
    zsVec - Out parameter, the graphic engine vector (of type zsVec3)


    Type: void   Description: The graphic engine vector is returned in the zsVec parameter


The 3D engine and the simulation engine represent position vectors differently. When using 3D engine API, you must convert from the LinearVec type that is used by simulation engine to zsVec3 type that is used by 3D engine, and then convert the results in conversely. See "SIMBox Coordinates Systems" for more information.

    Code Sample

      int main(int argc, char* argv[])
	zsVec3 vec;
	LinearVec linVec, linVecC;
	double lat = 0.6283;	// == 36 degrees 
	double lon =  -2.0071;	// == -115 degrees
	float x = 0.0, y = 0.0, z = 0.0;
	//convert global coordinates to local coordinates 
	SimApi::Convertor::globalToLocal(lon, lat, x, y);
	//get the height
	z = SimApi::Convertor::getTerrainHeightGlobal(lon,lat);
	linVec[X] = x;
	linVec[Y] = y;
	linVec[Z] = z;
	//convert to zsVec3
	//print results
	cout<<"LinearVec before conversion:"<<endl;
	cout<<"LinearVec X: "<<linVec(X)<<endl;
	cout<<"LinearVec Y: "<<linVec(Y)<<endl;
	cout<<"LinearVec Z: "<<linVec(Z)<<endl;
	cout<<"Converted zsVec:"<<endl;
	cout<<"zsVec 0: "<<vec[0]<<endl;
	cout<<"zsVec 1: "<<vec[1]<<endl;
	cout<<"zsVec 2: "<<vec[2]<<endl;
	//convert zsVec to LinearVec
	//print results
	cout<<"LinearVec after conversion from zsVec3:"<<endl;
	cout<<"LinearVec X: "<<linVecC(X)<<endl;
	cout<<"LinearVec Y: "<<linVecC(Y)<<endl;
	cout<<"LinearVec Z: "<<linVecC(Z)<<endl;
	return 0;

LinearVec before conversion:
LinearVec X: -7252.3706
LinearVec Y: 2415.3342
LinearVec Z: 794.48346

Converted zsVec:
zsVec 0: -7252.3706
zsVec 1: 2415.3342
zsVec 2: 794.48346

LinearVec after conversion from zsVec3:
LinearVec X: -7252.3706
LinearVec y: 2415.3342
LinearVec Z: 794.48346

    See Also




    Related Links

     SIMbox Coordinates Systems Overview