SimApi Convertor linearVec2zsVec

From SIMboxWiki
Jump to navigation Jump to search



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

    Description

    Converts linear vector to graphic engine vector.

    Parameters

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

    Return

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

    Remarks
    

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
	SimApi::Convertor::linearVec2zsVec(linVec,vec);
	
	//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<<endl;
	
	cout<<"Converted zsVec:"<<endl;
	cout<<"zsVec 0: "<<vec[0]<<endl;
	cout<<"zsVec 1: "<<vec[1]<<endl;
	cout<<"zsVec 2: "<<vec[2]<<endl;
	cout<<endl;
	
	//convert zsVec to LinearVec
	SimApi::Convertor::zsVec2LinearVec(vec,linVecC);
	
	//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;
	cout<<endl;
	
	return 0;
}

Output:
-------
  
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

     zsVec2LinearVec

     angularVec2zsVec

     zsVec2AngularVec

    Related Links

     SIMbox Coordinates Systems Overview

     LinearVec

     zsVec3