• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java HeadTransform类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.vr.sdk.base.HeadTransform的典型用法代码示例。如果您正苦于以下问题:Java HeadTransform类的具体用法?Java HeadTransform怎么用?Java HeadTransform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HeadTransform类属于com.google.vr.sdk.base包,在下文中一共展示了HeadTransform类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
 * Prepares OpenGL ES before we draw a frame.
 *
 * @param headTransform The head transformation in the new frame.
 */
@Override
public void onNewFrame(HeadTransform headTransform) {
  setCubeRotation();

  // Build the camera matrix and apply it to the ModelView.
  Matrix.setLookAtM(camera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

  headTransform.getHeadView(headView, 0);

  // Update the 3d audio engine with the most recent head rotation.
  headTransform.getQuaternion(headRotation, 0);
  gvrAudioEngine.setHeadRotation(
      headRotation[0], headRotation[1], headRotation[2], headRotation[3]);
  // Regular update call to GVR audio engine.
  gvrAudioEngine.update();

  checkGLError("onReadyToDraw");
}
 
开发者ID:codedavid,项目名称:PanoramaGL,代码行数:24,代码来源:TreasureHuntActivity.java


示例2: update

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
@Override
public void update(HeadTransform headTransform) {
    float[] forwardVec = new float[3];
    float[] upVec = new float[3];
    float[] rightVec = new float[3];
    headTransform.getForwardVector(forwardVec, 0);
    headTransform.getUpVector(upVec, 0);
    headTransform.getRightVector(rightVec, 0);

    // create m in column major order
    // invert forward vec because in opengl -z is forward
    float[] m = new float[] {
            rightVec[0], upVec[0], -forwardVec[0], 0.0f,
            rightVec[1], upVec[1], -forwardVec[1], 0.0f,
            rightVec[2], upVec[2], -forwardVec[2], 0.0f,
            0.0f, 0.0f, 0.0f, 1.0f
    };
    // a = M^T * b where b is vector representation in cardboard basis
    float[] mt = new float[16];
    Matrix.transposeM(mt, 0, m, 0);
    mModelScreen = mt;
}
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:23,代码来源:StereoScreenRenderer.java


示例3: getCardboardToWorldTransform

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
 * Calculates a column-major transformation matrix that will transform a vector in the basis
 * formed by the Google cardboard (up, right, and forward vector from the HeadTransform)
 * to the world system (right-handed for OpenGL). I.e., given the returned matrix M, and a vector b in cardboard coordinates,
 * then a = M * b where a is in world coordinates.
 * @param M The 4x4 matrix to place the transformation in.
 * @param headTransform The head transform to form the transformation from
 */
public static void getCardboardToWorldTransform(float[] M, HeadTransform headTransform) {
    if (M.length != 16) {
        throw new IllegalArgumentException("Destination matrix array must be 4x4 (length 16)!");
    }

    float[] forwardVec = new float[3];
    float[] upVec = new float[3];
    float[] rightVec = new float[3];
    headTransform.getForwardVector(forwardVec, 0);
    headTransform.getUpVector(upVec, 0);
    headTransform.getRightVector(rightVec, 0);

    // transform to world coordinates from camera
    // create m in column major order
    // invert forward vec because in opengl -z is forward
    float[] m = new float[] {
            rightVec[0], upVec[0], -forwardVec[0], 0.0f,
            rightVec[1], upVec[1], -forwardVec[1], 0.0f,
            rightVec[2], upVec[2], -forwardVec[2], 0.0f,
            0.0f, 0.0f, 0.0f, 1.0f
    };
    // a = m^T * b where b is vector representation in camera (cardboard) basis
    Matrix.transposeM(M, 0, m, 0);
}
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:33,代码来源:GarUtil.java


示例4: getTranslationMatFromTvec

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
 * Calculates a column-major translation matrix from the given
 * OpenCV tvec. This method transforms the translation into the
 * world coordinate system to valid OpenGL coordinates using the given HeadTransform, which could
 * be passed directly into a shader to translate an object to the
 * marker that produced the tvec.
 * @param transMat The 4x4 matrix to place the translation in.
 * @param tvec OpenCV tvec.
 */
public static void getTranslationMatFromTvec(float[] transMat, Mat tvec, HeadTransform headTransform) {
    if (transMat.length != 16) {
        throw new IllegalArgumentException("Destination matrix array must be 4x4 (length 16)!");
    }

    float[] tvecCam = new float[4];
    tvecToCardboardCoords(tvecCam, tvec);

    // transform to world coords
    float[] mt = new float[16];
    getCardboardToWorldTransform(mt, headTransform);
    float tvecWorld[] = new float[4];
    Matrix.multiplyMV(tvecWorld, 0, mt, 0, tvecCam, 0);

    // Build translation matrix
    Matrix.setIdentityM(transMat, 0);
    Matrix.translateM(transMat, 0, tvecWorld[0], tvecWorld[1], tvecWorld[2]);
}
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:28,代码来源:GarUtil.java


示例5: getRotationMatFromRvec

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
 * Calculates a column-major rotation matrix from the given
 * OpenCV rvec. This method transforms the rotation into the
 * world coordinate system using the given HeadTransform to valid OpenGL coordinates, which could
 * be passed directly into a shader to rotate an object to the
 * the pose estimated by the marker that produced the rvec.
 * @param rotMat The 4x4 matrix to place the rotation in.
 * @param rvec OpenCV rvec.
 * @param headTransform The HeadTransform for the current frame.
 */
public static void getRotationMatFromRvec(float[] rotMat, Mat rvec, HeadTransform headTransform) {
    if (rotMat.length != 16) {
        throw new IllegalArgumentException("Destination matrix array must be 4x4 (length 16)!");
    }

    // must use rvec to find rotation matrix
    // transform rotation axis to world space
    float angleRad = (float) Core.norm(rvec, Core.NORM_L2);
    float angle = (float)Math.toDegrees(angleRad);
    float rvecCam[] = {(float)rvec.get(0, 0)[0] / angleRad, -1.0f * (float)rvec.get(1, 0)[0] / angleRad, -1.0f * (float)rvec.get(2, 0)[0] / angleRad, 0.0f};
    float rvecArr[] = new float[4];
    float[] mt = new float[16];
    getCardboardToWorldTransform(mt, headTransform);
    Matrix.multiplyMV(rvecArr, 0, mt, 0, rvecCam, 0);

    // Build rotation matrix
    Matrix.setIdentityM(rotMat, 0);
    Matrix.rotateM(rotMat, 0, angle, rvecArr[0], rvecArr[1], rvecArr[2]);
}
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:30,代码来源:GarUtil.java


示例6: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
 * Prepares OpenGL ES before we draw a frame.
 *
 * @param headTransform The head transformation in the new frame.
 */
@Override
public void onNewFrame(HeadTransform headTransform) {

    //rotate the cube, mangle is how fast, x,y,z which directions it rotates.
    Matrix.rotateM(CubeMatrix0, 0, mAngle, 0.7f, 0.7f, 1.0f);
    //rotate cube2, mangle is how fast, x,y,z which directions it rotates.
    Matrix.rotateM(CubeMatrix1, 0, -mAngle, 0.7f, 0.7f, 1.0f);
    Matrix.rotateM(CubeMatrix2, 0, mAngle, 1.0f, 0.7f, 0.7f);
    Matrix.rotateM(CubeMatrix3, 0, -mAngle, 1.0f, 0.7f, 0.7f);
    Matrix.rotateM(CubeMatrix4, 0, mAngle, 0.7f, 1.0f, 0.7f);
    Matrix.rotateM(CubeMatrix5, 0, -mAngle, 0.7f, 1.0f, 0.7f);
    Matrix.rotateM(CubeMatrix6, 0, mAngle, 0.5f, 0.5f, 1.5f);
    Matrix.rotateM(CubeMatrix7, 0, -mAngle, 0.5f, 0.5f, 1.5f);

    // Build the camera matrix and apply it to the ModelView.
    Matrix.setLookAtM(camera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    headTransform.getHeadView(headView, 0);
}
 
开发者ID:JimSeker,项目名称:CardBoardVR,代码行数:25,代码来源:myStereoRenderer.java


示例7: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
     * Prepares OpenGL ES before we draw a frame.
     *
     * @param headTransform The head transformation in the new frame.
     */
    @Override
    public void onNewFrame(HeadTransform headTransform) {

        //rotate the cube, mangle is how fast, x,y,z which directions it rotates.
        Matrix.rotateM(mRotationMatrix, 0, mAngle, 0.7f, 0.7f, 1.0f);

        if (moving) {
            //so figure out which direction we are facing, using the forward normalized vector.
            headTransform.getForwardVector(forward, 0);
            Log.v(TAG, "X =" + forward[0] + " Y=" + forward[1] + " Z=" + forward[2]);
            MoveX = forward[0] * mSpeed;
            MoveY = forward[1] * mSpeed;
            MoveZ = -forward[2] * mSpeed;  //-Z otherwise, going the wrong direction...
//                                         X  Y  Z
            //Matrix.translateM(camera, 0, 0, 0, 0.1f);
            Matrix.translateM(camera, 0, MoveX, MoveY, MoveZ);
            //moving = false;
        }
        //I don't think I need this at all.
        headTransform.getHeadView(headView, 0);
    }
 
开发者ID:JimSeker,项目名称:CardBoardVR,代码行数:27,代码来源:myStereoRenderer.java


示例8: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
 * Prepares OpenGL ES before we draw a frame.
 *
 * @param headTransform The head transformation in the new frame.
 */
@Override
public void onNewFrame(HeadTransform headTransform) {
    // Build the Model part of the ModelView matrix.
    Matrix.rotateM(modelCube, 0, TIME_DELTA, 0.5f, 0.5f, 1.0f);

    // Build the camera matrix and apply it to the ModelView.
    Matrix.setLookAtM(camera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    headTransform.getHeadView(headView, 0);

    // Update the 3d audio engine with the most recent head rotation.
    headTransform.getQuaternion(headRotation, 0);
    gvrAudioEngine.setHeadRotation(
            headRotation[0], headRotation[1], headRotation[2], headRotation[3]);

    checkGLError("onReadyToDraw");
}
 
开发者ID:JimSeker,项目名称:CardBoardVR,代码行数:23,代码来源:MainActivity.java


示例9: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
@Override
public boolean onNewFrame(HeadTransform headTransform, boolean forceRedraw) {
	scenes.get(sceneIndex).camera.updateViewMatrix();

	headTransform.getForwardVector(forward, 0);
	forwardVector.setAll(forward, 0);

	// Check if we are looking to one of the two buttons
	buttonLeft.checkIsLooking(scenes.get(sceneIndex).camera.getPosition(), forwardVector);
	buttonRight.checkIsLooking(scenes.get(sceneIndex).camera.getPosition(), forwardVector);

	// Animations
	long currentTime = System.currentTimeMillis();
	long timeElapsed = lastTimeStamp == -1 ? 0 : currentTime - lastTimeStamp;
	lastTimeStamp = currentTime;

	// First animate the buttons (it can also generate an scene change)
	buttonLeft.animate(timeElapsed);
	buttonRight.animate(timeElapsed);

	// Now update the shown scene
	if (scenes.get(sceneIndex) instanceof ObjLoaderScene) {
		((ObjLoaderScene) scenes.get(sceneIndex)).update(timeElapsed);
	}

	return true;
}
 
开发者ID:mobialia,项目名称:jmini3d-vr-demo,代码行数:28,代码来源:MyScreenController.java


示例10: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
@Override
public void onNewFrame(HeadTransform headTransform) {
	screenController.onNewFrame(headTransform, true);

	// TODO Workaround for a R SDK bug, distortion correction disables GL_DEPTH_TEST
	GLES20.glEnable(GLES20.GL_DEPTH_TEST);

	if (logFps) {
		doFps();
	}
}
 
开发者ID:mobialia,项目名称:jmini3d-vr-demo,代码行数:12,代码来源:VRActivity.java


示例11: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
@Override
public void onNewFrame(HeadTransform headTransform) {
  checkIfAllProductsAreAnimated();

  long currentNanos = System.nanoTime();
  if (lastRendered == 0) {
    lastRendered = currentNanos;
  }

  actors.act(currentNanos - lastRendered);
  lastRendered = currentNanos;

  renderer.prepare();
}
 
开发者ID:contentful-labs,项目名称:contentful-cardboard,代码行数:15,代码来源:MainActivity.java


示例12: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
@Override
public void onNewFrame(HeadTransform headTransform) {
    // capture image to use
    try {
        mCameraCaptureSession.capture(mPreviewBuilder.build(), mCapCall, new Handler(Looper.getMainLooper()));
    } catch (RuntimeException | CameraAccessException ex) {
        Log.e(TAG, "Error capturing: " + ex.getMessage());
    }

    // Update the renderers
    camTexRenderer.update(headTransform);
    screenRenderer.update(headTransform);

    // Draw current camera view to texture through frame buffer
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFboIdCamera);
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glViewport(0, 0, mPreviewSize.getWidth(), mPreviewSize.getHeight());

    float[] iden = new float[16];
    Matrix.setIdentityM(iden, 0);
    // don't need view or perspective so just pass in identity
    camTexRenderer.draw(iden, iden);

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, DEFAULT_FBO_ID);

    // Build the camera matrix.
    Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    garutil.checkGLError("onReadyToDraw");
}
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:33,代码来源:GarActivity.java


示例13: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
 * Prepares OpenGL ES before we draw a frame.
 *
 * @param headTransform The head transformation in the new frame.
 */
@Override
public void onNewFrame(HeadTransform headTransform) {

    //rotate the cube, mangle is how fast, x,y,z which directions it rotates.
    Matrix.rotateM(mRotationMatrix, 0, mAngle, 0.7f, 0.7f, 1.0f);

    // Build the camera matrix and apply it to the ModelView.
    Matrix.setLookAtM(camera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    headTransform.getHeadView(headView, 0);
}
 
开发者ID:JimSeker,项目名称:CardBoardVR,代码行数:17,代码来源:myStereoRenderer.java


示例14: getTransformationFromTrackingParams

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
 * Takes in an OpenCV tvec and rvec, and returns a transformation matrix to place
 * an object defined in the Cardboard coordinate system (defined by up, right, and forward vectors from the HeadTransform)
 * in the pose and location defined by the tvec and rvec. <br></br><br></br>
 * <b>Note: this method is recommended for drawing augmented objects in the scene.</b>
 * @param transMat The 4x4 matrix to place the transformation in.
 * @param tvec The OpenCV tvec to use.
 * @param rvec The OpenCV rvec to use.
 * @param headTransform The head transformation from the same frame as tvec and rvec.
 */
public static void getTransformationFromTrackingParams(float[] transMat, Mat tvec, Mat rvec, HeadTransform headTransform) {
    if (transMat.length != 16) {
        throw new IllegalArgumentException("Destination matrix array must be 4x4 (length 16)!");
    }

    // Get the rotation matrix
    float[] rot = new float[16];
    getRotationMatFromRvec(rot, rvec, headTransform);

    // Turn tvec into a cardboard basis coordinate system
    float[] tvecCam = new float[4];
    tvecToCardboardCoords(tvecCam, tvec);

    // adjust z so not too close to camera
    // update x and y accordingly
    // must move away in cardboard -z as well as properly scale so this translation isn't noticed
    float xRatio = tvecCam[0] / Math.abs(tvecCam[2]);
    float yRatio = tvecCam[1] / Math.abs(tvecCam[2]);
    float scaleRatio = 1.0f / Math.abs(tvecCam[2]);
    float distToMoveZ = Math.abs(Math.abs(tvecCam[2]) - Math.abs(StereoScreenRenderer.SCREEN_DEPTH));
    float adjustZ = (StereoScreenRenderer.SCREEN_DEPTH <= tvecCam[2] ? -distToMoveZ : distToMoveZ); // actually moves to the initial Z position
    float scaleFact = 1.0f - adjustZ * scaleRatio;
    float adjustX = -adjustZ * xRatio;
    float adjustY = -adjustZ * yRatio;
    tvecCam[0] += adjustX;
    tvecCam[1] += adjustY;
    tvecCam[2] += adjustZ;
    // build the scale matrix
    float[] scale = new float[16];
    Matrix.setIdentityM(scale, 0);
    Matrix.scaleM(scale, 0, scaleFact, scaleFact, scaleFact);

    // transform to world coords
    float[] mt = new float[16];
    getCardboardToWorldTransform(mt, headTransform);
    float tvecWorld[] = new float[4];
    Matrix.multiplyMV(tvecWorld, 0, mt, 0, tvecCam, 0);
    // Build translation matrix
    float trans[] = new float[16];
    Matrix.setIdentityM(trans, 0);
    Matrix.translateM(trans, 0, tvecWorld[0], tvecWorld[1], tvecWorld[2]);

    // multiply together, we want v' = TSRM^T v
    float[] basisChangeRot = new float[16];
    float[] addScale = new float[16];
    Matrix.multiplyMM(basisChangeRot, 0, rot, 0, mt, 0);
    Matrix.multiplyMM(addScale, 0, scale, 0, basisChangeRot, 0);

    Matrix.setIdentityM(transMat, 0);
    Matrix.multiplyMM(transMat, 0, trans, 0, addScale, 0);
}
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:62,代码来源:GarUtil.java


示例15: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
@Override
public void onNewFrame(HeadTransform headTransform) {
    Matrix.setLookAtM(camera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    headTransform.getHeadView(headView, 0);
}
 
开发者ID:dbrant,项目名称:cardboard-mpo,代码行数:6,代码来源:MainActivity.java


示例16: update

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
 * Updates the GL elements of the renderer like vertex buffers
 * and model matrices. These things are independent of any single view
 * and is meant to be called once per frame. Should be called from
 * {@link GvrView.StereoRenderer#onNewFrame onNewFrame()}.
 *
 * @param headTransform Contains the up, right, and forward vectors of the
 *                      cardboard viewer needed for calculations.
 */
@Override
public void update(HeadTransform headTransform) {
    // Nothing to update
    return;
}
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:15,代码来源:CameraTextureRenderer.java


示例17: update

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
/**
 * Updates the GL elements of the renderer like vertex buffers
 * and model matrices. These things are independent of any single view
 * and is meant to be called once per frame. Should be called from
 * {@link com.google.vr.sdk.base.GvrView.StereoRenderer#onNewFrame onNewFrame()}.
 * @param headTransform Contains the up, right, and forward vectors of the
 *                      cardboard viewer needed for calculations.
 */
public void update(HeadTransform headTransform);
 
开发者ID:davrempe,项目名称:cardboardAR-lib,代码行数:10,代码来源:GLRenderer.java


示例18: onNewFrame

import com.google.vr.sdk.base.HeadTransform; //导入依赖的package包/类
public boolean onNewFrame(HeadTransform headTransform, boolean forceRedraw); 
开发者ID:mobialia,项目名称:jmini3d-vr-demo,代码行数:2,代码来源:VRScreenController.java



注:本文中的com.google.vr.sdk.base.HeadTransform类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Asserts类代码示例发布时间:2022-05-22
下一篇:
Java CommandUsageException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap