mvtview.c 20.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
/*====================================================================
 * mvtview.c
 *
 * Copyright 1995, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/


#include <ultra64.h>

/* define here so to override default definition, thus can use mvtdef macros */
#define MVTLOOKUP(V,PTR,N)	(&V->data[PTR])

#include "gfx.h"
#include "acos_i.h"
#include "matrix.h"
#include "mvtview.h"
#include "misc.h"


/* #define DEBUG */


/*
 * Used to depth sort the objects
 */
static float mvt_order_depth[MVT_MAX_OBJECTS];
static u8    mvt_order_object_id[MVT_MAX_OBJECTS];


/*
 * Array of MVT definitions
 */
       MVTTemplate mvt_template[MVT_MAX_TEMPLATES];
       int         mvt_num_templates = 0;
static MVTObject   mvt_object[MVT_MAX_OBJECTS];
static int         mvt_num_objects = 0;
static MVTGroup    mvt_group[MVT_MAX_GROUPS];
static int         mvt_num_groups = 0;


/*#### hardwired ####*/
static int lighting = 1;
static int culling  = 1;
/*#### hardwired ####*/


/****************************************************************************

For the given view direction (index), generate the appropriate mvt texture
using the template passed in. Texture is decompressed in constant
time (after the first decompression) assuming the view point has not
changed that much.

****************************************************************************/
static void
MVT_generate_view(MVTTemplate *mvt, short index, 
                  MVTTextureType texture[MVT_MAX_TILES][MVT_TILE_SIZE], 
                  u8 xluback, u8 interpolate)
{
   u16    x,y,found,left_subtexture_id,subtexture_id;
   u16    num_rows, num_cols, xtile, tile_xsize;
   int    n,ptr = 0;
   short  red,green,blue,alpha,nred,ngreen,nblue;
   short  this_index,next_index,i0,i1,pixel;
   u16    num_entries,last_used,base,nbase;

#if 0
   for (y=0; y<32; y++)
    for (x=0; x<32; x++)
     for (n=0; n<4; n++)
       texture[n][y*32+x] = 0xffffffff;

   return;
#endif

   num_cols = mvt->width >> 5;
   if ((num_cols * 32) < mvt->width) num_cols++;

   /*
    * Decompress the MVT into the appropriate number of tiles
    */
   left_subtexture_id = 0;
   for (y=0; y<mvt->height; y++) {

    if ((y > 0) && !(y % 32)) left_subtexture_id += num_cols;

    for (x=0,xtile=0; x<mvt->width; x++) {

        found = FALSE;

        if (x == 0) {
           subtexture_id = left_subtexture_id;
           tile_xsize = 32;
        } else if (!(x % 32)) {
           subtexture_id++;
           xtile++;
           if (xtile == (mvt->num_xtiles-1)) {
              tile_xsize = mvt->width % 32;
              if (tile_xsize == 0) tile_xsize = 32;
           } else
              tile_xsize = 32;
        }

        /* cache num of entries and last used offset for this pixel */
        MVT_GET_NUM_ENTRIES(mvt,ptr,NULL,num_entries);
        MVT_GET_LAST_USED(mvt,ptr,NULL,last_used);

        for (n=last_used; n>=0 && n<num_entries; ) {

           MVT_GET_BASE(mvt,ptr,NULL,n  ,base);
           MVT_GET_BASE(mvt,ptr,NULL,n+1,nbase);

           MVT_GET_ENTRY_INDEX(mvt,ptr,NULL, base,this_index);
           if ((n+1) < num_entries)
              MVT_GET_ENTRY_INDEX(mvt,ptr,NULL,nbase,next_index);
           else
              next_index = 1<<15;

           if ((num_entries == 1) ||
               (index >  this_index && index <= next_index) ||
               (index <= this_index && n == 0) ||
               (index >  this_index && n == num_entries-1)) {
              /* use this one */

              if (n != (num_entries-1) && 
                  index > this_index && index <= next_index) {

                 MVT_GET_ENTRY_COLOR(mvt,ptr,NULL,base,red,green,blue);
                 i0 = this_index;

                 MVT_GET_ENTRY_COLOR(mvt,ptr,NULL,nbase,nred,ngreen,nblue);
                 i1 = next_index;

                 n++;

                 if (interpolate) {
                    if ((nred != 0 || ngreen != 0 || nblue != 0) &&
                       ( red != 0 ||  green != 0 ||  blue != 0)) {

                      /* by definition, i1>i0, so assume this */
                      nred   = red +   ((nred  -  red)*(index-i0)) / ((i1-i0));
                      ngreen = green + ((ngreen-green)*(index-i0)) / ((i1-i0));
                      nblue  = blue +  ((nblue - blue)*(index-i0)) / ((i1-i0));
                    }
                 }

                 if (xluback) {
                    if (nred==0 && ngreen==0 && nblue==0)
                       alpha = 0;
                    else
                       alpha = 1;
                 } else
                    alpha = 1;

                 /* assumes that only the LAST row or col will be < 32 */
                 pixel = (y % 32) * tile_xsize + (x % 32);

                 MVT_SET_COLOR_TO_FB(texture[subtexture_id],pixel,
                                     nred,ngreen,nblue,alpha);
              } else {

                 MVT_GET_ENTRY_COLOR(mvt,ptr,NULL,base,red,green,blue);

                 if (xluback) {
                    if (red==0 && green==0 && blue==0)
                       alpha = 0;
                    else
                       alpha = 1;
                 } else
                    alpha = 1;

                 /* assumes that only the LAST row or col will be < 32 */
                 pixel = (y % 32) * tile_xsize + (x % 32);

                 MVT_SET_COLOR_TO_FB(texture[subtexture_id],pixel,
                                     red,green,blue,alpha);
              }

              MVT_SET_LAST_USED(mvt,ptr,NULL,n);
              found = TRUE;
              break;

           } else if (index <= this_index) {
              n--;
           } else {
              n++;
           }
        }

        if (!found) 
           rmonPrintf("MVT_generate_view(): pixel %i,%i not found!\n",x,y);

        ptr += MVT_ENTRY_SIZE*num_entries+MVT_ENTRY_HEADER;
     }
    }
}


