bool Tracer::Update(float dt) { if (length < 16) return false; if(!firstUpdate) { curDistance += dt * velocity; if(curDistance > length) { return false; } } firstUpdate = false; //Chameleon: .kv6 tracers if ((int)opt_tracers == 2) { matrix = Matrix4::Translate(dir * velocity * dt) * matrix; } //Chameleon: play sound if tracer after coming inbound starts going outbound. //aka: when distance to tracer starts increasing after having decreased. if (player) { Vector3 pos1 = startPos + dir * curDistance; //if tracer is heading outbound if ((pos1 - player->GetPosition()).GetLength() > flyByDist && flyByDist > 0 && flyByDist * 4 < client->soundDistance) { IAudioDevice *audio = client->GetAudioDevice(); AudioParam param = AudioParam(); param.volume = 150.f / flyByDist; param.referenceDistance = (flyByDist+10)/5.f; param.pitch = 0.8f + GetRandom()*0.4f; audio->Play(snd, pos1, param); flyByDist = -1; } else if (flyByDist != -1) { flyByDist = (pos1 - player->GetEye()).GetLength(); } } return true; }
bool GunCasing::Update(float dt) { if(onGround){ groundTime += dt; if(groundTime > 2.f){ return false; } GameMap *map = client->GetWorld()->GetMap(); if(!map->ClipWorld(groundPos.x, groundPos.y, groundPos.z)){ return false; } }else{ Matrix4 lastMat = matrix; matrix = matrix * Matrix4::Rotate(rotAxis, dt * rotSpeed); matrix = Matrix4::Translate(vel * dt) * matrix; vel.z += dt * 32.f; IntVector3 lp = matrix.GetOrigin().Floor(); GameMap *m = client->GetWorld()->GetMap(); if(lp.z >= 63){ // dropped into water float dist = (client->GetLastSceneDef().viewOrigin - matrix.GetOrigin()).GetPoweredLength(); if(waterSound){ if(dist < 40.f * 40.f && !client->IsMuted()){ IAudioDevice *dev = client->GetAudioDevice(); AudioParam param; param.referenceDistance = .6f; param.pitch = .9f + GetRandom() * .2f; dev->Play(waterSound, lastMat.GetOrigin(), param); } waterSound = NULL; } if(dist < 40.f * 40.f){ int splats = rand() % 3; Handle<IImage> img = client->GetRenderer()->RegisterImage("Gfx/White.tga"); Vector4 col = {1, 1, 1, 0.8f}; Vector3 pt = matrix.GetOrigin(); pt.z = 62.99f; for(int i = 0; i < splats; i++){ ParticleSpriteEntity *ent = new ParticleSpriteEntity(client, img, col); ent->SetTrajectory(pt, MakeVector3(GetRandom()-GetRandom(), GetRandom()-GetRandom(), -GetRandom()) * 2.f, 1.f, .4f); ent->SetRotation(GetRandom() * (float)M_PI * 2.f); ent->SetRadius(0.1f + GetRandom()*GetRandom()*0.1f); ent->SetLifeTime(2.f, 0.f, 1.f); client->AddLocalEntity(ent); } } return false; } if(m->ClipWorld(lp.x,lp.y,lp.z)){ // hit a wall IntVector3 lp2 = lastMat.GetOrigin().Floor(); if (lp.z != lp2.z && ((lp.x == lp2.x && lp.y == lp2.y) || !m->ClipWorld(lp.x, lp.y, lp2.z))){ vel.z = -vel.z; if(lp2.z < lp.z){ // ground hit if(vel.GetLength() < .5f + dt * 100.f && !dropSound){ // stick to ground onGround = true; groundPos = lp; // move to surface float z = matrix.GetOrigin().z; float shift = z - floorf(z); matrix = Matrix4::Translate(0,0,-shift) * matrix; // lie Vector3 v1 = matrix.GetAxis(0); Vector3 v2 = matrix.GetAxis(1); v1.z = 0; v2.z = 0; v1 = v1.Normalize(); v2 = v2.Normalize(); Vector3 v3 = Vector3::Cross(v1, v2).Normalize(); v1 = Vector3::Cross(v2, v3).Normalize(); matrix = Matrix4::FromAxis(v1, v2, v3, matrix.GetOrigin()); }else{ if(dropSound){ float dist = (client->GetLastSceneDef().viewOrigin - matrix.GetOrigin()).GetPoweredLength(); if(dist < 40.f * 40.f && !client->IsMuted()){ IAudioDevice *dev = client->GetAudioDevice(); AudioParam param; param.referenceDistance = .6f; dev->Play(dropSound, lastMat.GetOrigin(), param); } dropSound = NULL; } } } }else if(lp.x != lp2.x && ((lp.y == lp2.y && lp.z == lp2.z) || !m->ClipWorld(lp2.x, lp.y, lp.z))) vel.x = -vel.x; else if(lp.y != lp2.y && ((lp.x == lp2.x && lp.z == lp2.z) || !m->ClipWorld(lp.x, lp2.y, lp.z))) vel.y = -vel.y; else return false; if(!onGround){ matrix = lastMat; vel *= .2f; rotAxis = RandomAxis(); Vector3 r; r.x = GetRandom() - GetRandom(); r.y = GetRandom() - GetRandom(); r.z = GetRandom() - GetRandom(); vel += r * 0.1f; rotSpeed *= .2f; } } } return true; }