public class CardboardView

Convenience extension of GLSurfaceView that can be used for VR rendering.

Designed to work in full screen mode with a landscape or reverse landscape orientation.

This view can be used as a normalGLSurfaceViewby implementing one of its rendering interfaces:

  • CardboardView.StereoRenderer: abstracts all stereoscopic rendering details from the renderer.
  • CardboardView.Renderer: for complex engines that need to handle all stereo rendering details by themselves.

TheCardboardView.StereoRendererinterface is recommended for all applications that can make use of it, while theCardboardView.Rendererinterface is discouraged and should only be used if really needed.

The view allows switching from VR mode to normal rendering mode in stereo renderers at any time by calling thesetVRModeEnabledmethod.

Nested Classes

interface CardboardView.Renderer Interface for renderers who need to handle all the stereo rendering details by themselves.
interface CardboardView.StereoRenderer Interface for renderers that delegate all stereoscopic rendering details to the view.

Public Constructors

CardboardView(Context context)
CardboardView(Context context, AttributeSet attrs)

Public Methods

boolean getAlignmentMarkerEnabled()
CardboardDeviceParams getCardboardDeviceParams()
boolean getDistortionCorrectionEnabled()
boolean getElectronicDisplayStabilizationEnabled()
boolean getGyroBiasEstimationEnabled()
HeadMountedDisplay getHeadMountedDisplay()
float getInterpupillaryDistance()
float getNeckModelFactor()
boolean getRestoreGLStateEnabled()
ScreenParams getScreenParams()
boolean getSettingsButtonEnabled()
boolean getVRMode()
boolean getVignetteEnabled()
void onPause()
void onResume()
void resetHeadTracker()
void setAlignmentMarkerEnabled(boolean enabled)
void setDistortionCorrectionEnabled(boolean enabled)
void setElectronicDisplayStabilizationEnabled(boolean enabled)
void setGyroBiasEstimationEnabled(boolean enabled)
void setNeckModelEnabled(boolean enabled)
void setNeckModelFactor(float factor)
void setOnCardboardTriggerListener(Runnablelistener)
void setRenderer(CardboardView.Rendererrenderer)
void setRenderer(CardboardView.StereoRendererrenderer)
void setRestoreGLStateEnabled(boolean enabled)
void setSettingsButtonEnabled(boolean enabled)
void setVRModeEnabled(boolean enabled)
void setVignetteEnabled(boolean enabled)
void undistortTexture(int inputTexture)
void updateCardboardDeviceParams(CardboardDeviceParamscardboardDeviceParams)
void updateScreenParams(ScreenParamsscreenParams)

Inherited Methods

From class java.lang.Object

Public Constructors

publicCardboardView(Context context)

publicCardboardView(Context context, AttributeSet attrs)

Public Methods

public booleangetAlignmentMarkerEnabled()

Returns whether the alignment marker is drawn.

Returns
  • trueif the alignment marker is enabled,falseotherwise. Enabled by default.

publicCardboardDeviceParamsgetCardboardDeviceParams()

Returns the physical parameters of the current Cardboard device.

This is a convenience method forgetHeadMountedDisplay().getCardboardDeviceParams().

Changes to the returned object do not have any affect on rendering. To make them effective use theupdateCardboardDeviceParamsmethod.

Returns
  • The physical parameters of the current Cardboard device.

public booleangetDistortionCorrectionEnabled()

Gets whether distortion correction is enabled.

Returns
  • trueif distortion correction is enabled,falseotherwise.

public booleangetElectronicDisplayStabilizationEnabled()

