⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vectshape.cs

📁 3d游戏开发大全书所附带源吗,第3章,开发环境UltraEdit
💻 CS
字号:
// ========================================================================
//  animshape.cs
//
//  This module contains the definition of a test shape, which uses
//  a model of a stylized heart. It also contains functions for placing
//  the test shape in the game world and then animating the shape using 
//  a recurring scheduled function call.
// ========================================================================

datablock ItemData(TestShape)
// ----------------------------------------------------
//     Definition of the shape object
// ----------------------------------------------------
{
   // Basic Item properties
   shapeFile = "~/data/shapes/items/heart.dts";
   mass = 1;      //we give the shape mass and
   friction = 1;  // friction to stop the item from sliding
                  // down hills
};

function InsertTestShape()
// ----------------------------------------------------
//     Instantiates the test shape, then inserts it
//     into the game world roughly in front of the
//     the player's default spawn location.
// ----------------------------------------------------
{
   // An example function which creates a new TestShape object
   %shape = new Item() {
      datablock = TestShape;
      rotation = "0 0 1 0"; // initialize the values
                            // to something meaningful
   };
   MissionCleanup.add(%shape);

   // Player setup
   %shape.setTransform("-90 -2 20 0 0 1 0"); 
   echo("Inserting Shape " @ %shape);
   return %shape;
}

function AnimShape(%shape, %dist, %angle, %scale)
// ----------------------------------------------------
//     moves the %shape by %dist amount, and then
//     schedules itself to be called again in 1/5
//     of a second.
// ----------------------------------------------------
{
   %xfrm = %shape.getTransform();
   %lx = getword(%xfrm,0); // first, get the current transform values
   %ly = getword(%xfrm,1);
   %lz = getword(%xfrm,2);
   %rx = getword(%xfrm,3);
   %ry = getword(%xfrm,4);
   %rz = getword(%xfrm,5);
   %lx += %dist;           // set the new x position
   %angle += 1.0;
   %rd = %angle;           // Set the rotation angle 
   
   if ($grow)             // if the shape is growing larger
   {
    if (%scale < 5.0)     // and hasn't gotten too big
      %scale += 0.3;      // make it bigger
    else
      $grow = false;      // if it's too big, don't let it grow more
   }
   else                 // if it's shrinking
   {
     if (%scale > 3.0)  // and isn't too small 
       %scale -= 0.3;   // then make it smaller
     else
       $grow = true;   // if it's too small, don't let it grow smaller
   }
     
   %shape.setScale(%scale SPC %scale SPC %scale);    
   %shape.setTransform(%lx SPC %ly SPC %lz SPC %rx SPC %ry SPC %rz SPC %rd);
   schedule(200,0,AnimShape, %shape, %dist, %angle, %scale);

}

function DoAnimTest()
// ----------------------------------------------------
//     a function to tie together the instantion
//     and the movement in one easy to type function
//     call.
// ----------------------------------------------------
{
   %ms = InsertTestShape();
   $grow = true;
   AnimShape(%ms,0.2, 1, 2);
}


// %vector = %obj.getMuzzleVector( %slot );
// %xAngle = 0;
// %yAngle = 0;
// %zAngle = 90 * 3.1415926 / 180;

// %matrix = MatrixCreateFromEuler( %xAngle SPC %yAngle SPC %zAngle);

// %resultVector = MatrixMulVector( %matrix, %vector );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -