首页 安全技术 系统安全     /    gjkC++应用代码(碰撞问题)

gjkC++应用代码(碰撞问题)

上传者: tftnmgcx | 上传时间:2024/11/12 17:21:22 | 文件大小:50KB | 文件类型:zip
gjkC++应用代码(碰撞问题)
GJK计算碰撞代码的应用//-----------------------------------------------------------------------------//Torque3D//Copyright(C)GarageGames.com,Inc.////Thecorealgorithmsinthisfilearebasedoncodewritten//byG.vandenBergenforhisinterferencedetectionlibrary,//"SOLID2.0"//-----------------------------------------------------------------------------#include"core/dataChunker.h"#include"collision/collision.h"#include"sceneGraph/sceneObject.h"#include"collision/convex.h"#include"collision/gjk.h"//----------------------------------------------------------------------------staticF32rel_error=1E-5f;//relativeerrorinthecomputeddistancestaticF32sTolerance=1E-3f;//DistancetolerancestaticF32sEpsilon2=1E-20f;//ZerolengthvectorstaticU32sIteration=15;//Stuckinaloop?S32num_iterations=0;S32num_irregularities=0;//----------------------------------------------------------------------------GjkCollisionState::GjkCollisionState(){a=b=0;}GjkCollisionState::~GjkCollisionState(){}//----------------------------------------------------------------------------voidGjkCollisionState::swap(){Convex*t=a;a=b;b=t;CollisionStateList*l=mLista;mLista=mListb;mListb=l;v.neg();}//----------------------------------------------------------------------------voidGjkCollisionState::compute_det(){//Dotnewpointwithcurrentsetfor(inti=0,bit=1;i0)returnfalse;}}returntrue;}//----------------------------------------------------------------------------inlineboolGjkCollisionState::closest(VectorF&v){compute_det();for(ints=bits;s;--s){if((s&bits)==s){if(valid(s|last_bit)){ bits=s|last_bit;if(bits!=15) compute_vector(bits,v); returntrue;}}}if(valid(last_bit)){bits=last_bit;v=y[last];returntrue;}returnfalse;}//----------------------------------------------------------------------------inlineboolGjkCollisionState::degenerate(constVectorF&w){for(inti=0,bit=1;imState=this;mListb=CollisionStateList::alloc();mListb->mState=this;}//----------------------------------------------------------------------------voidGjkCollisionState::reset(constMatrixF&a2w,constMatrixF&b2w){VectorFzero(0,0,0),sa,sb;a2w.mulP(a->support(zero),&sa);b2w.mulP(b->support(zero),&sb);v=sa-sb;dist=v.len();}//----------------------------------------------------------------------------voidGjkCollisionState::getCollisionInfo(constMatrixF&mat,Collision*info){AssertFatal(false,"GjkCollisionState::getCollisionInfo()-Thereremainscalingproblemshere.");//ThisassumesthattheshapesdonotintersectPoint3Fpa,pb;if(bits){getClosestPoints(pa,pb);mat.mulP(pa,&info->point);b->getTransform().mulP(pb,&pa);info->normal=info->point-pa;}else{mat.mulP(p[last],&info->point);info->normal=v;}info->normal.normalize();info->object=b->getObject();}voidGjkCollisionState::getClosestPoints(Point3F&p1,Point3F&p2){F32sum=0;p1.set(0,0,0);p2.set(0,0,0);for(inti=0,bit=1;isupport(va);a2w.mulP(p[last],&sa);VectorFvb,sb;w2b.mulV(v,&vb);q[last]=b->support(vb);b2w.mulP(q[last],&sb);VectorFw=sa-sb;if(mDot(v,w)>0)returnfalse;if(degenerate(w)){++num_irregularities;returnfalse;}y[last]=w;all_bits=bits|last_bit;++num_iterations;if(!closest(v)||num_iterations>sIteration){++num_irregularities;returnfalse;}}while(bitssEpsilon2);returntrue;}F32GjkCollisionState::distance(constMatrixF&a2w,constMatrixF&b2w,constF32dontCareDist,constMatrixF*_w2a,constMatrixF*_w2b){num_iterations=0;MatrixFw2a,w2b;if(_w2a==NULL||_w2b==NULL){w2a=a2w;w2b=b2w;w2a.inverse();w2b.inverse();}else{w2a=*_w2a;w2b=*_w2b;}reset(a2w,b2w);bits=0;all_bits=0;F32mu=0;do{nextBit();VectorFva,sa;w2a.mulV(-v,&va);p[last]=a->support(va);a2w.mulP(p[last],&sa);VectorFvb,sb;w2b.mulV(v,&vb);q[last]=b->support(vb);b2w.mulP(q[last],&sb);VectorFw=sa-sb;F32nm=mDot(v,w)/dist;if(nm>mu)mu=nm;if(mu>dontCareDist)returnmu;if(mFabs(dist-mu)sIteration){++num_irregularities;returndist;}y[last]=w;all_bits=bits|last_bit;if(!closest(v)){++num_irregularities;returndist;}dist=v.len();}while(bitssTolerance);if(bits==15&&mu<=0)dist=0;returndist;} 本软件ID:2789969

