bool CHitSquare::CheckHitCircleLineSegment(Circle * pcircle,Segment * seg) { Segment segbuf,segbuf2; segbuf.s = seg->s; segbuf.v = pcircle->center - seg->s; segbuf2.s = seg->s + seg->v; segbuf2.v = segbuf.v - seg->v; float lenge = D3DXVec2Cross(&seg->v,&segbuf.v)/D3DXVec2Length(&seg->v); if(D3DXVec2Length(&seg->v) == 0) lenge = D3DXVec2Length(&(segbuf.v)); if(lenge < 0) lenge = -lenge; if(pcircle->halfdiameter < lenge) return false; if(D3DXVec2Dot(&segbuf.v,&seg->v)*D3DXVec2Dot(&segbuf2.v,&seg->v) <= 0) return true; else if(pcircle->halfdiameter > D3DXVec2Length(&segbuf.v )||pcircle->halfdiameter > D3DXVec2Length(&segbuf2.v )) return true; return false; }
void XViewSpline::OnMButtonDown(UINT nFlags, CPoint point) { // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다. if( m_idxSelected >= 0 ) // 관절이 선택되어 있을때 { if( m_bIK ) { for( int i = m_idxSelected; i >= 0; --i ) { JOINT *j = &m_listJoint[ i ]; D3DXVECTOR2 v0( LEN_JOINT, 0 ), v0T; D3DXVec2TransformCoord( &v0T, &v0, &j->m_mWorld ); D3DXVECTOR2 vF = D3DXVECTOR2( (float)point.x, (float)point.y ) - v0T; // 관절끝좌표에서 현재 마우스 위치로의 벡터 D3DXVec2Normalize( &j->m_vForce, &vF ); // 노말라이즈 float dot = D3DXVec2Dot( &j->m_vNormal, &j->m_vForce ); j->dot = dot; float torque = dot * 0.01f; j->m_rAngle -= torque; } } } Invalidate(0); __super::OnRButtonDown(nFlags, point); }
//============================================================================= // update // typically called once per frame // frameTime is used to regulate the speed of movement and animation //============================================================================= void TankHead::update(float frameTime) { D3DXVECTOR2 mouseLocation(input->getMouseX(), input->getMouseY()); D3DXVec2Normalize(&angleVector,(const D3DXVECTOR2*)new D3DXVECTOR2(mouseLocation.x - getCenterX(), mouseLocation.y - getCenterY())); float headAngle = acos(D3DXVec2Dot(&angleVector, &D3DXVECTOR2(0, -1))); spriteData.angle = headAngle; if (angleVector.x < 0) spriteData.angle = 2 * PI - spriteData.angle; Entity::update(frameTime); //spriteData.x += velocity.x * frameTime; //velocity.x = 0; //spriteData.y += velocity.y * frameTime; //velocity.y = 0; //// wrap around screen //if (spriteData.x > GAME_WIDTH) // if off screen right // spriteData.x = -tankHeadNS::WIDTH; // position off screen left //else if (spriteData.x < -tankHeadNS::WIDTH) // else if off screen left // spriteData.x = GAME_WIDTH; // position off screen right //if (spriteData.y < -tankHeadNS::HEIGHT) // if off screen top // spriteData.y = GAME_HEIGHT; // position off screen bottom //else if (spriteData.y > GAME_HEIGHT) // else if off screen bottom // spriteData.y = -tankHeadNS::HEIGHT; // position off screen top }
bool CObjCHAR_Collision::ReviseMonsterPosition(tagCYLINDERINFO *Cylinder) { float distance; distance = sqrtf( (m_vCurrent.x - Cylinder->m_Position.x)*(m_vCurrent.x - Cylinder->m_Position.x) + (m_vCurrent.y - Cylinder->m_Position.y)*(m_vCurrent.y - Cylinder->m_Position.y) ); if(distance < Cylinder->m_fRadius) { float dir_[3]; D3DXVECTOR2 v1,v2; D3DXVECTOR2 direction, p; float a,b,d,t; ::getModelDirectionVector(m_hNodeModel, dir_); v1 = (D3DXVECTOR2)m_vCurrent - (D3DXVECTOR2)Cylinder->m_Position; v2.x = dir_[0]; v2.y = dir_[1]; v2 /= D3DXVec2Length(&v2); direction = v1 - D3DXVec2Dot(&v1,&v2)*v2; if(D3DXVec2Length(&direction) < 0.001f) { direction.x = -v2.y; direction.y = v2.x; } direction/=D3DXVec2Length(&direction); p = (D3DXVECTOR2)m_vCurrent - (D3DXVECTOR2)Cylinder->m_Position; a= D3DXVec2Dot(&direction,&p); b= D3DXVec2Dot(&p,&p); d= Cylinder->m_fRadius * Cylinder->m_fRadius; t = -a + sqrtf(a*a+d-b); if(t<0.0f) t=0.0f; else { m_vCurrent.x += (t+5)*direction.x; m_vCurrent.y += (t+5)*direction.y; } return true; } return false; }
Line2D::Line2D(const D3DXVECTOR2 &start, const D3DXVECTOR2 &end) : start_(start), end_(end), direction_(end - start) { D3DXVec2Normalize(&direction_, &direction_); normal_.x = -direction_.y; normal_.y = direction_.x; distance_ = D3DXVec2Dot(&normal_, &start_); }
void GuiSlider::onMessage(gui::Message* message) { // anywhere onMouseUp if( message->event == gui::onMouseUp ) { if( _scrolling ) _scrolling = false; } // anywhere onMouseMove if scrolling is enabled if( _scrolling && message->event == gui::onMouseMove ) { // slider vector Flector sliding( float(_upperRect.left - _lowerRect.left), float(_upperRect.top - _lowerRect.top) ); Flector slidingN; D3DXVec2Normalize( &slidingN, &sliding ); // motion offset Flector offset( float( Gui::instance->getMouseDX() ), float( Gui::instance->getMouseDY() ) ); // motion offset in slider space Flector slidingOffset = slidingN * D3DXVec2Dot( &slidingN, &offset ); // parametric motion offset (0..1) float pSlidingOffset = D3DXVec2Length( &slidingOffset ) / D3DXVec2Length( &sliding ); if( D3DXVec2Dot( &slidingN, &offset ) < 0 ) pSlidingOffset *= -1; // final update setPosition( getPosition() + pSlidingOffset * getUpperLimit() - getLowerLimit() ); // messaging gui::Message message; message.origin = this; message.event = gui::onSlide; Gui::instance->pushMessage( &message ); } // mousedown from scroll button if( _scrollButton && message->event == gui::onMouseDown && message->origin == _scrollButton->getPanel() ) { _scrolling = true; } }
//============================================================================= // is hit line //============================================================================= bool CollisionCircle::IsHitLine(const D3DXVECTOR2& position,const D3DXVECTOR2& start,const D3DXVECTOR2& end)const { D3DXVECTOR2 vector_l = end - start; D3DXVECTOR2 vector_a = position_ - (start + position); D3DXVECTOR2 vector_b = position_ - (end + position); f32 distance = D3DXVec2CCW(&vector_l,&vector_a) / D3DXVec2Length(&vector_l); if(distance <= radius_) { if(D3DXVec2Dot(&vector_a,&vector_l) * D3DXVec2Dot(&vector_b,&vector_l) <= 0) { return true; } if(D3DXVec2Length(&vector_a) <= radius_ || D3DXVec2Length(&vector_b) <= radius_) { return true; } } return false; }
//------------------------------------- // SetBlind() //------------------------------------- void Bullet::SetBlind( Vector3 player_position, Vector3 player_rotation) { //------------------------------------- // シーン取得 Scene *scene = SceneManager::GetCurrentScene(); std::string str = SceneManager::GetCurrentSceneName(); if (str == "Game"){ Game *game = dynamic_cast<Game*>(scene); // プレイヤーから見てどの位置に当たったか計算する D3DXVECTOR2 vec = { parameter_.position_.x_ - player_position.x_, parameter_.position_.z_ - player_position.z_ }; D3DXVec2Normalize(&vec, &vec); D3DXVECTOR2 vec2 = { sinf(player_rotation.y_), cosf(player_rotation.y_) }; D3DXVec2Normalize(&vec2, &vec2); float rotato_y = atan2(D3DXVec2Dot(&vec, &vec2), (vec.x * vec2.y - vec.y * vec2.x)); float length = BLIND_LEN_MIN + float((rand() % 10)) * 0.1f * (BLIND_LEN_MAX - BLIND_LEN_MIN); float scaling = float((rand() % (BLIND_SCALING_MAX - BLIND_SCALING_MIN) + BLIND_SCALING_MIN)); float rotato_z = float((rand() % 314)) * 0.01f; //------------------------------------- // ブラインドを発生させる //------------------------------------- OBJECT_PARAMETER_DESC blind_param; blind_param.name_ = "blind"; blind_param.position_ = { SCREEN_WIDTH * 0.5f + cosf(rotato_y) * length * 1.777f, // 画面が横長分微調整する SCREEN_HEIGHT * 0.5f - sinf(rotato_y) * length, 0.0f }; blind_param.rotation_ = { 0.0f, 0.0f, rotato_z }; blind_param.scaling_ = { scaling, scaling, 0.0f }; blind_param.layer_ = LAYER_BLIND; Blind* blind = game->object_manager()->GetNoUseBlind(); if (blind != nullptr){ blind->SetBlind(blind_param); } } }
bool IT_PointLine2D(D3DXVECTOR2 A, D3DXVECTOR2 B, D3DXVECTOR2 P) { D3DXVECTOR2 AB = B - A; D3DXVec2Normalize(&AB, &AB); D3DXVECTOR2 v = P - A; D3DXVec2Normalize(&v, &v); float t = D3DXVec2Dot(&AB, &v); //RFE: try playing with the Eps value until done reaching a satisfying tone float Eps = 0.01f; if(t >= 1.0f-Eps || t <= 1.0f+Eps) return true; return false; }
float GetClosestPointOnLineSegment(const VEC2& A, const VEC2& B, const VEC2& P, VEC2& result) { VEC2 AP = P - A; //Vector from A to P VEC2 AB = B - A; //Vector from A to B float magnitudeAB = D3DXVec2LengthSq(&AB); //Magnitude of AB vector (it's length squared) float ABAPproduct = D3DXVec2Dot(&AP, &AB); //The DOT product of a_to_p and a_to_b float distance = ABAPproduct / magnitudeAB; //The normalized "distance" from a to your closest point if (distance < 0) //Check if P projection is over vectorAB result = A; else if (distance > 1) result = B; else result = A + AB * distance; return PointLineDistance(P.x, P.y, A.x, A.y, B.x, B.y); }
void CActorInstance::__HitGood(CActorInstance& rVictim) { if (rVictim.IsKnockDown()) return; if (rVictim.IsStun()) { rVictim.Die(); } else { rVictim.__Shake(100); if (!rVictim.isLock()) { float fRotRad = D3DXToRadian(GetRotation()); float fVictimRotRad = D3DXToRadian(rVictim.GetRotation()); D3DXVECTOR2 v2Normal(sin(fRotRad), cos(fRotRad)); D3DXVECTOR2 v2VictimNormal(sin(fVictimRotRad), cos(fVictimRotRad)); D3DXVec2Normalize(&v2Normal, &v2Normal); D3DXVec2Normalize(&v2VictimNormal, &v2VictimNormal); float fScalar = D3DXVec2Dot(&v2Normal, &v2VictimNormal); if (fScalar < 0.0f) { if (rVictim.InterceptOnceMotion(CRaceMotionData::NAME_DAMAGE)) rVictim.PushLoopMotion(CRaceMotionData::NAME_WAIT); } else { if (rVictim.InterceptOnceMotion(CRaceMotionData::NAME_DAMAGE_BACK)) rVictim.PushLoopMotion(CRaceMotionData::NAME_WAIT); else if (rVictim.InterceptOnceMotion(CRaceMotionData::NAME_DAMAGE)) rVictim.PushLoopMotion(CRaceMotionData::NAME_WAIT); } } } }
//============================================================================= // is hit line //============================================================================= bool CollisionPoint::IsHitLine(const D3DXVECTOR2& position,const D3DXVECTOR2& start,const D3DXVECTOR2& end)const { D3DXVECTOR2 vector_l = end - start; D3DXVECTOR2 vector_a = position_ - (start + position); D3DXVECTOR2 vector_b = position_ - (end + position); f32 cross = D3DXVec2CCW(&vector_l,&vector_a); if(cross <= 0.0001f || cross >= -0.0001f) { cross = 0.0f; } if(cross == 0.0f) { if(D3DXVec2Dot(&vector_a,&vector_l) >= 0 && D3DXVec2Length(&vector_l) >= D3DXVec2Length(&vector_a)) { return true; } } return false; }
float Line2D::Distance(const D3DXVECTOR2 &point) const { return D3DXVec2Dot(&normal_, &point) - distance_; }
void XViewSpline::FrameMove() { // 관절을 클릭한상태로 움직인다. if( m_idxSelected >= 0 ) { if( m_bIK ) { // 목표지점이 주어지면 각각의 IK알고리즘에 따라 관절들을 회전시킨다. if( m_typeIK == IK_DOT ) { for( int i = m_idxSelected; i >= 0; --i ) { JOINT *j = &m_listJoint[ i ]; D3DXVECTOR2 v0( LEN_JOINT, 0 ), v0T; D3DXVec2TransformCoord( &v0T, &v0, &j->m_mWorld ); D3DXVECTOR2 vF = D3DXVECTOR2( m_vTarget.x, m_vTarget.y ) - v0T; // 관절끝좌표에서 현재 마우스 위치로의 벡터 D3DXVec2Normalize( &j->m_vForce, &vF ); // 노말라이즈 float dot = D3DXVec2Dot( &j->m_vNormal, &j->m_vForce ); j->dot = dot; float torque = dot * 0.02f; j->m_rAngle -= torque; } } else if( m_typeIK == IK_CCD ) { // 관절의 끝에서 부터 시작 // 관절의 시작점에서 관절의 최하위관절의 끝지점을 연결하는 벡터A를 구함 // 관절의 시작점에서 목표지점까지를 연결하는 벡터B를 구함 // 벡터B - 벡터A만큼의 각도를 현재관절에 회전시킴 // 윗단계 관절로 이동 후 반복 for( int i = m_idxSelected; i >= 0; --i ) { JOINT *j = &m_listJoint[ i ]; D3DXVECTOR2 vA = m_listJoint[ m_idxSelected ].m_vEnd - j->m_vStart; // 관절의 시작점에서 관절의 최하위관절의 끝지점을 연결하는 벡터A를 구함 D3DXVECTOR2 vB = m_vTarget - j->m_vStart; // 관절의 시작점에서 목표지점까지를 연결하는 벡터B를 구함 float rA = GetAngle( vA ); // 벡터의 각도 구함 float rB = GetAngle( vB ); float rDist = rB - rA; // 두 벡터간의 각도차 if( rDist > D2R(180.f) ) rDist -= D2R(360.f); else if( rDist < D2R(-180.f) ) rDist += D2R(360.f); if( D2R(0.01f) > fabs( rDist ) ) { if( rDist > 0 ) rDist = D2R(0.01f); else if( rDist < 0 ) rDist = D2R(-0.01f); } float rOld = j->m_rAngle; j->m_rAngle += rDist; // 현재 관절에 각도차를 더함 // 각도제한 if( j->m_rAngle > D2R(45.f) ) j->m_rAngle = D2R(45.f); else if( j->m_rAngle < D2R(-45.f) ) j->m_rAngle = D2R(-45.f); UpdateMatrix( i ); } } }/* else { D3DXVECTOR2 vDist = m_vMouse - s_vPrev; // 마우스가 움직인 거리 JOINT *j = &m_listJoint[ m_idxSelected ]; if( vDist.x > 0 ) j->m_rAngle += D2R(1.f); else j->m_rAngle -= D2R(1.f); } */ // 행렬, 노말 갱신 UpdateMatrix(); } }
void CActorInstance::__HitGreate(CActorInstance& rVictim) { // DISABLE_KNOCKDOWN_ATTACK if (rVictim.IsKnockDown()) return; if (rVictim.__IsStandUpMotion()) return; // END_OF_DISABLE_KNOCKDOWN_ATTACK float fRotRad = D3DXToRadian(GetRotation()); float fVictimRotRad = D3DXToRadian(rVictim.GetRotation()); D3DXVECTOR2 v2Normal(sin(fRotRad), cos(fRotRad)); D3DXVECTOR2 v2VictimNormal(sin(fVictimRotRad), cos(fVictimRotRad)); D3DXVec2Normalize(&v2Normal, &v2Normal); D3DXVec2Normalize(&v2VictimNormal, &v2VictimNormal); float fScalar = D3DXVec2Dot(&v2Normal, &v2VictimNormal); rVictim.__Shake(100); if (rVictim.IsUsingSkill()) return; if (rVictim.IsStun()) { if (fScalar < 0.0f) rVictim.InterceptOnceMotion(CRaceMotionData::NAME_DAMAGE_FLYING); else { if (!rVictim.InterceptOnceMotion(CRaceMotionData::NAME_DAMAGE_FLYING_BACK)) rVictim.InterceptOnceMotion(CRaceMotionData::NAME_DAMAGE_FLYING); } rVictim.m_isRealDead=true; } else { if (fScalar < 0.0f) { if (rVictim.InterceptOnceMotion(CRaceMotionData::NAME_DAMAGE_FLYING)) { rVictim.PushOnceMotion(CRaceMotionData::NAME_STAND_UP); rVictim.PushLoopMotion(CRaceMotionData::NAME_WAIT); } } else { if (!rVictim.InterceptOnceMotion(CRaceMotionData::NAME_DAMAGE_FLYING_BACK)) { if (rVictim.InterceptOnceMotion(CRaceMotionData::NAME_DAMAGE_FLYING)) { rVictim.PushOnceMotion(CRaceMotionData::NAME_STAND_UP); rVictim.PushLoopMotion(CRaceMotionData::NAME_WAIT); } } else { rVictim.PushOnceMotion(CRaceMotionData::NAME_STAND_UP_BACK); rVictim.PushLoopMotion(CRaceMotionData::NAME_WAIT); } } } }
float dot(const Vec2 &v1, const Vec2 &v2) { return D3DXVec2Dot(&v1, &v2); }
float Line2D::Angle(const Line2D &line) const { return acos(D3DXVec2Dot(&direction_, &line.direction_)); }
//@} //----------------------------------------------------------------------------- /// @name 幾何ベクトルの演算 //@{ /// @copydoc psyq::geometry::vector::dot inline psyq::geometry::vector::traits<D3DXVECTOR2>::element dot( D3DXVECTOR2 const& in_left, D3DXVECTOR2 const& in_right) { return D3DXVec2Dot(&in_left, &in_right); }
int CBgDisp2::MoveTexUV( D3DXMATRIX matView ) { int i; D3DTLVERTEX* tlvptr1 = m_tlv1; D3DTLVERTEX2* tlvptr2 = m_tlv2; if( (uanime != 0.0f) || (vanime != 0.0f ) ){ for( i = 0; i < BGTLVNUM; i++ ){ tlvptr2->tu2 += uanime; tlvptr2->tv2 += vanime; tlvptr2++; } } if( isround ){ D3DXVECTOR3 vecbef;// = {0.0, 0.0, -1.0}; D3DXVECTOR3 vecaft; vecbef.x = 0.0f; vecbef.y = 0.0f; vecbef.z = -1.0f; float lx = vecbef.x; float ly = vecbef.y; float lz = vecbef.z; //!!!! 平行移動成分は、加味しない。 vecaft.x = matView._11*lx + matView._21*ly + matView._31*lz;// + matView._41; vecaft.y = matView._12*lx + matView._22*ly + matView._32*lz;// + matView._42; vecaft.z = matView._13*lx + matView._23*ly + matView._33*lz;// + matView._43; D3DXVec3Normalize( &vecaft, &vecaft ); D3DXVECTOR2 vec0; // = {0.0f, -1.0f}; D3DXVECTOR2 vec1; vec0.x = 0.0f; vec0.y = -1.0f; vec1.x = vecaft.x; vec1.y = vecaft.z; D3DXVec2Normalize( &vec1, &vec1 ); float dot; dot = D3DXVec2Dot( &vec0, &vec1 ); float rad; if( dot <= -1.0f ) dot = -1.0f; else if( dot >= 1.0f ) dot = 1.0f; rad = (float)acos( dot ); float ccw; ccw = D3DXVec2CCW( &vec0, &vec1 ); //float roty; //if( ccw >= 0.0f ){ // roty = -rad; //}else{ // roty = rad; //} float roty; if( ccw >= 0.0f ){ roty = rad; }else{ roty = -rad; } float centeru; centeru = 0.5f + roty * ( 0.5f / PI ); float usize, befu, aftu; usize = 0.4f; befu = centeru - usize; aftu = centeru + usize; //if( befu < 0.0f ) // befu += 1.0f; //if( aftu > 1.0f ) // aftu -= 1.0f; _ASSERT( BGUNUM == 3 );//!!!!!!!!!!!!!!!!! int uno, vno; int tlvno = 0; for( vno = 0; vno < BGVNUM; vno++ ){ for( uno = 0; uno < BGUNUM; uno++ ){ if( uno == 0 ){ m_tlv1[tlvno].tu = befu; m_tlv2[tlvno].tu1 = befu; }else if( uno == 1 ){ m_tlv1[tlvno].tu = centeru; m_tlv2[tlvno].tu1 = centeru; }else if( uno == 2 ){ m_tlv1[tlvno].tu = aftu; m_tlv2[tlvno].tu1 = aftu; }else{ _ASSERT( 0 ); m_tlv1[tlvno].tu = 0.0f; m_tlv2[tlvno].tu1 = 0.0f; } tlvno++; } } } return 0; }
float float2::Dot(const float2& rvalue) { D3DXVECTOR2 a(x,y); D3DXVECTOR2 b(rvalue.x,rvalue.y); return D3DXVec2Dot(&a,&b); }