亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? t3dlib4.cpp

?? 3D游戲編程大師技巧第十章的源代碼
?? CPP
?? 第 1 頁 / 共 5 頁
字號:
// T3DLIB4.CPP - Game Engine Part IV, Basic Math Engine Part I
 
// INCLUDES ///////////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN  

//#ifndef INITGUID
//#define INITGUID       // you need this or DXGUID.LIB
//#endif

#include <windows.h>   // include important windows stuff
#include <windowsx.h> 
#include <mmsystem.h>
#include <objbase.h>
#include <iostream.h> // include important C/C++ stuff
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#include <wchar.h>

#include <ddraw.h>      // needed for defs in T3DLIB1.H 
#include "T3DLIB1.H"    // T3DLIB4 is based on some defs in this 
#include "T3DLIB4.H"

// DEFINES ////////////////////////////////////////////////

// TYPES //////////////////////////////////////////////////

// PROTOTYPES /////////////////////////////////////////////

// EXTERNALS /////////////////////////////////////////////

extern HWND main_window_handle;     // access to main window handle in main module

// GLOBALS ////////////////////////////////////////////////

// FUNCTIONS //////////////////////////////////////////////

FIXP16 FIXP16_MUL(FIXP16 fp1, FIXP16 fp2)
{
// this function computes the product fp_prod = fp1*fp2
// using 64 bit math, so as not to loose precission

FIXP16 fp_prod; // return the product

_asm {
     mov eax, fp1      // move into eax fp2
     imul fp2          // multiply fp1*fp2
     shrd eax, edx, 16 // result is in 32:32 format 
                       // residing at edx:eax
                       // shift it into eax alone 16:16
     // result is sitting in eax
     } // end asm

} // end FIXP16_MUL

///////////////////////////////////////////////////////////////

FIXP16 FIXP16_DIV(FIXP16 fp1, FIXP16 fp2)
{
// this function computes the quotient fp1/fp2 using
// 64 bit math, so as not to loose precision

_asm {
     mov eax, fp1      // move dividend into eax
     cdq               // sign extend it to edx:eax
     shld edx, eax, 16 // now shift 16:16 into position in edx
     sal eax, 16       // and shift eax into position since the
                       // shld didn't move it -- DUMB! uPC
     idiv fp2          // do the divide
     // result is sitting in eax     
     } // end asm

} // end FIXP16_DIV

///////////////////////////////////////////////////////////////

void FIXP16_Print(FIXP16 fp)
{
// this function prints out a fixed point number
Write_Error("\nfp=%f", (float)(fp)/FIXP16_MAG);

} // end FIXP16_Print

///////////////////////////////////////////////////////////////

void QUAT_Add(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR qsum)
{
// this function adds two quaternions
qsum->x = q1->x + q2->x;
qsum->y = q1->y + q2->y;
qsum->z = q1->z + q2->z;
qsum->w = q1->w + q2->w;

} // end QUAT_Add

///////////////////////////////////////////////////////////////

 void QUAT_Sub(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR qdiff)
{
// this function subtracts two quaternions, q1-q2
qdiff->x = q1->x - q2->x;
qdiff->y = q1->y - q2->y;
qdiff->z = q1->z - q2->z;
qdiff->w = q1->w - q2->w;

} // end QUAT_Sub

///////////////////////////////////////////////////////////////

void QUAT_Conjugate(QUAT_PTR q, QUAT_PTR qconj)
{
// this function computes the conjugate of a quaternion
qconj->x = -q->x;
qconj->y = -q->y;
qconj->z = -q->z;
qconj->w = q->w;
} // end QUAT_Conjugate

///////////////////////////////////////////////////////////////

void QUAT_Scale(QUAT_PTR q, float scale, QUAT_PTR qs)
{
// this function scales a quaternion and returns it 
qs->x = scale*q->x;
qs->y = scale*q->y;
qs->z = scale*q->z;
qs->w = scale*q->w;

} // end QUAT_Scale

///////////////////////////////////////////////////////////////

void QUAT_Scale(QUAT_PTR q, float scale)
{
// this function scales a quaternion in place
q->x*=scale;
q->y*=scale;
q->z*=scale;
q->w*=scale;

} // end QUAT_Scale

