bool BoundingEllipsoid::intersects (math::Ray &r, bool segment, CollisionResultSet::Info& info) { math::Matrix4f transform = scale * rotation * translation; math::Matrix4f invTransform = transform.inverse(); math::Vec3f orig = invTransform * r.getOrig(); math::Vec3f ext = invTransform * r.getExt(); math::Ray tRay (orig, ext); math::Vec3f mtu; BoundingSphere bs(math::Vec3f(0, 0, 0), 1); if (!bs.intersects(tRay, segment, info)) return false; return false; }
bool BoundingEllipsoid::intersectsWhere(math::Ray& r, math::Vec3f& near, math::Vec3f& far, CollisionResultSet::Info& info) { math::Matrix4f transform = scale * rotation * translation; math::Matrix4f invTransform = transform.inverse(); math::Vec3f orig = invTransform * r.getOrig(); math::Vec3f ext = invTransform * r.getExt(); math::Ray tRay (orig, ext); math::Vec3f i1, i2; BoundingSphere bs(math::Vec3f(0, 0, 0), 1); if (!bs.intersectsWhere(tRay, i1, i2, info)) return false; near = transform * i1; far = transform * i2; return true; }
bool Surface::_hit(Ray& ray, double t0, double t1, hitRecord& rec) { if (_trans) { Ray tRay(apply(_mInv, ray.eye, 1), apply(_mInv, ray.dir, 0), ray.ref, ray.alpha, Ray::VIEW); Ray::count -= 1; bool temp = hit(tRay, t0, t1, rec); if (temp) { rec.n = apply(_mTrans, rec.n, 0); rec.n.normalize(); } return temp; } else { return hit(ray, t0, t1, rec); } }
bool SkillGoalie::execute(RobotCommand &rc) { if(_rid==-1) return false; Ray2D ballRay(_wm->ball.pos.loc,AngleDeg(_wm->ball.vel.loc.dir().degree())); Line2D lineGoal(Vector2D(-3025,-2025),Vector2D(-3025,2025)); Vector2D gdir, gloc; gdir=Vector2D(); gloc=Vector2D(); int kickerID=-1; float minDist=9000000,temp; Vector2D ballContact = ballRay.intersection(lineGoal); if(_wm->ball.pos.loc.dist2(Vector2D(-3025,175))<=640000 || _wm->ball.pos.loc.dist2(Vector2D(-3025,-175))<=640000 || (_wm->ball.pos.loc.x<=-2225 && _wm->ball.pos.loc.y<=175 && _wm->ball.pos.loc.y>=-175)) { if(ballContact.y>=-350 && ballContact.y<=350) { gloc=_wm->ball.pos.loc+_wm->ball.vel.loc.setLengthVector(90); } else { gloc=_wm->ball.pos.loc; gloc.x-=90; } gdir.x=1; gdir.y=0; } else { if(ballContact.y>=-350 && ballContact.y<=350) { gloc=ballContact-_wm->ball.vel.loc.setLengthVector(350); gdir=-_wm->ball.vel.loc; } else { for(int i=0; i<PLAYERS_MAX_NUM;i++) { if(_wm->oppRobot[i].isValid) { temp=_wm->oppRobot[i].pos.loc.dist2(_wm->ball.pos.loc); if(temp<minDist) { minDist=temp; kickerID=i; } } } if(kickerID!=-1) { if(_wm->oppRobot[kickerID].pos.dir>=-M_PI_2 && _wm->oppRobot[kickerID].pos.dir<=M_PI_2) { Vector2D rTarget,rTemp; Ray2D tRay(_wm->oppRobot[kickerID].pos.loc,AngleDeg(_wm->oppRobot[kickerID].pos.dir*AngleDeg::RAD2DEG)); minDist=100000000; for(int i=0;i<PLAYERS_MAX_NUM;i++) { rTemp=tRay.intersection(Ray2D(_wm->oppRobot[i].pos.loc,AngleDeg(_wm->oppRobot[i].vel.loc.dir().degree()))); temp=_wm->ball.pos.loc.dist2(rTemp); if(temp<minDist) { rTarget=rTemp; minDist=temp; } } gdir=(rTarget-Vector2D(-3025,0)).setLengthVector(500); gloc=Vector2D(-3025,0)+gdir; } else { Vector2D ins; Line2D l1(_wm->oppRobot[kickerID].pos.loc,AngleDeg(_wm->oppRobot[kickerID].pos.dir*AngleDeg::RAD2DEG)); ins = l1.intersection(lineGoal); if(ins.y>350) { ins.y=350; } else if(ins.y<-350) { ins.y=-350; } ins.x=-3025; gdir=(_wm->ball.pos.loc-ins).setLengthVector(500); gloc=gdir+ins; } } else { gdir=(_wm->ball.pos.loc-Vector2D(-3025,0)).setLengthVector(500); gloc=Vector2D(-3025,0)+gdir; } } } if(gloc.x<-2980) gloc.x=-2980; rc.FinalPos.loc=gloc; rc.TargetPos.loc=gloc; rc.FinalPos.dir=gdir.dir().radian(); rc.TargetPos.dir=gdir.dir().radian(); rc.Speed=1; return true; }
void TBox::SetCollider() { TGfxVec2 tRay(m_fRay_W / 2.0f, m_fRay_H / 2.0f); m_Collider.m_tSpot_LH = TGfxVec2(m_tCenter - tRay); m_Collider.m_tSpot_RD = TGfxVec2(m_tCenter + tRay); }