Package fcagnin.jglsdk.glm

Examples of fcagnin.jglsdk.glm.Vec3


    protected void update() {
        final float SMALL_ANGLE_INCREMENT = 9.0f;
        float lastFrameDuration = getLastFrameDuration() * 10 / 1000.0f;

        if ( Keyboard.isKeyDown( Keyboard.KEY_W ) ) {
            offsetOrientation( new Vec3( 1.0f, 0.0f, 0.0f ), SMALL_ANGLE_INCREMENT * lastFrameDuration );
        } else if ( Keyboard.isKeyDown( Keyboard.KEY_S ) ) {
            offsetOrientation( new Vec3( 1.0f, 0.0f, 0.0f ), -SMALL_ANGLE_INCREMENT * lastFrameDuration );
        }

        if ( Keyboard.isKeyDown( Keyboard.KEY_A ) ) {
            offsetOrientation( new Vec3( 0.0f, 0.0f, 1.0f ), SMALL_ANGLE_INCREMENT * lastFrameDuration );
        } else if ( Keyboard.isKeyDown( Keyboard.KEY_D ) ) {
            offsetOrientation( new Vec3( 0.0f, 0.0f, 1.0f ), -SMALL_ANGLE_INCREMENT * lastFrameDuration );
        }

        if ( Keyboard.isKeyDown( Keyboard.KEY_Q ) ) {
            offsetOrientation( new Vec3( 0.0f, 1.0f, 0.0f ), SMALL_ANGLE_INCREMENT * lastFrameDuration );
        } else if ( Keyboard.isKeyDown( Keyboard.KEY_E ) ) {
            offsetOrientation( new Vec3( 0.0f, 1.0f, 0.0f ), -SMALL_ANGLE_INCREMENT * lastFrameDuration );
        }


        while ( Keyboard.next() ) {
            if ( Keyboard.getEventKeyState() ) {
View Full Code Here


        float hOffset = (float) (Math.cos( cyclicAngle ) * 0.25f);
        float vOffset = (float) (Math.sin( cyclicAngle ) * 0.25f);

        MatrixStack modelMatrix = new MatrixStack();

        final Mat4 worldToCamMat = Glm.lookAt( new Vec3( hOffset, 1.0f, -64.0f ),
                new Vec3( hOffset, -5.0f + vOffset, -44.0f ), new Vec3( 0.0f, 1.0f, 0.0f ) );

        modelMatrix.applyMatrix( worldToCamMat );

        glUseProgram( program.theProgram );
        glUniformMatrix4( program.modelToCameraMatrixUnif, false, modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
View Full Code Here

        glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
        glClearDepth( 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        {
            final Vec3 camPos = resolveCamPosition();

            MatrixStack camMatrix = new MatrixStack();
            camMatrix.setMatrix( calcLookAtMatrix( camPos, camTarget, new Vec3( 0.0f, 1.0f, 0.0f ) ) );

            glUseProgram( uniformColor.theProgram );
            glUniformMatrix4( uniformColor.worldToCameraMatrixUnif, false,
                    camMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
            glUseProgram( objectColor.theProgram );
            glUniformMatrix4( objectColor.worldToCameraMatrixUnif, false,
                    camMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
            glUseProgram( uniformColorTint.theProgram );
            glUniformMatrix4( uniformColorTint.worldToCameraMatrixUnif, false,
                    camMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
            glUseProgram( 0 );

            MatrixStack modelMatrix = new MatrixStack();

            // Render the ground plane.
            {
                modelMatrix.push();
                modelMatrix.scale( 100.0f, 1.0f, 100.0f );

                glUseProgram( uniformColor.theProgram );
                glUniformMatrix4( uniformColor.modelToWorldMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
                glUniform4f( uniformColor.baseColorUnif, 0.302f, 0.416f, 0.0589f, 1.0f );
                planeMesh.render();
                glUseProgram( 0 );

                modelMatrix.pop();
            }

            // Draw the trees.
            drawForest( modelMatrix );

            // Draw the building.
            {
                modelMatrix.push();
                modelMatrix.translate( 20.0f, 0.0f, -10.0f );

                drawParthenon( modelMatrix );

                modelMatrix.pop();
            }

            if ( drawLookatPoint ) {
                glDisable( GL_DEPTH_TEST );

                modelMatrix.push();
                Vec3 cameraAimVec = Vec3.sub( camTarget, camPos );
                modelMatrix.translate( 0.0f, 0.0f, -Glm.length( cameraAimVec ) );
                modelMatrix.scale( 1.0f, 1.0f, 1.0f );

                Mat4 identity = new Mat4( 1.0f );
View Full Code Here

        float sinTheta = (float) Math.sin( theta );
        float cosTheta = (float) Math.cos( theta );
        float cosPhi = (float) Math.cos( phi );
        float sinPhi = (float) Math.sin( phi );

        Vec3 dirToCamera = new Vec3( sinTheta * cosPhi, cosTheta, sinTheta * sinPhi );
        return (dirToCamera.scale( sphereCamRelPos.z )).add( camTarget );
    }
View Full Code Here

        return (dirToCamera.scale( sphereCamRelPos.z )).add( camTarget );
    }


    private Mat4 calcLookAtMatrix(Vec3 cameraPt, Vec3 lookPt, Vec3 upPt) {
        Vec3 lookDir = Glm.normalize( Vec3.sub( lookPt, cameraPt ) );
        Vec3 upDir = Glm.normalize( upPt );

        Vec3 rightDir = Glm.normalize( Glm.cross( lookDir, upDir ) );
        Vec3 perpUpDir = Glm.cross( rightDir, lookDir );

        Mat4 rotMat = new Mat4( 1.0f );
        rotMat.setColumn( 0, new Vec4( rightDir, 0.0f ) );
        rotMat.setColumn( 1, new Vec4( perpUpDir, 0.0f ) );
        rotMat.setColumn( 2, new Vec4( Vec3.negate( lookDir ), 0.0f ) );
View Full Code Here

    protected void display() {
        glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
        glClearDepth( 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        final Vec3 camPos = resolveCamPosition();

        MatrixStack camMatrix = new MatrixStack();
        camMatrix.setMatrix( calcLookAtMatrix( camPos, camTarget, new Vec3( 0.0f, 1.0f, 0.0f ) ) );

        glBindBuffer( GL_UNIFORM_BUFFER, globalMatricesUBO );
        glBufferSubData( GL_UNIFORM_BUFFER, Mat4.SIZE, camMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
        glBindBuffer( GL_UNIFORM_BUFFER, 0 );
View Full Code Here

        float sinTheta = (float) Math.sin( theta );
        float cosTheta = (float) Math.cos( theta );
        float cosPhi = (float) Math.cos( phi );
        float sinPhi = (float) Math.sin( phi );

        Vec3 dirToCamera = new Vec3( sinTheta * cosPhi, cosTheta, sinTheta * sinPhi );
        return (dirToCamera.scale( sphereCamRelPos.z )).add( camTarget );
    }
View Full Code Here

        return (dirToCamera.scale( sphereCamRelPos.z )).add( camTarget );
    }


    private Mat4 calcLookAtMatrix(Vec3 cameraPt, Vec3 lookPt, Vec3 upPt) {
        Vec3 lookDir = Glm.normalize( Vec3.sub( lookPt, cameraPt ) );
        Vec3 upDir = Glm.normalize( upPt );

        Vec3 rightDir = Glm.normalize( Glm.cross( lookDir, upDir ) );
        Vec3 perpUpDir = Glm.cross( rightDir, lookDir );

        Mat4 rotMat = new Mat4( 1.0f );
        rotMat.setColumn( 0, new Vec4( rightDir, 0.0f ) );
        rotMat.setColumn( 1, new Vec4( perpUpDir, 0.0f ) );
        rotMat.setColumn( 2, new Vec4( Vec3.negate( lookDir ), 0.0f ) );
View Full Code Here

            // Render the sun
            {
                modelMatrix.push();

                Vec3 sunlightDir = new Vec3( lights.getSunlightDirection() );
                modelMatrix.translate( sunlightDir.scale( 500.0f ) );
                modelMatrix.scale( 30.0f, 30.0f, 30.0f );

                glUseProgram( unlit.theProgram );
                glUniformMatrix4( unlit.modelToCameraMatrixUnif, false,
                        modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
View Full Code Here

      // Remember: these transforms are in reverse order.

      // In this space, we are facing in the correct direction. Which means that the camera point
      // is directly behind us by the radius number of units.
      mat = Glm.translate(mat, new Vec3(0.0f, 0.0f, -m_currView.radius));

      // Rotate the world to look in the right direction..
      Quaternion fullRotation = Glm.angleAxis(m_currView.degSpinRotation, new Vec3(0.0f, 0.0f, 1.0f)).mul(m_currView.orient);

      mat.mul(Glm.matCast(fullRotation));

      // Translate the world by the negation of the lookat point, placing the origin at the lookat point.
      mat = Glm.translate(mat, Vec3.negate(m_currView.targetPos));
View Full Code Here

TOP

Related Classes of fcagnin.jglsdk.glm.Vec3

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.