//////////////////////////////////////////////////////////////

float QUAT_Norm(QUAT_PTR q)
{
// returns the length or norm of a quaterion
return(sqrtf(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z));

} // end QUAT_Norm

//////////////////////////////////////////////////////////////

float QUAT_Norm2(QUAT_PTR q)
{
// returns the length or norm of a quaterion squared
return(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z);

} // end QUAT_Norm2

/////////////////////////////////////////////////////////////

void QUAT_Normalize(QUAT_PTR q, QUAT_PTR qn)
{
// this functions normalizes the sent quaternion and 
// returns it

// compute 1/length
float qlength_inv = 1.0/(sqrtf(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z));

// now normalize
qn->w=q->w*qlength_inv;
qn->x=q->x*qlength_inv;
qn->y=q->y*qlength_inv;
qn->z=q->z*qlength_inv;

} // end QUAT_Normalize

/////////////////////////////////////////////////////////////

void QUAT_Normalize(QUAT_PTR q)
{
// this functions normalizes the sent quaternion in place

// compute length
float qlength_inv = 1.0/(sqrtf(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z));

// now normalize
q->w*=qlength_inv;
q->x*=qlength_inv;
q->y*=qlength_inv;
q->z*=qlength_inv;

} // end QUAT_Normalize

//////////////////////////////////////////////////////////////

void QUAT_Unit_Inverse(QUAT_PTR q, QUAT_PTR qi)
{
// this function computes the inverse of a unit quaternion
// and returns the result
// the inverse of a unit quaternion is the conjugate :)
qi->w =  q->w;
qi->x = -q->x;
qi->y = -q->y;
qi->z = -q->z;
} // end QUAT_Unit_Inverse

//////////////////////////////////////////////////////////////

void QUAT_Unit_Inverse(QUAT_PTR q)
{
// this function computes the inverse of a unit quaternion
// in place
// the inverse of a unit quaternion is the conjugate :)
q->x = -q->x;
q->y = -q->y;
q->z = -q->z;
} // end QUAT_Unit_Inverse

/////////////////////////////////////////////////////////////

void QUAT_Inverse(QUAT_PTR q, QUAT_PTR qi)
{
// this function computes the inverse of a general quaternion
// and returns result
// in general, q-1 = *q/|q|2
// compute norm squared
float norm2_inv = 1.0/(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z);

// and plug in
qi->w =  q->w*norm2_inv;
qi->x = -q->x*norm2_inv;
qi->y = -q->y*norm2_inv;
qi->z = -q->z*norm2_inv;

} // end QUAT_Inverse

/////////////////////////////////////////////////////////////

void QUAT_Inverse(QUAT_PTR q)
{
// this function computes the inverse of a general quaternion
// in place
// in general, q-1 = *q/|q|2
// compute norm squared
float norm2_inv = 1.0/(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z);

// and plug in
q->w =  q->w*norm2_inv;
q->x = -q->x*norm2_inv;
q->y = -q->y*norm2_inv;
q->z = -q->z*norm2_inv;

} // end QUAT_Inverse

/////////////////////////////////////////////////////////////

void QUAT_Mul(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR qprod)
{
// this function multiplies two quaternions

// this is the brute force method
//qprod->w = q1->w*q2->w - q1->x*q2->x - q1->y*q2->y - q1->z*q2->z;
//qprod->x = q1->w*q2->x + q1->x*q2->w + q1->y*q2->z - q1->z*q2->y;
//qprod->y = q1->w*q2->y - q1->x*q2->z + q1->y*q2->w - q1->z*q2->x;
//qprod->z = q1->w*q2->z + q1->x*q2->y - q1->y*q2->x + q1->z*q2->w;

// this method was arrived at basically by trying to factor the above
// expression to reduce the # of multiplies

float prd_0 = (q1->z - q1->y) * (q2->y - q2->z);
float prd_1 = (q1->w + q1->x) * (q2->w + q2->x);
float prd_2 = (q1->w - q1->x) * (q2->y + q2->z);
float prd_3 = (q1->y + q1->z) * (q2->w - q2->x);
float prd_4 = (q1->z - q1->x) * (q2->x - q2->y);
float prd_5 = (q1->z + q1->x) * (q2->x + q2->y);
float prd_6 = (q1->w + q1->y) * (q2->w - q2->z);
float prd_7 = (q1->w - q1->y) * (q2->w + q2->z);

float prd_8 = prd_5 + prd_6 + prd_7;
float prd_9 = 0.5 * (prd_4 + prd_8);

// and finally build up the result with the temporary products

qprod->w = prd_0 + prd_9 - prd_5;
qprod->x = prd_1 + prd_9 - prd_8;
qprod->y = prd_2 + prd_9 - prd_7;
qprod->z = prd_3 + prd_9 - prd_6;

} // end QUAT_Mul

