use of org.joml.Vector3d in project lwjgl3-demos by LWJGL.
the class SpaceGame method drawHudShotDirection.
private void drawHudShotDirection() {
glUseProgram(0);
Ship enemyShip = ships[shootingShip];
if (enemyShip == null)
return;
Vector3d targetOrigin = tmp;
targetOrigin.set(enemyShip.x, enemyShip.y, enemyShip.z);
Vector3f interceptorDir = intercept(cam.position, shotVelocity, targetOrigin, tmp3.set(cam.linearVel).negate(), tmp2);
viewMatrix.transformDirection(interceptorDir);
if (interceptorDir.z > 0.0)
return;
projMatrix.transformProject(interceptorDir);
float crosshairSize = 0.01f;
float xs = crosshairSize * height / width;
float ys = crosshairSize;
crosshairVertices.clear();
crosshairVertices.put(interceptorDir.x - xs).put(interceptorDir.y - ys);
crosshairVertices.put(interceptorDir.x + xs).put(interceptorDir.y - ys);
crosshairVertices.put(interceptorDir.x + xs).put(interceptorDir.y + ys);
crosshairVertices.put(interceptorDir.x - xs).put(interceptorDir.y + ys);
crosshairVertices.flip();
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glVertexPointer(2, GL_FLOAT, 0, crosshairVertices);
glDrawArrays(GL_QUADS, 0, 4);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
use of org.joml.Vector3d 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.Vector3d 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