//---------------------------------------------------------------------------------------------- ChsVector3 screenToVector( float scrX, float scrY )const{ // Scale to screen float x = (scrX - this->halfScreenWidth ) / (this->radius * this->halfScreenWidth ); float y = -(scrY -this->halfScreenHeight ) / (this->radius * this->halfScreenHeight ); float z = 0.0f; float mag = x * x + y * y; if( mag > 1.0f ) { float scale = 1.0f/sqrtf(mag); x *= scale; y *= scale; } else{ z = sqrtf( 1.0f - mag ); } // Return vector return ChsVector3( x, y, z ); }
//---------------------------------------------------------------------------------------------- ChsVector3 ChsVector3::operator / ( float scale )const{ assert( scale != 0 ); return ChsVector3( this->x / scale, this->y / scale, this->z / scale ); }
//---------------------------------------------------------------------------------------------- ChsVector3 ChsVector3::operator - ( void )const{ return ChsVector3( -this->x, -this->y, -this->z ); }
//---------------------------------------------------------------------------------------------- ChsVector3 ChsVector3::operator * ( float scale )const{ return ChsVector3( this->x * scale, this->y * scale, this->z * scale ); }
//---------------------------------------------------------------------------------------------- ChsVector3 ChsVector3::cross( const ChsVector3 & vec1, const ChsVector3 & vec2 ){ return ChsVector3( vec1.y * vec2.z - vec2.y * vec1.z, vec1.z * vec2.x - vec2.z * vec1.x, vec1.x * vec2.y - vec2.x * vec1.y ); }