use of net.drewke.tdme.math.Matrix4x4 in project tdme by andreasdr.
the class Sphere method fromBoundingVolumeWithTransformations.
/*
* (non-Javadoc)
* @see net.drewke.tdme.primitives.BoundingVolume#fromBoundingVolumeWithTransformations(net.drewke.tdme.primitives.BoundingVolume, net.drewke.tdme.engine.Transformations)
*/
public void fromBoundingVolumeWithTransformations(BoundingVolume original, Transformations transformations) {
// check for same type of original
if (original instanceof Sphere == false) {
System.out.println("Sphere::fromBoundingVolumeWithTransformations(): original is not of same type");
return;
}
//
Sphere sphere = (Sphere) original;
//
Matrix4x4 transformationsMatrix = transformations.getTransformationsMatrix();
// apply translations
// translate center
transformationsMatrix.multiply(sphere.center, center);
// note:
// sphere radius can only be scaled the same on all axes
// thats why its enough to only take x axis to determine scaling
axis.set(sphere.center).addX(sphere.radius);
transformationsMatrix.multiply(axis, axis);
radius = axis.sub(center).computeLength();
}
use of net.drewke.tdme.math.Matrix4x4 in project tdme by andreasdr.
the class Triangle method fromBoundingVolumeWithTransformations.
/*
* (non-Javadoc)
* @see net.drewke.tdme.primitives.BoundingVolume#fromBoundingVolumeWithTransformations(net.drewke.tdme.primitives.BoundingVolume, net.drewke.tdme.engine.Transformations)
*/
public void fromBoundingVolumeWithTransformations(BoundingVolume original, Transformations transformations) {
// check for same type of original
if (original instanceof Triangle == false) {
System.out.println("Triangle::fromBoundingVolumeWithTransformations(): original is not of same type");
return;
}
//
Triangle triangle = (Triangle) original;
Matrix4x4 transformationsMatrix = transformations.getTransformationsMatrix();
for (int i = 0; i < 3; i++) {
transformationsMatrix.multiply(triangle.vertices[i], vertices[i]);
}
//
update();
}
use of net.drewke.tdme.math.Matrix4x4 in project tdme by andreasdr.
the class PointsParticleSystemEntityInternal method updateParticles.
/*
* (non-Javadoc)
* @see net.drewke.tdme.engine.subsystems.particlesystem.ParticleSystemEntity#update(net.drewke.tdme.engine.Engine)
*/
public void updateParticles() {
if (enabled == false || active == false)
return;
// bounding box transformed min, max xyz
float[] bbMinXYZ = boundingBoxTransformed.getMin().getArray();
float[] bbMaxXYZ = boundingBoxTransformed.getMax().getArray();
//
boolean haveBoundingBox = false;
//
float distanceFromCamera;
Matrix4x4 modelViewMatrix = renderer.getModelViewMatrix();
// compute distance from camera
distanceFromCamera = -point.getZ();
// process particles
pointsRenderPool.reset();
int activeParticles = 0;
long timeDelta = engine.getTiming().getDeltaTime();
for (int i = 0; i < particles.length; i++) {
Particle particle = particles[i];
if (particle.active == false)
continue;
// life time
particle.lifeTimeCurrent += timeDelta;
// crop to max life time
if (particle.lifeTimeCurrent >= particle.lifeTimeMax) {
particle.active = false;
continue;
}
// add gravity if our particle have a noticeable mass
if (particle.mass > MathTools.EPSILON)
particle.velocity.subY(0.5f * MathTools.g * (float) timeDelta / 1000f);
// TODO:
// maybe take air resistance into account like a huge paper needs more time to fall than a sphere of paper
// or heat for smoke or fire, whereas having no mass for those particles works around this problem for now
// translation
particle.position.add(velocityForTime.set(particle.velocity).scale((float) timeDelta / 1000f));
// color
float[] color = particle.color.getArray();
float[] colorAdd = particle.colorAdd.getArray();
color[0] += colorAdd[0] * (float) timeDelta;
color[1] += colorAdd[1] * (float) timeDelta;
color[2] += colorAdd[2] * (float) timeDelta;
color[3] += colorAdd[3] * (float) timeDelta;
// transform particle position to camera space
modelViewMatrix.multiply(particle.position, point);
// check for collision
if (doCollisionTests == true) {
for (Entity entity : engine.getPartition().getObjectsNearTo(particle.position)) {
// skip on our self
if (entity == this)
continue;
// skip on other particle systems
if (entity instanceof ParticleSystemEntity)
continue;
// do we have a collision?
if (entity.getBoundingBoxTransformed().containsPoint(particle.position)) {
particle.active = false;
continue;
}
}
}
//
activeParticles++;
// compute distance from camera
distanceFromCamera = -point.getZ();
// set up bounding box
float[] positionXYZ = particle.position.getArray();
if (haveBoundingBox == false) {
System.arraycopy(positionXYZ, 0, bbMinXYZ, 0, 3);
System.arraycopy(positionXYZ, 0, bbMaxXYZ, 0, 3);
haveBoundingBox = true;
} else {
if (positionXYZ[0] < bbMinXYZ[0])
bbMinXYZ[0] = positionXYZ[0];
if (positionXYZ[1] < bbMinXYZ[1])
bbMinXYZ[1] = positionXYZ[1];
if (positionXYZ[2] < bbMinXYZ[2])
bbMinXYZ[2] = positionXYZ[2];
if (positionXYZ[0] > bbMaxXYZ[0])
bbMaxXYZ[0] = positionXYZ[0];
if (positionXYZ[1] > bbMaxXYZ[1])
bbMaxXYZ[1] = positionXYZ[1];
if (positionXYZ[2] > bbMaxXYZ[2])
bbMaxXYZ[2] = positionXYZ[2];
}
//
pointsRenderPool.addPoint(point, particle.color, distanceFromCamera);
}
// auto disable particle system if no more active particles
if (activeParticles == 0) {
active = false;
return;
}
// scale a bit up to make picking work better
boundingBoxTransformed.getMin().sub(0.1f);
boundingBoxTransformed.getMax().add(0.1f);
// compute bounding boxes
boundingBoxTransformed.update();
boundingBox.fromBoundingVolumeWithTransformations(boundingBoxTransformed, inverseTransformation);
}
use of net.drewke.tdme.math.Matrix4x4 in project tdme by andreasdr.
the class OrientedBoundingBox method fromBoundingVolumeWithTransformations.
/*
* (non-Javadoc)
* @see net.drewke.tdme.primitives.BoundingVolume#fromBoundingVolumeWithTransformations(net.drewke.tdme.primitives.BoundingVolume, net.drewke.tdme.engine.Transformations)
*/
public void fromBoundingVolumeWithTransformations(BoundingVolume original, Transformations transformations) {
// check for same type of original
if (original instanceof OrientedBoundingBox == false) {
System.out.println("OrientedBoundingBox::fromBoundingVolumeWithTransformations(): original is not of same type");
return;
}
//
OrientedBoundingBox obb = (OrientedBoundingBox) original;
//
Matrix4x4 transformationsMatrix = transformations.getTransformationsMatrix();
// apply rotation, scale, translation
transformationsMatrix.multiply(obb.center, center);
// apply transformations rotation + scale to axis
transformationsMatrix.multiplyNoTranslation(obb.axes[0], axisTransformed[0]);
transformationsMatrix.multiplyNoTranslation(obb.axes[1], axisTransformed[1]);
transformationsMatrix.multiplyNoTranslation(obb.axes[2], axisTransformed[2]);
// set up axes
axes[0].set(axisTransformed[0]).normalize();
axes[1].set(axisTransformed[1]).normalize();
axes[2].set(axisTransformed[2]).normalize();
// apply scale to half extension
halfExtension.set(obb.halfExtension);
halfExtension.scale(scale.set(axisTransformed[0].computeLength(), axisTransformed[1].computeLength(), axisTransformed[2].computeLength()));
// compute vertices
update();
}
use of net.drewke.tdme.math.Matrix4x4 in project tdme by andreasdr.
the class ShadowMap method computeDepthBiasMVPMatrix.
/**
* Computes shadow texture matrix and stores it
* @param gl
*/
protected void computeDepthBiasMVPMatrix() {
// matrices
Matrix4x4 modelViewMatrix = shadowMapping.renderer.getModelViewMatrix();
Matrix4x4 projectionMatrix = shadowMapping.renderer.getProjectionMatrix();
// compute shadow texture matrix
depthBiasMVPMatrix.set(modelViewMatrix).multiply(projectionMatrix).multiply(biasMatrix);
}
Aggregations