Vega programming materials

Source: Internet
Author: User
A motion body provides a means to control the orientation of dynamic entities in a scene. The Vega class related to the motion body includes entity, motion pattern, body, and collision detection. A motion body can only be associated with one motion pattern or body, but can be associated with multiple objects and collision detection at the same time.
Related attributes:
Vgcommon_enabled
Vgplyr_type
Vgplyr_classnum
Vgplyr_team
Vgplyr_csref
Vgplyr_motion
Vgplyr_spline_navigator
Related functions:
Vgplayer * vgnewplyr (void );
Vgplayer * vgnewplyrcopy (const vgplayer * SRC );
Vgplayer * vgfindplyr (const char * Name );
Vgplayer * vggetplyr (INT _ index );
Int vggetnumplyr (void );
Void vgplyrvol (vgplayer * plyr, vgvolume * vol );
Vgvolume * vggetplyrvol (vgplayer * plyr );
Void vgaddplyrisect (vgplayer * plyr, vgisector * isect );
Void vgremplyrisect (vgplayer * plyr, vgisector * isect );
Int vggetplyrnumisect (vgplayer * plyr );
Vgisector * vggetplyrisect (vgplayer * plyr, int idx );
Void vgaddplyrobj (vgplayer * plyr, vgobject * OBJ );
Void vgremplyrobj (vgplayer * plyr, vgobject * OBJ );
Int vggetplyrnumobj (vgplayer * plyr );
Vgobject * vggetplyrobj (vgplayer * plyr, int idx );
Void vgplyrmot (vgplayer * plyr, vgmotion * motion );
Vgmotion * vggetplyrmot (vgplayer * plyr );
Void vgplynav (vgplayer * plyr, vgnavigator * NAV );
Vgnavigator * vggetplynav (vgplayer * plyr );
Void vgplyrobservref (vgplayer * plyr, vgobserver * obs );
Vgobserver * vggetplyrobservref (vgplayer * plyr );
Vgplayer * vggetplyrplyrref (vgplayer * plyr );
Void vgplyrplyrref (vgplayer * plyr, vgplayer * plyrd );
Void vgplyrcsref (vgplayer * plyr, vgposition * POS );
Void vggetplyrcsref (vgplayer * plyr, vgposition * POS );
Void vgplyrrepresent (vgplayer * plyr, unsigned mask );
Unsigned vggetplyrrepresent (vgplayer * plyr );
1. attribute settings
You can use the universal functions vgprop () and vggetprop () of Vega to set or obtain the current attribute of the motion body. The following Code Specify the status of a motion body:
Vgprop (plyr, vgcommon_enabled, vg_on );
The following code returns the current status of the motion body:
Plyr_state = vggetprop (plyr, vgcommon_enabled );
The following table lists the attributes supported by the motion body:
Table 6.1 Vega player Properties
Propertydescription
Vgcommon_enabled
[Vg_on]
Vg_offplayer state.
Vgplyr_type
[Vg_air]
Vg_groundspecifies the type of player.
Vgplyr_classnum
[0]-255 player classification.
Vgplyr_team
[0]-255 player team identifier.
Vgplyr_csref
[Vgplyr_absolute]
Vgplyr_obs
Vgplyr_plyr
Vgplyr_csrefposcoordinate system reference mode.
Vgplyr_motion
Vg_on
[Vg_off] specifies whether the attached motion model will influence the player regardless of the current motion model state.
Vgplyr_spline_navigatorspecifies whether the attached spline Navigator will influence the player regardless of the current navigator state.

1. associate a category instance with a sports body instance
Associate a motion pattern with a motion body:
Vgplyrmot (plyr, MOT );
Query the current associated motion modes of a sports body:
Vgmotion * mot;
Mot = vggetplyrmot (plyr );
Vega maintains a list of management entities and Collision Detection classes for each motion body. during operation, all objects associated with the motion body are updated based on the orientation of the motion body and the offset of each object relative to the motion body. Vega provides four APIs for each type of list to manage the list.
Add an object to the motion body list:
Vgaddplyrobj (plyr, OBJ );
Delete an object from the motion body list:
Vgremplyrobj (plyr, OBJ );
Returns the number of entities associated with a motion body:
Num_obj = vggetnumplyrobj (plyr );
Returns an object in the motion body list through an index:
Vgobject * OBJ;
OBJ = vggetplyrobj (0);/* gets the first object in the list */
2. Positioning of motion bodies
The orientation of the motion body can be directly specified by vgpos (), or by the motion mode or navigator associated with the motion body.
/* Position the player */
Vgposition * Pos;
Pos = vgnewpos ();
Vgposvec (Pos, 1000.0f, */0f, 100366f, 90.0f, 0.0f, 0.0f );
Vgpos (plyr, POS );

/* Attach the motion model to a player */
Vgplyrmot (plyr, MOT );
/* Now query the player for the current motion model */
Mot = vggetplyrmot (plyr );

