Esempio n. 1
0
bool ParticleEmitter::Update() {
	if (this->transform->isSelected) { Inspector(); }

	if (enabled) {
		// Tick the emitter
		m_time += Time::deltaTime;
		m_respawnTime += Time::deltaTime;
		int numberSpawn = 10;
		// If respawn time is greater than our release delay then we spawn at 
		// least one particle so work out how many to spawn
		if (m_respawnTime > m_releaseDelay) {
			numberSpawn = (int)(m_respawnTime / m_releaseDelay);
			m_respawnTime -= (numberSpawn * m_releaseDelay);
		}
		// Spawn the required number of particles 
		for (int count = 0; count < numberSpawn; count++) {
			// Get the next free particle
			int particleIndex = GetNextFreeParticle();
			if (particleIndex >= 0) {
				// If we got a particle ID then spawn it
				AddPhysXParticle(particleIndex);
			}
		}
	}

	// Check to see if we need to release particles. They can either be too old or have hit the particle sink
	// Lock the particle buffer so we can work on it and get a pointer to read data
	PxParticleReadData* readData = particleFluid->lockParticleReadData();
	// Access particle data from PxParticleReadData was OK
	if (readData) {
		vector<PxU32> particlesToRemove; //we need to build a list of particles to remove so we can do it all in one go
		PxStrideIterator<const PxParticleFlags> flagsIt(readData->flagsBuffer);
		PxStrideIterator<const PxVec3> positionIt(readData->positionBuffer);

		for (unsigned i = 0; i < readData->validParticleRange; ++i, ++flagsIt, ++positionIt) {
			if (*flagsIt & PxParticleFlag::eVALID) {
				//if particle is either too old or has hit the sink then mark it for removal.  We can't remove it here because we buffer is locked
				if (*flagsIt & PxParticleFlag::eCOLLISION_WITH_DRAIN) {
					//mark our local copy of the particle free
					ReleaseParticle(i);
					//add to our list of particles to remove
					particlesToRemove.push_back(i);
				}
			}
		}
		// return ownership of the buffers back to the SDK
		readData->unlock();
		//if we have particles to release then pass the particles to remove to PhysX so it can release them
		if (particlesToRemove.size() > 0) {
			//create a buffer of particle indicies which we are going to remove
			PxStrideIterator<const PxU32> indexBuffer(&particlesToRemove[0]);
			//free particles from the physics system
			particleFluid->releaseParticles(particlesToRemove.size(), indexBuffer);
		}
	}

	return true;
}
Esempio n. 2
0
bool MeshCollider::Update() {
	if (this->transform && this->transform->isSelected) { Inspector(); }

	attachedRigidbody = this->gameObject->GetComponent<Rigidbody>();

	MeshRenderer* renderer = this->gameObject->GetComponent<MeshRenderer>();
	if (renderer != nullptr) {
		Bounds meshBounds = renderer->mesh.bounds;
		bounds.center = this->transform->position;
		bounds.size = this->transform->scale * meshBounds.size;
		bounds.min = bounds.center - bounds.size;
		bounds.max = bounds.center + bounds.size;
	}
	
	return true;
}
Esempio n. 3
0
bool Camera::Update() {
    aspect = (float)Window::width / (float)Window::height;

    if (Camera::current == this) {
        ImGui::Begin("Main Camera Settings");
        ImGui::Checkbox("Orthographic", &orthographic);

        if (orthographic) {
            ImGui::DragFloat("Orthographic Size", &orthographicSize);
            ImGui::DragFloat("Near Clip Plane", (float*)&orthoNear);
            ImGui::DragFloat("Far Clip Plane", (float*)&orthoFar);
        } else {
            ImGui::DragFloat("Field Of View", &fieldOfView);
            ImGui::DragFloat("Near Clip Plane", (float*)&perspNear);
            ImGui::DragFloat("Far Clip Plane", (float*)&perspFar);
        }

        ImGui::ColorEdit4("Background Color", (float*)&backgroundColor);
        ImGui::DragFloat("Mouse Sensitivity", &mouseSensitivity, 0.1f);
        ImGui::DragFloat3("Velocity", (float*)&velocity);

        ImGui::End();
    }

    if (this->transform && this->transform->isSelected) {
        Inspector();
    }

    if (initializedOldStuff) {
        oldProjectionMatrix = projectionMatrix;
        oldViewMatrix = viewMatrix;
    } else {
        oldProjectionMatrix = projectionMatrix + mat4(1);
        oldViewMatrix = viewMatrix + mat4(1);
        oldOrthographic = orthographic;
        initializedOldStuff = true;
    }

    UpdateProjection();

    if(Camera::current != this) RenderFrustum();

    return true;
}
Esempio n. 4
0
bool BoxCollider::Update() {
	if (this->transform && this->transform->isSelected) Inspector();
	
	attachedRigidbody = this->gameObject->GetComponent<Rigidbody>();

	MeshRenderer* renderer = this->gameObject->GetComponent<MeshRenderer>();
	if (renderer != nullptr) {
		Bounds meshBounds = renderer->mesh.bounds;
		bounds.center = this->transform->position;
		bounds.size = this->transform->scale * meshBounds.size;
		bounds.min = bounds.center - bounds.size;
		bounds.max = bounds.center + bounds.size;
	}

	for (int i = 0; i < 12; ++i) {
		LineSegment line = obb.Edge(i);
		Gizmos::AddLine(line.start, line.end, vec4(0, 1, 0, 1));
	}

	obb.SetFrom(bounds, *this->transform);

	return true;
}
Esempio n. 5
0
bool Rigidbody::Update() {
	if (transform && transform->isSelected) Inspector();
	return true;
}
Esempio n. 6
0
void initInspector(TetrisSim ts){
	active = Inspector(ts);
}