///////////////////////////////////////////////////////////

void QUAT_Triple_Product(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR q3, 
                         QUAT_PTR qprod)
{
// this function computes q1*q2*q3 in that order and returns 
// the results in qprod

QUAT qtmp;
QUAT_Mul(q1,q2,&qtmp);
QUAT_Mul(&qtmp, q3, qprod);

} // end QUAT_Triple_Product

///////////////////////////////////////////////////////////

void VECTOR3D_Theta_To_QUAT(QUAT_PTR q, VECTOR3D_PTR v, float theta)
{
// initializes a quaternion based on a 3d direction vector and angle
// note the direction vector must be a unit vector
// and the angle is in rads

float theta_div_2 = (0.5)*theta; // compute theta/2

// compute the quaterion, note this is from chapter 4
// pre-compute to save time
float sinf_theta = sinf(theta_div_2);

q->x = sinf_theta * v->x;
q->y = sinf_theta * v->y;
q->z = sinf_theta * v->z;
q->w = cosf( theta_div_2 );

} // end VECTOR3D_Theta_To_QUAT

///////////////////////////////////////////////////////////////

 void VECTOR4D_Theta_To_QUAT(QUAT_PTR q, VECTOR4D_PTR v, float theta)
{
// initializes a quaternion based on a 4d direction vector and angle
// note the direction vector must be a unit vector
// and the angle is in rads

float theta_div_2 = (0.5)*theta; // compute theta/2

// compute the quaterion, note this is from chapter 4

// pre-compute to save time
float sinf_theta = sinf(theta_div_2);

q->x = sinf_theta * v->x;
q->y = sinf_theta * v->y;
q->z = sinf_theta * v->z;
q->w = cosf( theta_div_2 );

} // end VECTOR4D_Theta_to_QUAT

///////////////////////////////////////////////////////////////

void EulerZYX_To_QUAT(QUAT_PTR q, float theta_z, float theta_y, float theta_x)
{
// this function intializes a quaternion based on the zyx
// multiplication order of the angles that are parallel to the
// zyx axis respectively, note there are 11 other possibilities
// this is just one, later we may make a general version of the
// the function

// precompute values
float cos_z_2 = 0.5*cosf(theta_z);
float cos_y_2 = 0.5*cosf(theta_y);
float cos_x_2 = 0.5*cosf(theta_x);

float sin_z_2 = 0.5*sinf(theta_z);
float sin_y_2 = 0.5*sinf(theta_y);
float sin_x_2 = 0.5*sinf(theta_x);

// and now compute quaternion
q->w = cos_z_2*cos_y_2*cos_x_2 + sin_z_2*sin_y_2*sin_x_2;
q->x = cos_z_2*cos_y_2*sin_x_2 - sin_z_2*sin_y_2*cos_x_2;
q->y = cos_z_2*sin_y_2*cos_x_2 + sin_z_2*cos_y_2*sin_x_2;
q->z = sin_z_2*cos_y_2*cos_x_2 - cos_z_2*sin_y_2*sin_x_2;

} // EulerZYX_To_QUAT

///////////////////////////////////////////////////////////////

