use of gaiasky.vr.openvr.VRContext.VRDevice in project gaiasky by langurmonkey.
the class GaiaSky method createVR.
/**
* Attempt to create a VR context. This operation will only succeed if an HMD is connected
* and detected via OpenVR
*/
private VRStatus createVR() {
if (vr) {
// is not installed.
try {
// OpenVRQuery.queryOpenVr();
settings.runtime.openVr = true;
Constants.initialize(settings.scene.distanceScaleVr);
vrContext = new VRContext();
vrContext.pollEvents();
final VRDevice hmd = vrContext.getDeviceByType(VRDeviceType.HeadMountedDisplay);
logger.info("Initialization of VR successful");
if (hmd == null) {
logger.info("HMD device is null!");
} else {
logger.info("HMD device is not null: " + vrContext.getDeviceByType(VRDeviceType.HeadMountedDisplay).toString());
}
vrDeviceToModel = new HashMap<>();
if (settings.graphics.resolution[0] != vrContext.getWidth()) {
logger.info("Warning, resizing according to VRSystem values: [" + settings.graphics.resolution[0] + "x" + settings.graphics.resolution[1] + "] -> [" + vrContext.getWidth() + "x" + vrContext.getHeight() + "]");
// Do not resize the screen!
settings.graphics.backBufferResolution[1] = vrContext.getHeight();
settings.graphics.backBufferResolution[0] = vrContext.getWidth();
// this.resizeImmediate(vrContext.getWidth(), vrContext.getHeight(), true, true, true);
}
settings.graphics.vsync = false;
graphics.setWindowedMode(settings.graphics.resolution[0], settings.graphics.resolution[1]);
graphics.setVSync(settings.graphics.vsync);
vrLoadingLeftFb = new FrameBuffer(Format.RGBA8888, vrContext.getWidth(), vrContext.getHeight(), true);
vrLoadingLeftTex = org.lwjgl.openvr.Texture.create();
vrLoadingLeftTex.set(vrLoadingLeftFb.getColorBufferTexture().getTextureObjectHandle(), VR.ETextureType_TextureType_OpenGL, VR.EColorSpace_ColorSpace_Gamma);
vrLoadingRightFb = new FrameBuffer(Format.RGBA8888, vrContext.getWidth(), vrContext.getHeight(), true);
vrLoadingRightTex = org.lwjgl.openvr.Texture.create();
vrLoadingRightTex.set(vrLoadingRightFb.getColorBufferTexture().getTextureObjectHandle(), VR.ETextureType_TextureType_OpenGL, VR.EColorSpace_ColorSpace_Gamma);
// Sprite batch for VR - uses back buffer resolution
globalResources.setSpriteBatchVR(new SpriteBatch(500, globalResources.getSpriteShader()));
globalResources.getSpriteBatchVR().getProjectionMatrix().setToOrtho2D(0, 0, settings.graphics.backBufferResolution[0], settings.graphics.backBufferResolution[1]);
// Enable visibility of 'Others' if off (for VR controllers)
if (!settings.scene.visibility.get(ComponentType.Others.name())) {
EventManager.publish(Event.TOGGLE_VISIBILITY_CMD, this, "element.others", false);
}
return VRStatus.OK;
} catch (Exception e) {
// If initializing the VRContext failed
settings.runtime.openVr = false;
logger.error(e);
logger.error("Initialisation of VR context failed");
return VRStatus.ERROR_NO_CONTEXT;
}
} else {
// Desktop mode
settings.runtime.openVr = false;
Constants.initialize(settings.scene.distanceScaleDesktop);
}
return VRStatus.NO_VR;
}
use of gaiasky.vr.openvr.VRContext.VRDevice in project gaiasky by langurmonkey.
the class CrashReporter method appendSystemInfo.
private static void appendSystemInfo(Array<String> strArray) {
/* Gaia Sky info */
if (Settings.settings.version != null) {
strArray.add("");
strArray.add("## GAIA SKY INFORMATION");
strArray.add("Version: " + Settings.settings.version.version);
strArray.add("Build: " + Settings.settings.version.build);
strArray.add("Builder: " + Settings.settings.version.builder);
strArray.add("System: " + Settings.settings.version.system);
strArray.add("Build time: " + Settings.settings.version.buildTime);
}
/* Java info */
strArray.add("");
strArray.add("## JAVA INFORMATION");
strArray.add("Java version: " + System.getProperty("java.version"));
strArray.add("Java runtime name: " + System.getProperty("java.runtime.name"));
strArray.add("Java VM name: " + System.getProperty("java.vm.name"));
strArray.add("Java VM version: " + System.getProperty("java.vm.version"));
strArray.add("Java VM vendor: " + System.getProperty("java.vm.vendor"));
/* System information */
strArray.add("");
strArray.add("## SYSTEM INFORMATION");
try {
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
CentralProcessor cp = hal.getProcessor();
strArray.add("CPU: " + cp.getProcessorIdentifier().getName());
strArray.add(cp.getProcessorIdentifier().getIdentifier());
strArray.add("Proc ID: " + cp.getProcessorIdentifier().getProcessorID());
strArray.add("CPU Family: " + cp.getProcessorIdentifier().getFamily());
strArray.add(cp.getPhysicalPackageCount() + " physical CPU package(s)");
strArray.add(cp.getPhysicalProcessorCount() + " physical CPU core(s)");
int nLp = cp.getLogicalProcessorCount();
strArray.add(nLp + " logical CPU(s)");
} catch (Error e) {
strArray.add("Could not get CPU information!");
}
String mbUnits = " MB";
strArray.add("Java used memory: " + MemInfo.getUsedMemory() + mbUnits);
strArray.add("Java free memory: " + MemInfo.getFreeMemory() + mbUnits);
strArray.add("Java total memory: " + MemInfo.getTotalMemory() + mbUnits);
strArray.add("Java max memory (-Xmx): " + MemInfo.getMaxMemory() + mbUnits);
strArray.add("Total system RAM: " + MemInfo.getTotalRam() + mbUnits);
File[] roots = File.listRoots();
for (File root : roots) {
strArray.add(" # File system root: " + root.getAbsolutePath());
strArray.add(" Total space: " + (root.getTotalSpace() * Constants.BYTE_TO_MB) + mbUnits);
strArray.add(" Free space: " + (root.getFreeSpace() * Constants.BYTE_TO_MB) + mbUnits);
strArray.add(" Usable space: " + (root.getUsableSpace() * Constants.BYTE_TO_MB) + mbUnits);
}
/* OS info */
strArray.add("");
strArray.add("## OS INFORMATION");
try {
SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
strArray.add("OS name: " + os.toString());
strArray.add("OS version: " + System.getProperty("os.version"));
strArray.add("OS architecture: " + System.getProperty("os.arch"));
strArray.add("Booted: " + Instant.ofEpochSecond(os.getSystemBootTime()));
strArray.add("Uptime: " + FormatUtil.formatElapsedSecs(si.getOperatingSystem().getSystemUptime()));
} catch (Exception e) {
strArray.add("OS name: " + System.getProperty("os.name"));
strArray.add("OS version: " + System.getProperty("os.version"));
strArray.add("OS architecture: " + System.getProperty("os.arch"));
}
try {
/* GL info */
strArray.add("");
strArray.add("## GL INFORMATION");
strArray.add("Graphcis device: " + Gdx.gl.glGetString(GL20.GL_RENDERER));
strArray.add("GL vendor: " + Gdx.gl.glGetString(GL20.GL_VENDOR));
strArray.add("GL version: " + Gdx.gl.glGetString(GL20.GL_VERSION));
strArray.add("GLSL version: " + Gdx.gl.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
String extensions = Gdx.gl.glGetString(GL20.GL_EXTENSIONS);
IntBuffer buf = BufferUtils.newIntBuffer(16);
if (extensions == null || extensions.isEmpty()) {
Gdx.gl.glGetIntegerv(GL30.GL_NUM_EXTENSIONS, buf);
int next = buf.get(0);
String[] extensionsString = new String[next];
for (int i = 0; i < next; i++) {
extensionsString[i] = Gdx.gl30.glGetStringi(GL30.GL_EXTENSIONS, i);
}
extensions = TextUtils.arrayToStr(extensionsString, "", "", " ");
}
strArray.add("GL extensions: " + extensions);
Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_SIZE, buf);
int maxSize = buf.get(0);
strArray.add("GL max texture size: " + maxSize);
} catch (Exception e) {
strArray.add("## GL INFORMATION not available");
}
if (Settings.settings.runtime.openVr) {
VRContext vrContext = GaiaSky.instance.vrContext;
if (vrContext != null) {
/* VR info **/
strArray.add("");
strArray.add("## VR INFORMATION");
strArray.add("VR resolution: " + vrContext.getWidth() + "x" + vrContext.getHeight());
Array<VRDevice> devices = vrContext.getDevices();
for (VRDevice device : devices) {
strArray.add("Device: " + device.renderModelName);
strArray.add(" Model number: " + device.modelNumber);
strArray.add(" Manufacturer: " + device.manufacturerName);
strArray.add(" Role: " + device.getControllerRole());
strArray.add(" Type: " + device.getType());
strArray.add(" Index: " + (device.getPose() != null ? device.getPose().getIndex() : "null"));
}
}
}
}
use of gaiasky.vr.openvr.VRContext.VRDevice in project gaiasky by langurmonkey.
the class SGROpenVR method notify.
@Override
public void notify(final Event event, Object source, final Object... data) {
switch(event) {
case VR_DEVICE_CONNECTED:
VRDevice device = (VRDevice) data[0];
if (device.getType() == VRDeviceType.Controller) {
GaiaSky.postRunnable(() -> addVRController(device));
}
break;
case VR_DEVICE_DISCONNECTED:
device = (VRDevice) data[0];
if (device.getType() == VRDeviceType.Controller) {
GaiaSky.postRunnable(() -> removeVRController(device));
}
break;
case UI_SCALE_CMD:
sb.getProjectionMatrix().setToOrtho2D(0, 0, Settings.settings.graphics.backBufferResolution[0] * Settings.settings.program.ui.scale, Settings.settings.graphics.backBufferResolution[1] * Settings.settings.program.ui.scale);
initializeVRGUI((Lwjgl3Graphics) Gdx.graphics);
break;
default:
break;
}
}
use of gaiasky.vr.openvr.VRContext.VRDevice in project gaiasky by langurmonkey.
the class SGROpenVR method updateCamera.
private void updateCamera(NaturalCamera cam, PerspectiveCamera camera, int eye, boolean updateFrustum, RenderingContext rc) {
// get the projection matrix from the HDM
VRSystem.VRSystem_GetProjectionMatrix(eye, camera.near, camera.far, projectionMat);
VRContext.hmdMat4toMatrix4(projectionMat, camera.projection);
// get the eye space matrix from the HDM
VRSystem.VRSystem_GetEyeToHeadTransform(eye, eyeMat);
VRContext.hmdMat34ToMatrix4(eyeMat, eyeSpace);
invEyeSpace.set(eyeSpace).inv();
// get the pose matrix from the HDM
VRDevice hmd = vrContext.getDeviceByType(VRDeviceType.HeadMountedDisplay);
Vector3 up = hmd.getUp(Space.Tracker);
Vector3 dir = hmd.getDirection(Space.Tracker);
Vector3 pos = hmd.getPosition(Space.Tracker);
// Update main camera
if (cam != null) {
cam.vrOffset.set(pos).scl(Constants.M_TO_U);
cam.direction.set(dir);
cam.up.set(up);
rc.vrOffset = cam.vrOffset;
}
// Update Eye camera
camera.viewportWidth = rc.w();
camera.viewportHeight = rc.h();
camera.view.idt();
camera.view.setToLookAt(pos, auxf1.set(pos).add(dir), up);
camera.combined.set(camera.projection);
Matrix4.mul(camera.combined.val, invEyeSpace.val);
Matrix4.mul(camera.combined.val, camera.view.val);
if (updateFrustum) {
camera.invProjectionView.set(camera.combined);
Matrix4.inv(camera.invProjectionView.val);
camera.frustum.update(camera.invProjectionView);
}
}
Aggregations