Search in sources :

Example 6 with Matrix4x4

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();
}
Also used : Matrix4x4(net.drewke.tdme.math.Matrix4x4)

Example 7 with Matrix4x4

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();
}
Also used : Matrix4x4(net.drewke.tdme.math.Matrix4x4)

Example 8 with Matrix4x4

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);
}
Also used : Entity(net.drewke.tdme.engine.Entity) Matrix4x4(net.drewke.tdme.math.Matrix4x4)

Example 9 with Matrix4x4

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();
}
Also used : Matrix4x4(net.drewke.tdme.math.Matrix4x4)

Example 10 with Matrix4x4

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);
}
Also used : Matrix4x4(net.drewke.tdme.math.Matrix4x4)

Aggregations

Matrix4x4 (net.drewke.tdme.math.Matrix4x4)21 Group (net.drewke.tdme.engine.model.Group)6 Joint (net.drewke.tdme.engine.model.Joint)5 Vector3 (net.drewke.tdme.math.Vector3)5 StringTokenizer (java.util.StringTokenizer)3 Skinning (net.drewke.tdme.engine.model.Skinning)3 Element (org.w3c.dom.Element)3 ArrayList (java.util.ArrayList)2 Animation (net.drewke.tdme.engine.model.Animation)2 JointWeight (net.drewke.tdme.engine.model.JointWeight)2 HashMap (net.drewke.tdme.utils.HashMap)2 File (java.io.File)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 Entity (net.drewke.tdme.engine.Entity)1 Rotation (net.drewke.tdme.engine.Rotation)1 Transformations (net.drewke.tdme.engine.Transformations)1 Face (net.drewke.tdme.engine.model.Face)1 FacesEntity (net.drewke.tdme.engine.model.FacesEntity)1 Model (net.drewke.tdme.engine.model.Model)1 UpVector (net.drewke.tdme.engine.model.Model.UpVector)1