use of org.joml.Vector4f in project lwjgl3-demos by LWJGL.
the class SpaceGame method drawShots.
private void drawShots() {
shotsVertices.clear();
int num = 0;
for (int i = 0; i < projectilePositions.length; i++) {
Vector3d projectilePosition = projectilePositions[i];
Vector4f projectileVelocity = projectileVelocities[i];
if (projectileVelocity.w > 0.0f) {
float x = (float) (projectilePosition.x - cam.position.x);
float y = (float) (projectilePosition.y - cam.position.y);
float z = (float) (projectilePosition.z - cam.position.z);
if (frustumIntersection.testPoint(x, y, z)) {
float w = projectileVelocity.w;
viewMatrix.transformPosition(tmp2.set(x, y, z));
shotsVertices.put(tmp2.x - shotSize).put(tmp2.y - shotSize).put(tmp2.z).put(w).put(-1).put(-1);
shotsVertices.put(tmp2.x + shotSize).put(tmp2.y - shotSize).put(tmp2.z).put(w).put(1).put(-1);
shotsVertices.put(tmp2.x + shotSize).put(tmp2.y + shotSize).put(tmp2.z).put(w).put(1).put(1);
shotsVertices.put(tmp2.x + shotSize).put(tmp2.y + shotSize).put(tmp2.z).put(w).put(1).put(1);
shotsVertices.put(tmp2.x - shotSize).put(tmp2.y + shotSize).put(tmp2.z).put(w).put(-1).put(1);
shotsVertices.put(tmp2.x - shotSize).put(tmp2.y - shotSize).put(tmp2.z).put(w).put(-1).put(-1);
num++;
}
}
}
shotsVertices.flip();
if (num > 0) {
glUseProgram(shotProgram);
glDepthMask(false);
glEnable(GL_BLEND);
glVertexPointer(4, GL_FLOAT, 6 * 4, shotsVertices);
shotsVertices.position(4);
glTexCoordPointer(2, GL_FLOAT, 6 * 4, shotsVertices);
shotsVertices.position(0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, num * 6);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_BLEND);
glDepthMask(true);
}
}
use of org.joml.Vector4f in project lwjgl3-demos by LWJGL.
the class SpaceGame method shootFromShip.
private void shootFromShip(long thisTime, int index) {
Ship ship = ships[index];
if (ship == null)
return;
if (thisTime - ship.lastShotTime < 1E6 * shotOpponentMilliseconds) {
return;
}
ship.lastShotTime = thisTime;
Vector3d shotPos = tmp.set(ship.x, ship.y, ship.z).sub(cam.position).negate().normalize().mul(1.01f * shipRadius).add(ship.x, ship.y, ship.z);
Vector3f icept = intercept(shotPos, shotVelocity, cam.position, cam.linearVel, tmp2);
if (icept == null)
return;
// jitter the direction a bit
GeometryUtils.perpendicular(icept, tmp3, tmp4);
icept.fma(((float) Math.random() * 2.0f - 1.0f) * 0.01f, tmp3);
icept.fma(((float) Math.random() * 2.0f - 1.0f) * 0.01f, tmp4);
icept.normalize();
for (int i = 0; i < projectilePositions.length; i++) {
Vector3d projectilePosition = projectilePositions[i];
Vector4f projectileVelocity = projectileVelocities[i];
if (projectileVelocity.w <= 0.0f) {
projectilePosition.set(shotPos);
projectileVelocity.x = tmp2.x * shotVelocity;
projectileVelocity.y = tmp2.y * shotVelocity;
projectileVelocity.z = tmp2.z * shotVelocity;
projectileVelocity.w = 0.01f;
break;
}
}
}
use of org.joml.Vector4f in project lwjgl3-demos by LWJGL.
the class SpaceGame method shoot.
private void shoot() {
boolean firstShot = false;
for (int i = 0; i < projectilePositions.length; i++) {
Vector3d projectilePosition = projectilePositions[i];
Vector4f projectileVelocity = projectileVelocities[i];
invViewProjMatrix.transformProject(tmp2.set(mouseX, -mouseY, 1.0f)).normalize();
if (projectileVelocity.w <= 0.0f) {
projectileVelocity.x = cam.linearVel.x + tmp2.x * shotVelocity;
projectileVelocity.y = cam.linearVel.y + tmp2.y * shotVelocity;
projectileVelocity.z = cam.linearVel.z + tmp2.z * shotVelocity;
projectileVelocity.w = 0.01f;
if (!firstShot) {
projectilePosition.set(cam.right(tmp3)).mul(shotSeparation).add(cam.position);
firstShot = true;
} else {
projectilePosition.set(cam.right(tmp3)).mul(-shotSeparation).add(cam.position);
break;
}
}
}
}
Aggregations