Vgnavigator * nav;
/* Attach the navigator to a player */
Vgplynav (plyr, NAV );
/* Now query the player for the current navigator attachment:
NAV = vggetplynav (plyr );

3. reference coordinate system of the motion body
Generally, the orientation of the motion body is defined in the absolute coordinate system. For convenience, you can also set the attributes of the motion body to change the type of the reference coordinate system. Vega provides an API for reference coordinate system of a motion body relative to other motion bodies, observers, and any specified position:
Observer vgplyrobservref () vggetplyrobservref ()
Player vgplyrplyrref () vggetplyrplyrref ()
Arbitrary vgplyrcsref () vggetplyrcsref ()
The following code specifies a space point (5000.0f, 5000.0f, 1000.0f) as the origin of the reference coordinate system of the motion body.
Vgplayer * plyr;
Vgobject * OBJ;
Vgposition * POs, * cspos;

/* Create a new player */
Plyr = vgnewplyr ();
Vgname (plyr, "plane ");

/* Enable the player */
Vgprop (plyr, vgcommon_enabled, vg_on );

/* Set the player type to air */
Vgprop (plyr, vgplyr_type, vg_air );

/* Find the F16 object and set an object offset value */
OBJ = vgfindobj ("F16 ");

/* Attach the object */
Vgaddplyrobj (plyr, OBJ );

/* Set the coordinate system mode */
Vgprop (plyr, vgplyr_csref, vgplyr_csrefpos );

/* Assign the new coordinate system reference point */
Cspos = vgnewpos ();
Vgposvec (cspos, 5000.0f, 5000.0f, 1000.0f, 0.0f, 0.0f, 0.0f );
Vgplyrcsref (plyr, cspos );

/* Now query the current CS reference */
Vggetplyrcsref (plyr, POS );
4. object orientation
When an object is associated with a moving person, its orientation is determined by the moving body's orientation and the offset between the object and the moving body. Note: When a motion body is associated with a motion mode or a navigator, its orientation is determined by the latter. The orientation previously specified for the motion body is invalid. When an object is associated with a motion body, the orientation previously specified for it is regarded as an offset.
Vgplayer * plyr;
Vgobject * OBJ;
Vgposition * POs, * offpos;

/* Create a new player */
Plyr = vgnewplyr ();
Vgname (plyr, "plane ");

/* Enable the player */
Vgprop (plyr, vgcommon_enabled, vg_on );

/* Set the player type to air */
Vgprop (plyr, vgplyr_type, vg_air );

/* Attach the object */
Vgaddplyrobj (plyr, OBJ );

/* Position the player */
Pos = vgnewpos ();
Vgposvec (Pos, 1000.0f, 1000.0f, 1000000f, 90.0f, 0.0f, 0.0f );
Vgpos (plyr, POS );

5. Body of the Moving Body
Each motion body can be associated with a body similar to its shape and size to support Collision Detection and related operations. The code below associates an individual with a sports body.
Vgvolume * vol;

/* Attach a volume to a player */
Vgplyrvol (plyr, vol );

/* Query the player for the current volume */
Vol = vggetplyrvol (plyr );
6. entity body
In the ApplicationProgramUsually want to get information about the surrounding environment, such as collision detection or altitude. This can be achieved by adding one or more collision detection objects to the motion body. The code below shows how to add a collision detection object to a motion body "plane" for querying the altitude hat from the database. The target of the hat query is the terrain ry in the scene "scene". When each frame is updated, the hat object will automatically move along with the moving of the associated motion body and return the detection results at the new position.
Vgplayer * plyr;
Vgisector * isector;
Vgscene * scene;

/* Create a new player */
Plyr = vgnewplyr ();
Vgname (plyr, "plane ");

/* Enable the player */
Vgprop (plyr, vgcommon_enabled, vg_on );

/* Set the player type to air */
Vgprop (plyr, vgplyr_type, vg_air );

/* Attach the object */
Vgaddplyrobj (plyr, OBJ );

/* Create an isector */
Isector = vgnewisect ();
Vgisecttarget (isector, scene );
Vgisectclass (isector, vgis_terrall );
Vgprop (isector, vgis_method, vgis_hat );
Vgprop (isector, vgis_minz, 10.0f );
Vgprop (isector, vgis_maxz, rj0000f );

/* Attach an isector to a player */
Vgaddplyrisect (plyr, isect );

/* Position the player */
Pos = vgnewpos ();
Vgposvec (Pos, 1000.0f, 1000.0f, 1000000f, 0.0f, 0.0f, 0.0f );
Vgpos (plyr, POS );
7. Callback functions related to the motion body
L vgplyr_add_obj
After adding an object to a motion body, call the callback function in the following format:
Void myfunc (vgcommon * parent, vgcommon * child, void * udata );
L vgplyr_rem_obj
Delete an object from the motion body and call it. The callback function format is as follows:
Void myfunc (vgcommon * parent, vgcommon * child, void * udata );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.