It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

By Miguel Gomez
Gamasutra
July 2, 1999

Letters to the Editor:
Write a letter
View all letters


Features

The COORDINATE_FRAME type

Contents

Introduction

The Vector type

The MATRIX type

The BASIS type

The COORDINATE FRAME type

The RIGID_BODY STATE type

Bibliography

Just as the (x,y,z) values of a vector depend on the basis you are using, the (x,y,z) values of a point in 3D space depend on which coordinate frame you are using. For instance, the (x,y,z) position you are sitting at could be specified with respect to your chair, the corner of the room, the center of the Earth, or the center of the Sun. And just like vectors, your (x,y,z) coordinates will vary depending on the orientation of the coordinate frame.

In Listing 4 all that was done to create the COORDINATE_FRAME type was to derive from BASIS and add a position member (known as the origin of the frame). Deriving from BASIS will preserve the ability to transform vectors to and from the local frame and rotate the frame. Specifying an origin allows us to transform points to and from the local frame, as well as translate and position the coordinate frame.

It’s important to remember that the basis and the origin are specified with respect to a parent frame. For example, if a tire’s parent is the car, the tire’s basis and position must be in car coordinates.

Listing 4.

// A coordinate frame (basis and origin) with respect to a parent

//

class COORD_FRAME : public BASIS

{

public:

POINT O; //this coordinate frame’s origin, relative to its parent frame

public:

COORD_FRAME()

{}

COORD_FRAME(

const POINT& o,

const VECTOR& v0,

const VECTOR& v1,

const VECTOR& v2

)

: O ( o ),

BASIS ( v0, v1, v2 )

{}

COORD_FRAME(

const POINT& o,

const BASIS& b

)

: O ( o ),

BASIS ( b )

{}

const POINT& position() const { return O; }

void position( const POINT& p ) { O = p; }

const POINT transformPointToLocal( const POINT& p ) const

{

//translate to this frame’s origin, then project onto this basis

return transformVectorToLocal( p - O );

}

const POINT transformPointToParent( const POINT& p ) const

{

//transform the coordinate vector and translate by this origin

return transformVectorToParent( p ) + O;

}

//translate the origin by the given vector

void translate( const VECTOR& v )

{

O += v;

}

};


The RIGID_BODY STATE type


join | contact us | advertise | write | my profile
news | features | companies | jobs | resumes | education | product guide | projects | store



Copyright © 2003 CMP Media LLC

privacy policy
| terms of service