void ParticleEmitter3D::PrepareEmitterParameters(Particle * particle, float32 velocity, int32 emitIndex) { Vector3 tempPosition = Vector3(); Matrix4 * worldTransformPtr = GetWorldTransformPtr(); Matrix3 rotationMatrix; rotationMatrix.Identity(); if(worldTransformPtr) { tempPosition = worldTransformPtr->GetTranslationVector(); rotationMatrix = Matrix3(*worldTransformPtr);; } //Vector3 tempPosition = particlesFollow ? Vector3() : position; if (emitterType == EMITTER_POINT) { particle->position = tempPosition; } else if (emitterType == EMITTER_RECT) { float32 rand05_x = (float32)Random::Instance()->RandFloat() - 0.5f; // [-0.5f, 0.5f] float32 rand05_y = (float32)Random::Instance()->RandFloat() - 0.5f; // [-0.5f, 0.5f] float32 rand05_z = (float32)Random::Instance()->RandFloat() - 0.5f; // [-0.5f, 0.5f] Vector3 lineDirection(0, 0, 0); if(size) lineDirection = Vector3(size->GetValue(time).x * rand05_x, size->GetValue(time).y * rand05_y, size->GetValue(time).z * rand05_z); //particle->position = tempPosition + lineDirection; particle->position = tempPosition + TransformPerserveLength(lineDirection, rotationMatrix); } else if ((emitterType == EMITTER_ONCIRCLE_VOLUME) || (emitterType == EMITTER_ONCIRCLE_EDGES)) { CalculateParticlePositionForCircle(particle, tempPosition, rotationMatrix); } if (emitterType == EMITTER_SHOCKWAVE) { // For "Shockwave" emitters the calculation is different. PrepareEmitterParametersShockwave(particle, velocity, emitIndex, tempPosition, rotationMatrix); } else { PrepareEmitterParametersGeneric(particle, velocity, emitIndex, tempPosition, rotationMatrix); } if(worldTransformPtr) { Matrix4 newTransform = *worldTransformPtr; newTransform._30 = newTransform._31 = newTransform._32 = 0; float32 speedLength = particle->speed.Length(); particle->speed = particle->speed*newTransform; float32 speedLengthAfter = particle->speed.Length(); if (speedLengthAfter) particle->speed*=speedLength/speedLengthAfter; } }
void SoundUpdateSystem::ImmediateEvent(Entity * entity, uint32 event) { if (event == EventSystem::WORLD_TRANSFORM_CHANGED) { Matrix4 * worldTransformPointer = ((TransformComponent*)entity->GetComponent(Component::TRANSFORM_COMPONENT))->GetWorldTransformPtr(); Vector3 translation = worldTransformPointer->GetTranslationVector(); SoundEvent * sEvent = ((SoundComponent *)entity->GetComponent(Component::SOUND_COMPONENT))->GetSoundEvent(); sEvent->SetPosition(translation); } if (event == EventSystem::SOUND_CHANGED) { SoundComponent * soundComponent = (SoundComponent *)entity->GetComponent(Component::SOUND_COMPONENT); SoundEvent * sEvent = SoundSystem::Instance()->CreateSoundEvent(soundComponent->GetEventName()); soundComponent->SetSoundEvent(sEvent); SafeRelease(sEvent); } }
void EditorBodyControl::UpdateArrowsNode(Entity* node) { ArrowsNode* arrowsNode = GetArrowsNode(false); if (node && arrowsNode) { if (node == arrowsNode) { arrowsNode->SetVisible(false); return; } Matrix4 nodeWT = node->GetWorldTransform(); Matrix4 arrowsNodeTransform; arrowsNodeTransform.CreateTranslation(nodeWT.GetTranslationVector()); arrowsNode->SetLocalTransform(arrowsNodeTransform); arrowsNode->SetVisible(true); arrowsNode->SetActive(InModificationMode()); } }
void ParticleEmitter3D::PrepareEmitterParameters(Particle * particle, float32 velocity, int32 emitIndex) { Vector3 tempPosition = Vector3(); Matrix4 * worldTransformPtr = GetWorldTransformPtr(); if(worldTransformPtr) { tempPosition = worldTransformPtr->GetTranslationVector(); } //Vector3 tempPosition = particlesFollow ? Vector3() : position; if (emitterType == EMITTER_POINT) { particle->position = tempPosition; } else if (emitterType == EMITTER_LINE) { // TODO: add emitter angle support float32 rand05 = (float32)Random::Instance()->RandFloat() - 0.5f; // [-0.5f, 0.5f] Vector3 lineDirection(0, 0, 0); if(size) lineDirection = size->GetValue(time)*rand05; particle->position = tempPosition + lineDirection; } else if (emitterType == EMITTER_RECT) { // TODO: add emitter angle support float32 rand05_x = (float32)Random::Instance()->RandFloat() - 0.5f; // [-0.5f, 0.5f] float32 rand05_y = (float32)Random::Instance()->RandFloat() - 0.5f; // [-0.5f, 0.5f] float32 rand05_z = (float32)Random::Instance()->RandFloat() - 0.5f; // [-0.5f, 0.5f] Vector3 lineDirection(0, 0, 0); if(size) lineDirection = Vector3(size->GetValue(time).x * rand05_x, size->GetValue(time).y * rand05_y, size->GetValue(time).z * rand05_z); particle->position = tempPosition + lineDirection; } else if (emitterType == EMITTER_ONCIRCLE) { // here just set particle position particle->position = tempPosition; } Vector3 vel = Vector3(1.0f, 0.0f, 0.0f); if(emissionVector) { vel = emissionVector->GetValue(0); vel = vel*rotationMatrix; } Vector3 rotVect(0, 0, 1); float32 phi = PI*2*(float32)Random::Instance()->RandFloat(); if(vel.x != 0) { rotVect.y = sinf(phi); rotVect.z = cosf(phi); rotVect.x = - rotVect.y*vel.y/vel.x - rotVect.z*vel.z/vel.x; } else if(vel.y != 0) { rotVect.x = cosf(phi); rotVect.z = sinf(phi); rotVect.y = - rotVect.z*vel.z/vel.y; } else if(vel.z != 0) { rotVect.x = cosf(phi); rotVect.y = sinf(phi); rotVect.z = 0; } rotVect.Normalize(); float32 range = 0; if(emissionRange) range = DegToRad(emissionRange->GetValue(time) + angle); float32 rand05 = (float32)Random::Instance()->RandFloat() - 0.5f; Vector3 q_v(rotVect*sinf(range*rand05/2)); float32 q_w = cosf(range*rand05/2); Vector3 q1_v(q_v); float32 q1_w = -q_w; q1_v /= (q_v.SquareLength() + q_w*q_w); q1_w /= (q_v.SquareLength() + q_w*q_w); Vector3 v_v(vel); Vector3 qv_v = q_v.CrossProduct(v_v) + q_w*v_v; float32 qv_w = - q_v.DotProduct(v_v); Vector3 qvq1_v = qv_v.CrossProduct(q1_v) + qv_w*q1_v + q1_w*qv_v; Vector3 speed = qvq1_v * velocity; particle->speed = speed.Length(); particle->direction = speed/particle->speed; if (particle->direction.x <= EPSILON && particle->direction.x >= -EPSILON) particle->direction.x = 0.f; if (particle->direction.y <= EPSILON && particle->direction.y >= -EPSILON) particle->direction.y = 0.f; if (particle->direction.z <= EPSILON && particle->direction.z >= -EPSILON) particle->direction.z = 0.f; if (emitterType == EMITTER_ONCIRCLE) { qvq1_v.Normalize(); if(radius) particle->position += qvq1_v * radius->GetValue(time); } particle->angle = atanf(particle->direction.z/particle->direction.x); if(worldTransformPtr) { Matrix4 newTransform = *worldTransformPtr; newTransform._30 = newTransform._31 = newTransform._32 = 0; particle->direction = particle->direction*newTransform; } }