亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
51精品视频一区二区三区| 欧美日韩在线不卡| 亚洲国产精品精华液网站| 日韩精品中文字幕一区二区三区 | 国产.精品.日韩.另类.中文.在线.播放| 综合久久综合久久| 久久久久国产免费免费| 欧美年轻男男videosbes| 高清视频一区二区| 日本不卡高清视频| 亚洲综合在线第一页| 欧美高清一级片在线观看| 91精品国产综合久久福利| 91网上在线视频| 国产成人精品午夜视频免费| 懂色av一区二区三区蜜臀| 日韩电影网1区2区| 亚洲一区二区成人在线观看| 国产精品久久久久久户外露出 | 国产精品激情偷乱一区二区∴| 日韩女优制服丝袜电影| 欧美色图免费看| 91久久奴性调教| 色综合中文字幕国产 | 日本人妖一区二区| 亚洲国产成人高清精品| 亚洲乱码日产精品bd| 中文字幕av一区二区三区免费看| 久久亚洲捆绑美女| 精品av综合导航| 日韩三级精品电影久久久| 欧美另类videos死尸| 欧美午夜精品久久久久久超碰| 91日韩在线专区| 91丨九色丨黑人外教| 成人高清在线视频| 成人av手机在线观看| 成人性生交大片免费看中文| 激情欧美一区二区| 国产永久精品大片wwwapp| 久久99国产精品免费| 久久精品国产网站| 黄网站免费久久| 国产一区二区不卡在线| 国产乱码字幕精品高清av| 国模一区二区三区白浆| 国产精品一区三区| 成人精品高清在线| av福利精品导航| 97se亚洲国产综合自在线不卡| 色综合久久久久网| 欧美日韩和欧美的一区二区| 91精品国产黑色紧身裤美女| 欧美一级一区二区| 久久久噜噜噜久久人人看| 国产网站一区二区| 亚洲图片激情小说| 亚洲v精品v日韩v欧美v专区| 青青草国产精品亚洲专区无| 国产一区二三区好的| 成人免费视频app| 91丨九色丨黑人外教| 欧美浪妇xxxx高跟鞋交| 欧美一区二区三区四区高清 | 精品欧美乱码久久久久久1区2区| 久久久久久久久久久电影| 国产精品久久久久久久蜜臀| 亚洲免费在线观看视频| 午夜欧美电影在线观看| 久久精品久久综合| 成人黄色av网站在线| 在线视频你懂得一区二区三区| 久久久青草青青国产亚洲免观| 国产精品日日摸夜夜摸av| 一区二区三区av电影| 极品销魂美女一区二区三区| 99久久精品99国产精品| 91精品一区二区三区久久久久久| 国产性天天综合网| 亚洲一线二线三线视频| 国产精品一区二区三区网站| 在线视频中文字幕一区二区| 精品电影一区二区| 亚洲午夜久久久久中文字幕久| 久久91精品国产91久久小草| 一本大道久久精品懂色aⅴ| 日韩一区二区视频在线观看| 亚洲欧洲日产国产综合网| 免费的国产精品| 色综合久久久久久久| 久久一区二区视频| 亚洲成人第一页| 99在线热播精品免费| 日韩欧美一区二区在线视频| 亚洲乱码一区二区三区在线观看| 久草在线在线精品观看| 欧洲亚洲精品在线| 国产精品毛片久久久久久久| 免费高清在线一区| 欧美日韩中文字幕一区二区| 中文字幕成人av| 精品一二三四在线| 91精品国产综合久久小美女 | 狠狠色狠狠色综合系列| 欧美偷拍一区二区| 国产精品乱码一区二区三区软件| 老汉av免费一区二区三区| 色嗨嗨av一区二区三区| 国产亚洲成年网址在线观看| 免费在线欧美视频| 欧美日韩亚洲另类| 一区二区欧美在线观看| 成人成人成人在线视频| 精品日本一线二线三线不卡| 午夜精品久久久久久| 在线一区二区三区| 一区精品在线播放| 夫妻av一区二区| 久久嫩草精品久久久精品| 久久激情五月婷婷| 欧美一区二区三区在| 日韩精品亚洲专区| 欧美图区在线视频| 亚洲成a人片在线不卡一二三区| 99久久免费国产| 国产精品人成在线观看免费 | 日韩中文欧美在线| 欧美日韩三级在线| 亚洲高清视频在线| 欧美老肥妇做.爰bbww视频| 亚洲成人1区2区| 在线电影欧美成精品| 石原莉奈在线亚洲三区| 欧美精品欧美精品系列| 午夜免费久久看| 欧美肥妇free| 欧美aaa在线| 精品久久久久久久久久久久久久久 | 精品伦理精品一区| 久久电影网站中文字幕| 亚洲精品一区二区三区在线观看 | 日韩一二三区不卡| 强制捆绑调教一区二区| 日韩欧美一卡二卡| 国产一区二区久久| 国产欧美一区二区精品秋霞影院| 东方欧美亚洲色图在线| 亚洲猫色日本管| 欧美日韩美女一区二区| 亚洲电影中文字幕在线观看| 欧美巨大另类极品videosbest | 在线国产亚洲欧美| 亚洲成人精品一区| 欧美变态tickling挠脚心| 国产九色sp调教91| 亚洲欧洲av色图| 欧美色视频在线观看| 老司机精品视频导航| 国产精品麻豆视频| 欧美日韩综合一区| 国产自产v一区二区三区c| 亚洲欧美综合另类在线卡通| 精品视频在线免费| 国内精品免费**视频| 中文字幕中文字幕在线一区| 在线观看www91| 久久精品国产精品亚洲精品| 中文字幕精品一区二区三区精品| 色哟哟日韩精品| 日产国产欧美视频一区精品| 久久久久久一二三区| 91日韩一区二区三区| 免费日韩伦理电影| 18成人在线观看| 日韩欧美视频一区| 99视频精品在线| 蜜桃久久久久久| 亚洲色图视频网站| 日韩一区二区在线观看| 91网站在线观看视频| 久久精品免费观看| 亚洲乱码国产乱码精品精可以看 | 亚洲国产岛国毛片在线| 欧美午夜精品久久久| 国产激情一区二区三区四区| 亚洲与欧洲av电影| 久久精品欧美日韩| 欧美日本韩国一区二区三区视频 | 日本福利一区二区| 国产经典欧美精品| 午夜精品免费在线| 亚洲视频在线观看三级| 亚洲精品一区二区三区福利| 欧美伊人久久大香线蕉综合69| 国产精品一区二区三区四区 | 亚洲一二三四久久| 欧美激情综合网| 欧美电视剧在线观看完整版| 欧美视频日韩视频在线观看| 成人激情小说乱人伦|