D3DXVECTOR3 D3DXVECTOR3Helper::RottoTarget2dplane(D3DXVECTOR3 position,D3DXVECTOR3 target)//XY PLANE{ //Create std::vector to target D3DXVECTOR3 vectorToTarget = target - position; D3DXVec3normalize(&vectorToTarget,&vectorToTarget); //creates a displacement std::vector of relative 0,0 D3DXVECTOR3 neutralDirectionalVector = D3DXVECTOR3(1,0);//set this to whatever direction your models are loaded facing //Create the angle between them if(D3DXVec3Dot(&vectorToTarget,&neutralDirectionalVector) >= 1.0f ||D3DXVec3Dot(&vectorToTarget,&neutralDirectionalVector) <= -1.0f) { float i = D3DXVec3Dot(&vectorToTarget,&neutralDirectionalVector); float j = 0; //ADDED THIS IF STATEMENT } float angle = acos(D3DXVec3Dot(&vectorToTarget,&neutralDirectionalVector)); if (target.y > position.y) { return D3DXVECTOR3(0,angle); } else { return D3DXVECTOR3(0,-angle); }}//end VecRotatetoTarget2dplane()解决方法 在可能正好/1.0的值上调用acos是危险的,因为舍入错误可能导致计算值超出此范围.
但它很容易修复 – 使用此功能:
double SafeAcos (double x) { if (x < -1.0) x = -1.0 ; else if (x > 1.0) x = 1.0 ; return acos (x) ; }总结
以上是内存溢出为你收集整理的c – 服用1.0f或-1.0f的acos是否合法?全部内容,希望文章能够帮你解决c – 服用1.0f或-1.0f的acos是否合法?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)