/****************************************************************************

Assuming the view plane is in the xz plane, compute the view angle
to it from the eyept passed in.

The angle_offset offsets the angle by that amount (i.e. if the case of
"0" is not axis aligned with the y or z axis).

****************************************************************************/
static short
MVT_compute_view_angle(float xpos, float ypos, float zpos, float eyept[3],
                       float angle_offset)
{
   float eyep[2],eyev[2],v[2],base,len,dot,angle;

   eyep[0] = eyept[0] - xpos;
   eyep[1] = eyept[1] - ypos;

   len     = sqrtf(SQR(eyep[0])+SQR(eyep[1]));
   eyev[0] = eyep[0] / len;
   eyev[1] = eyep[1] / len;

   if      (eyep[0] >= 0 && eyep[1] >= 0) {base = 0;   v[0] =  0; v[1] =  1;}
   else if (eyep[0] >= 0 && eyep[1] <= 0) {base = 90;  v[0] =  1; v[1] =  0;}
   else if (eyep[0] <= 0 && eyep[1] <= 0) {base = 180; v[0] =  0; v[1] = -1;}
   else if (eyep[0] <= 0 && eyep[1] >= 0) {base = 270; v[0] = -1; v[1] =  0;}

   dot   = DOT2(eyev, v);
   angle = ACOS_I(dot) + base;

#ifdef DEBUG
/*    rmonPrintf("\tdot = %f, base = %f, angle_offset = %f\n", */
/*               angle - base, base, angle_offset); */
#endif

   angle -= angle_offset;

   if (angle > 180) angle = -1*(360 - angle);

   return ((short)angle);
}