文件下载

资源详情

[{"title":"(27个子文件50KB)gjkC++应用代码(碰撞问题)","children":[{"title":"collision","children":[{"title":"earlyOutPolyList.cpp <span style='color:#111;'>6.97KB</span>","children":null,"spread":false},{"title":"clippedPolyList.h <span style='color:#111;'>2.97KB</span>","children":null,"spread":false},{"title":"collision.h <span style='color:#111;'>3.71KB</span>","children":null,"spread":false},{"title":"polytope.h <span style='color:#111;'>2.02KB</span>","children":null,"spread":false},{"title":"planeExtractor.cpp <span style='color:#111;'>2.80KB</span>","children":null,"spread":false},{"title":"gjk.h <span style='color:#111;'>1.92KB</span>","children":null,"spread":false},{"title":"polyhedron.h <span style='color:#111;'>976B</span>","children":null,"spread":false},{"title":"boxConvex.cpp <span style='color:#111;'>5.32KB</span>","children":null,"spread":false},{"title":"gjk.cpp <span style='color:#111;'>9.26KB</span>","children":null,"spread":false},{"title":"extrudedPolyList.h <span style='color:#111;'>2.58KB</span>","children":null,"spread":false},{"title":"optimizedPolyList.h <span style='color:#111;'>3.42KB</span>","children":null,"spread":false},{"title":"depthSortList.cpp <span style='color:#111;'>27.65KB</span>","children":null,"spread":false},{"title":"planeExtractor.h <span style='color:#111;'>1.40KB</span>","children":null,"spread":false},{"title":"convex.cpp <span style='color:#111;'>18.47KB</span>","children":null,"spread":false},{"title":"convex.h <span style='color:#111;'>7.78KB</span>","children":null,"spread":false},{"title":"polytope.cpp <span style='color:#111;'>13.18KB</span>","children":null,"spread":false},{"title":"abstractPolyList.h <span style='color:#111;'>7.31KB</span>","children":null,"spread":false},{"title":"boxConvex.h <span style='color:#111;'>1.16KB</span>","children":null,"spread":false},{"title":"optimizedPolyList.cpp <span style='color:#111;'>7.24KB</span>","children":null,"spread":false},{"title":"earlyOutPolyList.h <span style='color:#111;'>1.99KB</span>","children":null,"spread":false},{"title":"extrudedPolyList.cpp <span style='color:#111;'>13.97KB</span>","children":null,"spread":false},{"title":"concretePolyList.h <span style='color:#111;'>1.66KB</span>","children":null,"spread":false},{"title":"clippedPolyList.cpp <span style='color:#111;'>12.14KB</span>","children":null,"spread":false},{"title":"depthSortList.h <span style='color:#111;'>3.35KB</span>","children":null,"spread":false},{"title":"abstractPolyList.cpp <span style='color:#111;'>2.36KB</span>","children":null,"spread":false},{"title":"concretePolyList.cpp <span style='color:#111;'>3.79KB</span>","children":null,"spread":false},{"title":"polyhedron.cpp <span style='color:#111;'>2.14KB</span>","children":null,"spread":false}],"spread":false}],"spread":true}]

评论信息

  • sq_wang1983:
    代码很简单,也没有优化,但是能看清楚gjk的基本逻辑,非常不错2016-05-19
  • 守钱:
    代码很简单,也没有优化,但是能看清楚gjk的基本逻辑,非常不错2016-05-19
  • u012371504:
    只有头文件和源文件,不知道怎么用。不过还是感谢分享2015-08-13
  • fatislord:
    只有头文件和源文件,不知道怎么用。不过还是感谢分享2015-08-13
  • xitele2036:
    只有头文件和源文件2014-06-05
  • LK-BPFC:
    只有头文件和源文件2014-06-05
  • dhull:
    只有头文件和源文件,不知道怎么用。不过还是感谢分享。2014-03-07
  • dhull:
    只有头文件和源文件,不知道怎么用。不过还是感谢分享。2014-03-07

免责申明

【好快吧下载】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【好快吧下载】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【好快吧下载】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,8686821#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明