void QUAT_To_VECTOR3D_Theta(QUAT_PTR q, VECTOR3D_PTR v, float *theta)
{
// this function converts a unit quaternion into a unit direction
// vector and rotation angle about that vector

// extract theta
*theta = acosf(q->w);

// pre-compute to save time
float sinf_theta_inv = 1.0/sinf(*theta);

// now the vector
v->x    = q->x*sinf_theta_inv;
v->y    = q->y*sinf_theta_inv;
v->z    = q->z*sinf_theta_inv;

// multiply by 2
*theta*=2;

} // end QUAT_To_VECTOR3D_Theta

////////////////////////////////////////////////////////////

void QUAT_Print(QUAT_PTR q, char *name="q")
{
// this function prints out a quaternion
Write_Error("\n%s=%f+[(%f)i + (%f)j + (%f)k]", 
       name, q->w, q->x, q->y, q->z);

} // end QUAT_Print

///////////////////////////////////////////////////////////

float Fast_Sin(float theta)
{
// this function uses the sin_look[] lookup table, but
// has logic to handle negative angles as well as fractional
// angles via interpolation, use this for a more robust
// sin computation that the blind lookup, but with with
// a slight hit in speed

// convert angle to 0-359
theta = fmodf(theta,360);

// make angle positive
if (theta < 0) theta+=360.0;

// compute floor of theta and fractional part to interpolate
int theta_int    = (int)theta;
float theta_frac = theta - theta_int;

// now compute the value of sin(angle) using the lookup tables
// and interpolating the fractional part, note that if theta_int
// is equal to 359 then theta_int+1=360, but this is fine since the
// table was made with the entries 0-360 inclusive
return(sin_look[theta_int] + 
       theta_frac*(sin_look[theta_int+1] - sin_look[theta_int]));

} // end Fast_Sin

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
fc2成人免费人成在线观看播放| 欧美日韩精品综合在线| 亚洲成av人综合在线观看| 亚洲欧美怡红院| 亚洲福利一二三区| 国产精品99久久久久久似苏梦涵 | 免费在线观看一区| 国内精品久久久久影院色| 91啪亚洲精品| 日韩精品一区在线观看| 中文字幕亚洲一区二区av在线 | 欧美综合一区二区| 日韩欧美一卡二卡| 国产99精品国产| 欧美一级搡bbbb搡bbbb| 亚洲婷婷综合色高清在线| 欧美精品自拍偷拍| 日韩综合在线视频| 九九热在线视频观看这里只有精品 | 99精品视频在线免费观看| 日韩美女视频在线| 国产成人无遮挡在线视频| 欧美视频三区在线播放| 国产欧美一区二区在线观看| 日韩中文字幕不卡| 国产午夜久久久久| 经典三级视频一区| 亚洲乱码国产乱码精品精小说| 男女男精品视频| 国产精品护士白丝一区av| 国产91在线|亚洲| 亚洲高清免费视频| 中文字幕精品一区二区三区精品 | 伊人性伊人情综合网| 欧美不卡123| 免费的国产精品| 国产精品网站导航| 久久成人av少妇免费| 91超碰这里只有精品国产| 亚洲综合在线第一页| 欧美在线观看一区| 国产精品99久久久久久有的能看| 亚洲一区在线视频观看| 国产无人区一区二区三区| 欧美日韩国产综合草草| 成人av网站免费观看| 国产精品麻豆网站| 精品久久久久av影院| 精品视频在线免费观看| 五月天网站亚洲| 日韩一区和二区| 韩国一区二区在线观看| 亚洲国产乱码最新视频| 亚洲免费在线视频一区 二区| 色呦呦国产精品| 亚洲一区二区三区视频在线| 久久久99精品免费观看不卡| 在线成人免费视频| 日本韩国精品在线| 日本伊人色综合网| www久久久久| www.亚洲人| 丁香婷婷综合色啪| 国产九九视频一区二区三区| 日韩av午夜在线观看| 免费欧美在线视频| 午夜久久久影院| 亚洲一二三四在线观看| 最新高清无码专区| 国产精品超碰97尤物18| 中文字幕欧美区| 日本一区免费视频| 国产欧美一区二区在线观看| 久久婷婷国产综合精品青草| 精品国产不卡一区二区三区| 成人国产精品免费| 成人午夜又粗又硬又大| 亚洲在线观看免费| 亚洲bt欧美bt精品777| 亚洲小说春色综合另类电影| 亚洲午夜三级在线| 亚洲成a人片综合在线| 午夜一区二区三区在线观看| 亚洲va天堂va国产va久| 日韩国产高清影视| 久久99精品久久久久| 国产一区二区精品在线观看| 亚洲九九爱视频| 一区二区三区在线免费播放| 精品久久久久久久人人人人传媒| 精品女同一区二区| 国产农村妇女精品| 亚洲女同女同女同女同女同69| 亚洲激情男女视频| 日韩精品免费专区| 久久国产精品免费| 成人激情视频网站| 欧美中文字幕一区二区三区| 欧美精品123区| 精品国产一区二区亚洲人成毛片| 久久精品一区二区三区不卡| 亚洲素人一区二区| 天天色天天操综合| 国产福利精品一区| av亚洲精华国产精华精| 欧美亚洲国产一区二区三区va| 欧美精品在线观看一区二区| 精品国产免费人成在线观看| 国产精品热久久久久夜色精品三区 | 亚洲精品视频一区| 日韩国产高清在线| 不卡电影一区二区三区| 欧美浪妇xxxx高跟鞋交| 国产欧美视频一区二区三区| 一区二区三区中文字幕电影| 久久国产尿小便嘘嘘尿| 91丨porny丨在线| 欧美成人a在线| 一区二区三区在线观看视频| 精油按摩中文字幕久久| 日本道免费精品一区二区三区| 日韩欧美黄色影院| 亚洲色图视频网| 精品一二三四在线| 欧美日韩另类一区| 欧美国产精品v| 日韩va亚洲va欧美va久久| 成人免费观看视频| 欧美大胆一级视频| 午夜精品久久久久| zzijzzij亚洲日本少妇熟睡| 欧美一区二区黄| 亚洲一区视频在线观看视频| 国内久久婷婷综合| 欧美精品一二三| 亚洲永久免费视频| 99vv1com这只有精品| 久久久久亚洲蜜桃| 国产女主播一区| 麻豆91免费观看| 国产成人免费xxxxxxxx| 337p亚洲精品色噜噜| 亚洲摸摸操操av| av毛片久久久久**hd| 久久久久久电影| 精品一区二区三区视频| 欧美久久久久久蜜桃| 亚洲自拍偷拍九九九| 成人久久久精品乱码一区二区三区| 欧美电影免费提供在线观看| 爽爽淫人综合网网站| 欧美图片一区二区三区| 亚洲三级久久久| 91麻豆精品在线观看| 国产精品毛片高清在线完整版| 国产乱码精品一区二区三区av | 972aa.com艺术欧美| 国产精品人妖ts系列视频| 国产成人精品综合在线观看| 精品国产91乱码一区二区三区| 视频在线观看一区| 欧美久久久一区| 日韩精品电影一区亚洲| 欧美日韩亚洲综合一区二区三区 | 婷婷丁香久久五月婷婷| 欧美日精品一区视频| 亚洲午夜av在线| 欧美少妇bbb| 午夜精品久久一牛影视| 欧美日韩另类一区| 日韩avvvv在线播放| 日韩欧美一区二区免费| 蜜臀av性久久久久蜜臀aⅴ | 国产精品三级电影| 91色视频在线| 亚洲成人免费视频| 欧美一区二区三区四区高清| 麻豆91小视频| 日本一区二区三区四区| 97久久精品人人做人人爽| 亚洲欧美一区二区久久| 欧美综合一区二区| 日产国产欧美视频一区精品| 精品欧美黑人一区二区三区| 国产精品888| 最新不卡av在线| 欧美精品在线观看播放| 狠狠狠色丁香婷婷综合激情| 国产片一区二区三区| 色呦呦一区二区三区| 日本视频免费一区| 久久综合狠狠综合久久综合88| 丁香婷婷综合色啪| 亚洲一区二区三区视频在线播放| 91精品国产综合久久精品麻豆| 国产在线一区二区综合免费视频| 国产精品伦一区二区三级视频| 在线一区二区观看| 韩国午夜理伦三级不卡影院| 亚洲欧美综合另类在线卡通|