/****************************************************************************

Update the mvt texture and the matrices of the group.

****************************************************************************/
static void
MVT_update_group(int group_id, Dynamic *dynamicp, float eyept[3])
{
   MVTObject *obj,*prev_obj = NULL;
   Mtx        scaleMat,rotMat,transMat;
   int        object_id;
   u8         xluback=0,interpolate=0;
   u8         indep_rot = mvt_group[group_id].indep_rot;
   s16        n,angle;
   float      xpos = 0;
   float      ypos = 0;
   float      zpos = 0;
   float      angle_offset = 0;
   float      rotation = 0;

   /*
    * Compute the average position of all group objects
    */
   for (n=0; n<mvt_group[group_id].num_objects; n++) {
      obj = &mvt_object[mvt_group[group_id].object_id[n]];
      xpos         += obj->xpos;
      ypos         += obj->ypos;
      zpos         += obj->zpos;
      angle_offset += obj->angle_offset;
      rotation     += obj->rotation;
      xluback      |= obj->xluback;
      interpolate  |= obj->interpolate;
   }

   if (mvt_group[group_id].num_objects > 1) {
      xpos         /= mvt_group[group_id].num_objects;
      ypos         /= mvt_group[group_id].num_objects;
      zpos         /= mvt_group[group_id].num_objects;
      angle_offset /= mvt_group[group_id].num_objects;
      rotation     /= mvt_group[group_id].num_objects;
   }

   /*
    * Determine the view angle required for this average group position
    */
   angle = MVT_compute_view_angle(xpos, ypos, zpos, eyept, angle_offset);

#ifdef DEBUG
   rmonPrintf("angle=%hi, rotation=%f\n",angle,rotation);
#endif

   /*
    * If going to render as texture and if different than the current 
    * decompressed texture, regenerate the texture to use.
    */
   rotation += angle;
   if (rotation >  180) rotation = -1*(360 - rotation);
   if (rotation < -180) rotation =  1*(rotation + 360);

   if (rotation != mvt_group[group_id].last_angle1) {
      MVT_generate_view(&mvt_template[mvt_group[group_id].template_id], 
                   -rotation, dynamicp->mvt_texture[group_id],
                   xluback, interpolate);
      mvt_group[group_id].last_angle1 = rotation;
   } else if (rotation != mvt_group[group_id].last_angle2) {
      MVT_generate_view(&mvt_template[mvt_group[group_id].template_id], 
                   -rotation, dynamicp->mvt_texture[group_id],
                   xluback, interpolate);
      mvt_group[group_id].last_angle2 = rotation;
   }


   /*
    * Foreach object of the group, compute its modeling matrix
    */
   if (!indep_rot) guRotate(&rotMat, -angle, 0.0, 0.0, 1.0);

   for (n=0; n<mvt_group[group_id].num_objects; n++) {

      object_id = mvt_group[group_id].object_id[n];
      obj       = &mvt_object[object_id];


      /* for MVT */

      guScale(&scaleMat, obj->scale, obj->scale, obj->scale);

      if (indep_rot) {

         /* All textures in the group are decompressed from the same view
            point, but they are rotated to always face the user */
         angle = MVT_compute_view_angle(obj->xpos, obj->ypos, obj->zpos, eyept,
                                        obj->angle_offset);

         guRotate(&rotMat, -angle, 0.0, 0.0, 1.0);
      }

      /* translate the mvt to its world space position */
      if (obj->translates)
         guTranslate(&transMat,obj->xpos,obj->ypos,obj->zpos);
      else
         guTranslate(&transMat,0,0,0);

      makeIdentMtx(&dynamicp->mvt[object_id]);
      multMtx(&dynamicp->mvt[object_id],&transMat,&dynamicp->mvt[object_id]);
      multMtx(&dynamicp->mvt[object_id],&scaleMat,&dynamicp->mvt[object_id]);
      multMtx(&dynamicp->mvt[object_id],&rotMat,  &dynamicp->mvt[object_id]);


      /* for Geometry */

      guScale(&scaleMat, obj->scale, obj->scale, obj->scale);
      guRotate(&rotMat, rotation-angle, 0.0, 0.0, 1.0);

      if (obj->translates)
         guTranslate(&transMat,obj->xpos,obj->ypos,obj->zpos);
      else
         guTranslate(&transMat,0,0,0);

      makeIdentMtx(&dynamicp->mvtg[object_id]);
      multMtx(&dynamicp->mvtg[object_id],&transMat,&dynamicp->mvtg[object_id]);
      multMtx(&dynamicp->mvtg[object_id],&rotMat,&dynamicp->mvtg[object_id]);
      multMtx(&dynamicp->mvtg[object_id],&scaleMat,&dynamicp->mvtg[object_id]);
   }
}


/****************************************************************************

Compute the depths from eyept to mvt object centers.

****************************************************************************/
static void
MVT_compute_depths(float eyept[3])
{
   float dist[2],val;
   int   n;

   /*
    * Compute the distances from objects to eye point
    */
   for (n=0; n<mvt_num_objects; n++) {
      dist[0] = mvt_object[n].xpos - eyept[0];
      dist[1] = mvt_object[n].ypos - eyept[1];

      mvt_order_depth[n]     = DOT2(dist,dist);
      mvt_order_object_id[n] = n;

#ifdef DEBUG
      val = sqrtf(mvt_order_depth[n]);
      rmonPrintf("%1.2f ",val);
#endif
   }
#ifdef DEBUG
   rmonPrintf("\n");
#endif
}


/****************************************************************************

Sort mvt objects by depth.

****************************************************************************/
#define SWAP(A,B,T)	\
	if (1)	{	\
	   T = B;	\
	   B = A;	\
	   A = T;	\
	} else
