Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Scrap billboarding. Not enough time.

  • Loading branch information...
commit a7411f15e45c37c0f78a8fe39d7a8fa443bfe037 1 parent cd92aec
@johnfn authored
View
BIN  src/main/resources/levels/level1_t.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  src/main/resources/levels/level2_t.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  src/main/resources/textures/particle.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
83 src/main/scala/Camera.scala
@@ -44,14 +44,14 @@ class Camera extends Entity {
glLoadIdentity()
multModelViewMatrix()
- storeViewMat()
+ viewMatrix = storeViewMat()
}
def storeViewMat() = {
import java.nio._
import org.lwjgl._
- viewMatrix = new Matrix4f()
+ var viewMatrix: Matrix4f = new Matrix4f()
var buf: FloatBuffer = BufferUtils.createFloatBuffer(16 * 4);
// Get the current model view matrix from OpenGL.
@@ -78,40 +78,77 @@ class Camera extends Entity {
viewMatrix.m31 = buf.get(13)
viewMatrix.m32 = buf.get(14)
viewMatrix.m33 = buf.get(15)
+
+ viewMatrix
}
- def facingCamMat() = {
+ def facingCamMat(px: Float, py: Float, pz: Float) = {
import java.nio._
import org.lwjgl._
+ import org.lwjgl.util.vector._
+
+ var buf: FloatBuffer = BufferUtils.createFloatBuffer(16 * 4);
+ var viewmat: Matrix4f = storeViewMat()
+
+ // Get the current model view matrix from OpenGL.
+ glGetFloat(GL_MODELVIEW_MATRIX, buf);
+
+ var camPos = new Vector3f(-buf.get(12), -buf.get(13), -buf.get(14))
+ var camUp = new Vector3f(buf.get(1), buf.get(5), buf.get(9))
- var result = new Matrix4f(viewMatrix)
+ viewmat.m30 = 0.0f
+ viewmat.m31 = 0.0f
+ viewmat.m32 = 0.0f
- val d: Float = math.sqrt(result.m00 * result.m00 +
- result.m01 * result.m01 +
- result.m02 * result.m02 ).asInstanceOf[Float]
+ viewmat.transpose()
- result.m00 = d
- result.m11 = d
- result.m22 = d
+ camPos.x = viewmat.m00 * camPos.x + viewmat.m10 * camPos.y + viewmat.m20 * camPos.z
+ camPos.y = viewmat.m01 * camPos.x + viewmat.m11 * camPos.y + viewmat.m21 * camPos.z
+ camPos.z = viewmat.m02 * camPos.x + viewmat.m12 * camPos.y + viewmat.m22 * camPos.z
- result.m01 = 0.0f
- result.m02 = 0.0f
- result.m03 = 0.0f
- result.m12 = 0.0f
- result.m13 = 0.0f
- result.m23 = 0.0f
- result.m10 = 0.0f
- result.m20 = 0.0f
- result.m21 = 0.0f
+ var result: Matrix4f = new Matrix4f()
+ var right: Vector3f = new Vector3f()
+ var look = new Vector3f( -px + camPos.x
+ , -py + camPos.y
+ , -pz + camPos.z)
+ look.normalise();
+ var upvec = camUp
+
+ /* right = look x upvec */
+ Vector3f.cross(upvec, look, right);
+ right.normalise();
+
+ /* Recompute upvec as: upvec = right x look */
+ Vector3f.cross(look, right, upvec);
+
+ result.m00 = right.x;
+ result.m10 = right.y;
+ result.m20 = right.z;
+ result.m30 = 0.0f
+
+ result.m01 = up.x;
+ result.m11 = up.y;
+ result.m21 = up.z;
+ result.m31 = 0.0f
+
+ result.m02 = look.x;
+ result.m12 = look.y;
+ result.m22 = look.z;
+ result.m32 = 0.0f
+
+ result.m03 = px
+ result.m13 = py
+ result.m23 = pz
result.m33 = 1.0f
- var buf: FloatBuffer = BufferUtils.createFloatBuffer(16 * 4);
- result.store(buf)
- buf.rewind()
- buf
+ var resbuf: FloatBuffer = BufferUtils.createFloatBuffer(16 * 4);
+ result.store(resbuf)
+ resbuf.rewind()
+
+ resbuf
}
def loadIntoTextureMatrices() = {
View
2  src/main/scala/Game.scala
@@ -140,7 +140,7 @@ object Main {
manager.add(new Block(9, 8, 0))
manager.add(new Enemy(6, 6))
- partmanager.add(new Particle(5.0f, 0.0f, 1.0f))
+ //partmanager.add(new Particle(5.0f, 5.0f, 1.0f))
skybox = new SkyBox()
}
View
2  src/main/scala/Particle.scala
@@ -45,5 +45,5 @@ class Particle(p_x: Float, p_y: Float, p_z: Float) extends VBOModelEntity {
val model = new ParticleModel(x, y, z)
- override def traits() = List("particle")
+ override def traits() = List("render", "particle")
}
View
11 src/main/scala/entity/ParticleManager.scala
@@ -21,21 +21,24 @@ class ParticleManager {
def renderAll(cam: Camera, shader: Shader) = {
import GL11._
+ import java.nio._
+ import org.lwjgl._
+ glDisable(GL_CULL_FACE)
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_BLEND)
glDepthMask(false)
entities.foreach { part =>
glPushMatrix()
- glLoadIdentity()
-
- glMultMatrix(cam.facingCamMat())
-
+ glColor4f(0.0f, 0.0f, 0.0f, 0.0f)
part.renderGL(shader)
glPopMatrix()
}
+
glDisable(GL_BLEND)
glDepthMask(true)
+ glEnable(GL_CULL_FACE)
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.