//レイとモデルのあたり判定 CollisionParameter Actor::RayModelStep(const Actor& other)const{ Vector3 pos = RCMatrix4::getPosition(parameter.matrix) + RCMatrix4::getUp(parameter.matrix) * 3.0f; Vector3 rad = RCVector3::normalize(parameter.moveVec); Vector3 start = pos + rad * 0.5f; Vector3 end = pos - rad * 0.5f; //Graphic::GetInstance().DrawLine(start, end); CollisionParameter colpara = ModelRay(other.parameter.matrix, other.parameter.octId, start, end); Vector3 nor = colpara.colNormal; if (!colpara.colFlag)return colpara; while (true){ pos = pos - rad * 0.1f; start = pos + rad * 0.5f; end = pos - rad * 0.5f; colpara = ModelRay(other.parameter.matrix, other.parameter.octId, start, end); if (!colpara.colFlag){ colpara.colFlag = true; colpara.id = COL_ID::RAY_MODEL_STEP_COLL; colpara.colPos = pos - rad * 0.3f; colpara.colNormal = nor; break; } } return colpara; }
//レイとモデルのあたり判定 CollisionParameter Actor::RayModel(const Actor& other)const{ Vector3 pos = RCMatrix4::getPosition(parameter.matrix); float rad = parameter.radius; Vector3 down = -RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 end = pos + down* rad; //Graphic::GetInstance().DrawLine(pos, end); return ModelRay(other.parameter.matrix, other.parameter.octId, pos, end); }
void Thread::Update(float frameTime){ //始点と終点の距離が一定以下かつ、ショット中でなければ死亡 if (RCVector3::length(threadParam.startPosition - threadParam.currentEndPosition) < 0.3f && !IsShot()) parameter.isDead = true; //糸発射処理 if (IsShot()){ ThreadShot(frameTime); //shotSpeed = THREAD_SPEED; //当たり判定のセット world.SetCollideSelect(this->shared_from_this(),parameter.id == ACTOR_ID::PLAYER_THREAD_ACTOR ? ACTOR_ID::ENEMY_THREADWEB_ACTOR : ACTOR_ID::PLAYER_THREADWEB_ACTOR, COL_ID::TRIANGLE_LINE_T_COLL); } CollisionParameter col_; if (!IsShot()){ col_ = ModelRay(*stage._Get()->ReturnMat(), OCT_ID::STAGE_OCT, threadParam.startPosition + threadParam.endNormal * 0.1f, threadParam.endPosition + threadParam.startNormal * 0.1f); if (col_.colFlag){ threadParam.endPosition = col_.colPos; threadParam.currentEndPosition = col_.colPos; } } if (dangle){ threadParam.startNormal = RCVector3::normalize(threadParam.startPosition - threadParam.endPosition); threadParam.endNormal = RCVector3::normalize(threadParam.endPosition - threadParam.startPosition); } else{ col_ = ModelRay(*stage._Get()->ReturnMat(), OCT_ID::STAGE_OCT, threadParam.endPosition + threadParam.startNormal * 0.1f, threadParam.startPosition + threadParam.endNormal * 0.1f); if (col_.colFlag){ threadParam.startPosition = col_.colPos; } } color = vector3(1, 0.5f, 0.5f); if (parameter.id == ACTOR_ID::ENEMY_THREAD_ACTOR)color = vector3(0.5f, 0.5f, 1); if (selectThread)color = vector3(1, 1, 1); selectThread = false; if (RCVector3::length(threadParam.startPosition - threadParam.endPosition) < 2.0f && !dangle){ parameter.isDead = true; } }
Thread::Thread(IWorld& world_, std::weak_ptr<Player> player_, std::weak_ptr<Stage> stage_, CAMERA_ID cID, bool startPosGroundTouch_, int playerNum_) :Actor(world_), player(player_), stage(stage_), playerNum(playerNum_){ //各種パラメーターに値をセット parameter.isDead = false; threadParam.startPosition = RCMatrix4::getPosition(*player._Get()->ReturnMat()); threadParam.currentEndPosition = threadParam.startPosition; threadParam.startPosIsGroundTouch = startPosGroundTouch_; isRewind = false; isGoingEnd = false; goingVec = vector3(0, 0, 0); rewindSpeed = 12.0f; isShot = true; shotSpeed = THREAD_SPEED; threadHit = false; rootActor = player._Get()->GetParameter().id; if (rootActor == ACTOR_ID::PLAYER_ACTOR) parameter.id = ACTOR_ID::PLAYER_THREAD_ACTOR; else parameter.id = ACTOR_ID::ENEMY_THREAD_ACTOR; //糸の発射 Vector3 eye = Device::GetInstance().GetCamera(cID)->CameraParam()->Eye; Vector3 target = Device::GetInstance().GetCamera(cID)->CameraParam()->Target; Vector3 vec =RCVector3::normalize(target - eye); //カメラからモデルへのヒット地点へ向けた判定 CollisionParameter col = ModelRay(*stage._Get()->ReturnMat(), OCT_ID::STAGE_OCT, eye,eye + vec * 10000.0f); threadParam.endPosition = col.colPos; if (col.colFlag){ ////プレイヤーからヒット地点へ向けた判定 //CollisionParameter col_ = ModelRay(*stage._Get()->ReturnMat(), OCT_ID::STAGE_OCT, threadParam.startPosition + RCVector3::normalize(RCMatrix4::getUp(*player._Get()->ReturnMat())) * 0.1f, col.colPos); // //threadParam.endPosition = col_.colPos; } else{ parameter.isDead = true; } threadParam.startNormal = RCVector3::normalize(threadParam.startPosition - threadParam.endPosition); threadParam.endNormal = RCVector3::normalize(threadParam.endPosition - threadParam.startPosition); dangle = false; selectThread = false; AddThreadWebInit(); }
ThreadWeb::ThreadWeb(IWorld& world, std::shared_ptr<Thread> parent1, std::shared_ptr<Thread> parent2) :Actor(world), mParent1(parent1), mParent2(parent2){ parameter.id = ACTOR_ID::PLAYER_THREADWEB_ACTOR; if (parent1->GetRootActor() != ACTOR_ID::PLAYER_ACTOR) parameter.id = ACTOR_ID::ENEMY_THREADWEB_ACTOR; parameter.isDead = false; hitCount = 0; mWebParamater = { mParent1._Get()->GetThreadParameter().startPosition, mParent1._Get()->GetThreadParameter().endPosition, mParent2._Get()->GetThreadParameter().endPosition }; mWebThreads.clear(); mDivide = 20; //蜘蛛の巣の間に敷く糸の座標を計算し格納 WebThreadsCalc(); float size2 = 3.0f; Matrix4 stageMatrix = RCMatrix4::matrix( vector3(size2, size2, size2), 0.0f, 0, 0.0f, vector3(-1, -2.0f, 0)); for (int i = 0; i < mDivide * 2; i += 2) { CollisionParameter cp = ModelRay(stageMatrix, OCT_ID::STAGE_OCT, mWebThreads[i], mWebThreads[i + 1]); if (cp.colFlag){ mWebParamater.b = mWebThreads[i-2]; mWebParamater.c = mWebThreads[i-2 + 1]; break; } } mWebThreads.clear(); //蜘蛛の巣の間に敷く糸の座標を計算し格納 WebThreadsCalc(); selectThreadWeb = false; }
//レイとモデルのあたり判定(蜘蛛版) CollisionParameter Actor::RayModelNaturalTest(Vector3 pos_)const{ CollisionParameter colpara; colpara.colFlag = false; colpara.colPos = vector3(0, 0, 0); colpara.colNormal = vector3(0, 1, 0); float downVec = 2.0f; Vector3 down = -RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 up = RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)) * 0.3f; Vector3 pos = pos_ + up; Vector3 end = down * downVec + pos; float len = RCVector3::length(end - pos); float size2 = 3.0f; Matrix4 stageMat = RCMatrix4::matrix( vector3(size2, size2, size2), 0.0f, 0, 0.0f, vector3(-1, -2.0f, 0)); colpara = ModelRay(stageMat, OCT_ID::STAGE_OCT, pos, end); if (colpara.colFlag){ float zure = 0.2f; float rad = 0.45f; Vector3 down1 = -RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 up1 = RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 pos1 = pos_ + RCVector3::normalize(RCMatrix4::getLeft(parameter.matrix)) * 1 * rad + up; Vector3 end1 = pos1 + down1 * downVec + RCVector3::normalize(pos1 - pos) * zure; float len1 = RCVector3::length(end1 - pos); CollisionParameter colpara1 = ModelRay(stageMat, OCT_ID::STAGE_OCT, pos1, end1); Vector3 down2 = -RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 up2 = RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 pos2 = pos_ - RCVector3::normalize(RCMatrix4::getLeft(parameter.matrix)) * 1 * rad + up; Vector3 end2 = pos2 + down2 * downVec + RCVector3::normalize(pos2 - pos) * zure; float len2 = RCVector3::length(end2 - pos); CollisionParameter colpara2 = ModelRay(stageMat, OCT_ID::STAGE_OCT, pos2, end2); Vector3 down3 = -RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 up3 = RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 pos3 = pos_ + RCVector3::normalize(RCMatrix4::getFront(parameter.matrix)) * 1 * rad + up; Vector3 end3 = pos3 + down3 * downVec + RCVector3::normalize(pos3 - pos) * zure; float len3 = RCVector3::length(end3 - pos); CollisionParameter colpara3 = ModelRay(stageMat, OCT_ID::STAGE_OCT, pos3, end3); Vector3 down4 = -RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 up4 = RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 pos4 = pos_ - RCVector3::normalize(RCMatrix4::getFront(parameter.matrix)) * 1 * rad + up; Vector3 end4 = pos4 + down4 * downVec + RCVector3::normalize(pos4 - pos) * zure; float len4 = RCVector3::length(end4 - pos); CollisionParameter colpara4 = ModelRay(stageMat, OCT_ID::STAGE_OCT, pos4, end4); if (Device::GetInstance().GetInput()->KeyDown(INPUTKEY::KEY_R)){ /*Graphic::GetInstance().DrawLine(pos, end); Graphic::GetInstance().DrawLine(pos1, end1); Graphic::GetInstance().DrawLine(pos2, end2); Graphic::GetInstance().DrawLine(pos3, end3); Graphic::GetInstance().DrawLine(pos4, end4);*/ } if (!colpara1.colFlag || !colpara2.colFlag || !colpara3.colFlag || !colpara4.colFlag){ colpara.id = COL_ID::RAY_MODEL_NATURAL_COLL; return colpara; } Vector3 centerLeft = RCVector3::lerp(colpara1.colPos, colpara2.colPos, 0.5f); Vector3 centerFront = RCVector3::lerp(colpara3.colPos, colpara4.colPos, 0.5f); Vector3 dummyHitPos; down = (down + pos_); if (RCVector3::length(centerFront - down) >= RCVector3::length(centerLeft - down)){ dummyHitPos = centerFront; } else dummyHitPos = centerLeft; if (RCVector3::length(colpara.colPos - down) >= RCVector3::length(dummyHitPos - down)){ dummyHitPos = colpara.colPos; } colpara.colPos = dummyHitPos; Vector3 left = RCVector3::normalize(colpara1.colPos - colpara2.colPos); Vector3 front = RCVector3::normalize(colpara3.colPos - colpara4.colPos); colpara.colNormal = -RCVector3::cross(left, front); } colpara.id = COL_ID::RAY_MODEL_NATURAL_COLL; return colpara; }