static void
MVT_depth_sort(float eyept[3])
{
   float tmp_depth;
   u8    tmp_object_id;
   int   n,sorting;

   /*
    * Do a depth sort, using bubble-sort, inefficient but the
    * number of objects should be small anyway
    */
   do {
      sorting = 0;
      for (n=0; n<(mvt_num_objects-1); n++) {
         if (mvt_order_depth[n] < mvt_order_depth[n+1]) {
            SWAP(mvt_order_depth[n],mvt_order_depth[n+1],tmp_depth);
            SWAP(mvt_order_object_id[n],mvt_order_object_id[n+1],tmp_object_id);
            sorting = 1;
         }
      }
   } while (sorting);
}


/****************************************************************************

Render a mvt objects as texture or geometry.

****************************************************************************/
static void
MVT_render_objects(Dynamic *dynamicp)
{
   u16           n,t,xtile,ytile,tile_xsize,tile_ysize;
   u16           group_id,template_id,object_id;
   unsigned char talpha;
   float         tmp;
   u32           geometrymode;


   gDPPipeSync(glistp++);
   for (n=0; n<mvt_num_objects; n++) {

      object_id   = mvt_order_object_id[n];
      group_id    = mvt_object[object_id].group_id;
      template_id = mvt_group[group_id].template_id;


      /*
       * Draw regular geometry
       */
      if (mvt_order_depth[n] < mvt_object[object_id].t2texture) {

         gDPLoadSync(glistp++);
         gSPMatrix(glistp++, osVirtualToPhysical(&dynamicp->projection),
                   G_MTX_PROJECTION|G_MTX_LOAD|G_MTX_NOPUSH);
         gSPMatrix(glistp++, osVirtualToPhysical(&dynamicp->viewing),
                   G_MTX_PROJECTION|G_MTX_MUL|G_MTX_NOPUSH);
         gSPMatrix(glistp++, osVirtualToPhysical(&dynamicp->mvtg[object_id]),
                   G_MTX_MODELVIEW|G_MTX_LOAD|G_MTX_NOPUSH);

         /* set appropriate geometry mode */
         gSPClearGeometryMode (glistp++, 0xffffffff);
         geometrymode = G_SHADING_SMOOTH | G_ZBUFFER | G_SHADE;
         if (lighting) geometrymode |= G_LIGHTING;
         if (culling)  geometrymode |= G_CULL_BACK;
         gSPSetGeometryMode (glistp++, geometrymode);



         gSPDisplayList(glistp++, mvt_common_geometry_dl);
         gSPDisplayList(glistp++, mvt_template[template_id].geometry_dl);
      }


      /* 
       * Draw as MVT texture
       */
      if (mvt_order_depth[n] >= mvt_object[object_id].t2geometry) {

         gSPMatrix(glistp++, osVirtualToPhysical(&dynamicp->projection), 
                   G_MTX_PROJECTION|G_MTX_LOAD|G_MTX_NOPUSH);
         gSPMatrix(glistp++, osVirtualToPhysical(&dynamicp->viewing), 
                   G_MTX_PROJECTION|G_MTX_MUL|G_MTX_NOPUSH);
         gSPMatrix(glistp++, osVirtualToPhysical(&dynamicp->mvt[object_id]), 
                   G_MTX_MODELVIEW|G_MTX_LOAD|G_MTX_NOPUSH);
         gSPDisplayList(glistp++, mvt_common_texture_dl);

         if (mvt_order_depth[n] < mvt_object[object_id].t2texture) {

            /*
             * Draw dissappearing edges
             */
            tmp = (mvt_order_depth[n]-mvt_object[object_id].t2geometry) / 
             (mvt_object[object_id].t2texture-mvt_object[object_id].t2geometry);
            talpha = 255 - (u8)(tmp*255.0);

	    gDPSetBlendColor(glistp++, 255, 255, 255, talpha);
         } else {
	    gDPSetBlendColor(glistp++, 255, 255, 255, 1);
         }

         if (mvt_template[template_id].height < 32) {
            tile_ysize = mvt_template[template_id].height;
            if (tile_ysize % 4) tile_ysize += 4 - (tile_ysize % 4);
         } else
            tile_ysize = 32;

         for (t=0,xtile=0,ytile=0; t<mvt_template[template_id].num_tiles; t++) {

            if (xtile == (mvt_template[template_id].num_xtiles-1)) {
               tile_xsize = mvt_template[template_id].width % 32;
               if (tile_xsize == 0) tile_xsize = 32;
               if (tile_xsize % 4) tile_xsize += 4 - (tile_xsize % 4);
            } else
               tile_xsize = 32;

#ifdef DEBUG
            rmonPrintf("(%hi,%hi) ",tile_xsize,tile_ysize);
#endif

            gDPLoadTextureBlock(glistp++, 
                osVirtualToPhysical(&dynamicp->mvt_texture[group_id][t][0]),
                G_IM_FMT_RGBA,
#ifdef MVT_16_BIT
                G_IM_SIZ_16b, 
#endif
#if defined(MVT_32_BIT) || defined(MVT_32_BIT_SPECIAL)
                G_IM_SIZ_32b, 
#endif
                tile_xsize, tile_ysize, 0, G_TX_CLAMP | G_TX_NOMIRROR,
                G_TX_CLAMP | G_TX_NOMIRROR, MVT_TEXSCALE_MASK, 
                MVT_TEXSCALE_MASK, MVT_XTEXSCALE_SHIFT, MVT_YTEXSCALE_SHIFT);
            gSPVertex(glistp++,&(mvt_template[template_id].mvt_vtx[t][0]),4,0);
            gSP1Triangle(glistp++, 0, 1, 2, 0);
            gSP1Triangle(glistp++, 0, 2, 3, 0);

            xtile++;
            if (xtile == mvt_template[template_id].num_xtiles) {
               xtile = 0;
               ytile++;

               if (ytile == (mvt_template[template_id].num_ytiles-1)) {
                  tile_ysize = mvt_template[template_id].height % 32;
                  if (tile_ysize == 0) tile_ysize = 32;
                  if (tile_ysize % 4) tile_ysize += 4 - (tile_ysize % 4);
               } else
                  tile_ysize = 32;
            }
         }
#ifdef DEBUG
         rmonPrintf("\n");
#endif
      }
   }
}