(Experimental) Returns whether or not Electronic Display Stabilization (EDS) is enabled. Refer to {link #setElectronicDisplayStabilizationEnabled} for more details about EDS.

Returns
  • trueif EDS is currently enabledfalseotherwise.

public booleangetGyroBiasEstimationEnabled()

Whether gyroscope bias estimation is enabled.

Returns
  • trueif gyroscope bias estimation is enabled.

publicHeadMountedDisplaygetHeadMountedDisplay()

Returns the current head mounted display this view is rendering for.

Contains various parameters about the screen and Cardboard device that combined make up the head mounted display.

Note that changing the returned object will not make any changes to rendering. For that purpose theupdateCardboardDeviceParamsandupdateScreenParamsmethods should be used instead.

Returns
  • The parameters of the target head mounted display.

public floatgetInterpupillaryDistance()

Gets the interpupillary distance. The Cardboard framework currently assumes that user IPD matches inter-lens distance of the viewing device.

Returns
  • The current interpupillary distance in meters.

public floatgetNeckModelFactor()

Gets the neck model factor for head tracking.

Refer to {link #setNeckModelEnabled()} for more detail on neck model and {link #setNeckModelFactor()} for more detail on neck model factor.

Returns
  • the neck model factor.

public booleangetRestoreGLStateEnabled()

Returns whether or not the application's GL state after postprocessing is restored.

Returns
  • trueif GL state restoration is currently enabled,falseotherwise. Enabled by default.

publicScreenParamsgetScreenParams()

Returns the screen parameters of the inserted device.

This is a convenience method forgetHeadMountedDisplay().getScreenParams().

Changes to the returned object do not have any affect on rendering. To make them effective use theupdateScreenParamsmethod.

Returns
  • The screen parameters of the inserted device.

public booleangetSettingsButtonEnabled()

Returns whether the settings button is drawn.

Returns
  • trueif the settings button is enabled,falseotherwise. Enabled by default.

public booleangetVRMode()

Returns the current VR mode setting.

Returns
  • trueif VR mode is currently enabled,falseotherwise. Enabled by default.

public booleangetVignetteEnabled()

Returns whether or not vignetting is enabled.

Returns
  • trueif vignetting is currently enabled,falseotherwise. Enabled by default.

public voidonPause()

Informs the view that the activity has been paused.

public voidonResume()

Informs the view that the activity has been resumed.

public voidresetHeadTracker()

Ask the head-tracker to reset itself.

Among other things, this will make the scene's Z axis align with the current phone heading (compass direction).

public voidsetAlignmentMarkerEnabled(boolean enabled)

Enables or disables drawing a vertical line dividing the viewport in half. This is designed to help users correctly align the cardboard to the screen.

Only applies when VR mode is enabled.

Parameters
enabled trueto enable drawing the alignment marker,falseto disable.

public voidsetDistortionCorrectionEnabled(boolean enabled)

Sets whether distortion correction is enabled.

Enabled by default. Changes will be effective from the first frame after this call.

Parameters
enabled trueto enable distortion correction,falseto disable.

public voidsetElectronicDisplayStabilizationEnabled(boolean enabled)

(Experimental) Enables or disables Electronic Display Stabilization (EDS).

Electronic Display Stabilization is done during the distortion rendering pass (so it only works if distortion correction is enabled). It reads the latest sensor input and, if the head has rotated since the app rendered the frame, it uses the difference in head rotation to warp the frame rendered by the app to account for the change in head rotation. This can reduce latency.

This is an experimental feature, and is disabled by default.

Parameters
enabled trueto enable EDS,falseto disable it.

public voidsetGyroBiasEstimationEnabled(boolean enabled)

Enables or disables the use of gyroscope bias estimation for head tracking.

Gyroscopes often exhibit a bias, meaning that they don't return zero values when at rest. This can lead to spurious drift in head tracking. When gyroscope bias estimation is enabled, the framework will constantly attempt to estimate the gyroscope bias. This bias is then subtracted from the raw gyroscope values to reduce unwanted drift in head tracking. Note that gyroscope bias estimation is enabled by default.

Parameters
enabled whether gyroscope bias estimation should be enabled.

public voidsetNeckModelEnabled(boolean enabled)

Fully enables or disables use of the neck model for head tracking.

The neck model simulates how head rotations naturally happen relative to the base of the neck, not around the midpoint between the eyes, causing translational viewpoint movement in addition to rotation.

Parameters
enabled trueto enable the neck model,falseto disable. It is equivalent to calling setNeckModelFactor(enabled ? 1.0 : 0.0).

public voidsetNeckModelFactor(float factor)

Sets the neck model factor for head tracking.

Refer to {link #setNeckModelEnabled()} for more detail on neck model.

Parameters
factor Neck model factor between 0.0f and 1.0f. Set factor to 0.0f will completely disable the neck model, and 1.0f will completely activate the neck model. Value beturn 0.0f and 1.0f will partially use the neck model by linear interpolating the full neck model and no neck model according to the factor value.

public voidsetOnCardboardTriggerListener(Runnablelistener)

Sets a runnable that gets called back whenever a Cardboard trigger event occurs.

This is only useful if you're not usingCardboardActivityand want to handle trigger events at theCardboardViewlevel. If you're usingCardboardActivity, then it's recommended to use the onCardboardTrigger method fromCardboardActivityinstead of using this function.

Parameters
listener Runnable that gets called back whenever a Cardboard trigger event occurs.

public voidsetRenderer(CardboardView.Rendererrenderer)

Sets a renderer that handles all stereoscoping rendering details by itself.

Only one renderer should be set during the entire lifetime of this object. See theRendererinterface for details.

Parameters
renderer Renderer to set. Cannot benull.

public voidsetRenderer(CardboardView.StereoRendererrenderer)

Sets a renderer that delegates all details about stereoscopic rendering to the view.

Only one renderer should be set during the entire lifetime of this object. See theStereoRendererinterface for details.

Parameters
renderer Stereo renderer to set.

public voidsetRestoreGLStateEnabled(boolean enabled)

Enables or disables restoration of the application's GL state after postprocessing.

CardboardView may perform certain postprocessing steps at the end of each frame. For example, application imagery might be rendered into a texture instead of on-screen. If this flag is enabled, the framework ensures that the GL state at the beginning of the next frame is equivalent to the GL state at the end of the last frame. Enabled by default.

If disabled, applications may gain a performance boost but can't make any assumptions about the following subset of the GL state machine at the beginning of each frame:

  • Viewport
  • Clear color
  • Active texture unit
  • Shader program that is being used
  • Vertex attributes (pointers and whether or not they are enabled)
  • Whether GL_CULL_FACE and GL_SCISSOR_TEST are enabled
  • Bindings for GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER
  • Binding for GL_TEXTURE_2D in texture unit 0

There are two exceptions: 1. The currently bound frame buffer will always be restored, regardless of the state of this setting. 2. Vertex attribute bindings are never restored. Any calls to glVertexAttribPointer at the end of last frame will not be in effect anymore at the beginning of next frame.

Parameters
enabled trueto enable GL state restoration,falseto disable.

public voidsetSettingsButtonEnabled(boolean enabled)

Enables or disables drawing a settings button at the bottom center of the screen. Tapping the button sends the user to the Google Cardboard app where they can configure user parameters and Cardboard viewer parameters. The configuration will automatically apply to all of the user's apps that are using the vrtoolkit.

Only applies when VR mode is enabled.

Parameters
enabled trueto enable drawing the settings button,falseto disable.

public voidsetVRModeEnabled(boolean enabled)

Enables or disables VR rendering mode.

Controls stereo rendering and distortion correction. Enabled by default. Changes will be effective from the first frame after this call.

If disabled, no interpupillary distance will be applied to the eye transformations, automatic distortion correction will not take place, field of view and perspective may look off especially if the view is not set to fullscreen. Changes will be applied to the next frames being drawn.

See the documentation of theRendererandStereoRendererinterfaces for details on how they are affected by VR mode.

Parameters
enabled trueto enable VR mode,falseto disable.

public voidsetVignetteEnabled(boolean enabled)

Enables or disables vignetting around the frame edge.

If this flag is enabled, the distortion shader applies a darkening effect to the edges of the visible viewport, simulating vignetting.

Enabled by default.

Parameters
enabled trueto enable vignette effect,falseto disable.

public voidundistortTexture(int inputTexture)

Undistorts the provided texture by rendering into the current output buffer.

This method is designed for API users that have their own rendering loop and cannot use the standardCardboardView.RendererandCardboardView.StereoRendererinterfaces. Its use is discouraged for other purposes.

If a renderer has been set, texture undistortion will take place in the renderer thread. Otherwise the operation will happen in the calling thread. It is the responsibility of the caller to ensure the validity of the texture in the GL context of the thread where is used.

Parameters
inputTexture Texture name to undistort.

public voidupdateCardboardDeviceParams(CardboardDeviceParamscardboardDeviceParams)

Updates the physical parameters of the Cardboard device used for rendering.

Changes will be effective from the first frame after this call.

Parameters
cardboardDeviceParams Physical parameters of a Cardboard-compatible device. Ignores the request if the object is null or same as current.

public voidupdateScreenParams(ScreenParamsscreenParams)

Updates the screen parameters used for rendering.

Updates the screen parameters of the device inserted in the Cardboard. Changes will be effective from the first frame after this call.

Parameters
screenParams Parameters to update. Ignored if null.

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)Studio报错:Ignoring unkno
  2. Android存储数据到本地文件
  3. 默认不弹出输入面板
  4. Android(安卓)Tutorial: Optimizing for
  5. 一个简单的Android(安卓)自定义view,实现
  6. android中处理各种触摸事件
  7. Android画图Path的使用
  8. Android开发日记 --(1)Android系统开发环境
  9. Android: Android(安卓)Resources
  10. Android(安卓)textView字间距自定义Lette