/****************************************************************************
****************************************************************************/
int
MVTcreate_group(int template_id, int indep_rot)
{
   int group_id = mvt_num_groups++;

   mvt_group[group_id].last_angle1 = -9999;
   mvt_group[group_id].last_angle2 = -9999;
   mvt_group[group_id].num_objects = 0;
   mvt_group[group_id].template_id = template_id;
   mvt_group[group_id].indep_rot   = indep_rot;

  return (group_id);
}


/****************************************************************************
****************************************************************************/
int 
MVTinstance_object(int group_id, 
                   float xpos, float ypos, float zpos, float rotation, 
                   float angle_offset, 
                   int   translates,
                   int   xluback,
                   int   interpolate,
                   float scale,
                   float transition_delta,
                   float tdist)
{
   int object_id = mvt_num_objects++;

   mvt_object[object_id].xpos         = xpos;
   mvt_object[object_id].ypos         = ypos;
   mvt_object[object_id].zpos         = zpos;
   mvt_object[object_id].rotation     = rotation;
   mvt_object[object_id].angle_offset = angle_offset;
   mvt_object[object_id].translates   = translates;
   mvt_object[object_id].xluback      = xluback;
   mvt_object[object_id].interpolate  = interpolate;
   mvt_object[object_id].scale        = scale;
   mvt_object[object_id].t2texture    = SQR(tdist*scale);
   mvt_object[object_id].t2geometry   = SQR(scale*(tdist-transition_delta));
   mvt_object[object_id].group_id     = group_id;

   mvt_group[group_id].object_id[mvt_group[group_id].num_objects] = object_id;
   mvt_group[group_id].num_objects++;

   return (object_id);
}

/****************************************************************************
****************************************************************************/
void 
MVTset_position(int object_id, float pos[3], float rotation)
{
   mvt_object[object_id].rotation  = rotation;
   mvt_object[object_id].xpos      = pos[0];
   mvt_object[object_id].ypos      = pos[1];
   mvt_object[object_id].zpos      = pos[2];
   mvt_group[mvt_object[object_id].group_id].last_angle1 = -9999;
   mvt_group[mvt_object[object_id].group_id].last_angle2 = -9999;
}

/****************************************************************************
****************************************************************************/
void 
MVTdraw(Dynamic *dynamicp, float eyept[3])
{
   int n;

   MVT_compute_depths(eyept);

   for (n=0; n<mvt_num_groups; n++)
      MVT_update_group(n, dynamicp, eyept);

   MVT_depth_sort(eyept);
   MVT_render_objects(dynamicp);

   osWritebackDCacheAll();
}