1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-04-22 03:51:58 +02:00

fix touch controls transparency; hide touch controls on keyboard or gamepad keypress; fix title screen for VR

This commit is contained in:
XProger 2018-04-16 04:38:27 +03:00
parent 1c16d55eb9
commit f2bcbd341d
7 changed files with 92 additions and 53 deletions

View File

@ -83,7 +83,10 @@ namespace Input {
}
down[key] = value;
if (value && key <= ikZ) lastKey = key;
if (value && key <= ikZ) {
lastKey = key;
touchTimerVis = 0.0f;
}
}
void setPos(InputKey key, const vec2 &pos) {
@ -107,7 +110,10 @@ namespace Input {
joy[index].down[key] = value;
if (value) joy[index].lastKey = key;
if (value) {
joy[index].lastKey = key;
touchTimerVis = 0.0f;
}
}
void setJoyPos(int index, JoyKey key, const vec2 &pos) {
@ -216,7 +222,7 @@ namespace Input {
btnPos[bJump] = center + vec2(cosf(-PI * 0.5f), sinf(-PI * 0.5f)) * radius;
btnPos[bAction] = center + vec2(cosf(-PI * 3.0f / 4.0f), sinf(-PI * 3.0f / 4.0f)) * radius;
btnPos[bWalk] = center + vec2(cosf(-PI), sinf(-PI)) * radius;
btnPos[bInventory] = vec2(Core::width - btnRadius * 2.0f, btnRadius * 2.0f);
btnPos[bInventory] = vec2(Core::width - btnRadius * 8.0f, btnRadius * 4.0f);
// touch update
Joystick &joy = Input::joy[Core::settings.controls[0].joyIndex];

View File

@ -680,7 +680,7 @@ struct Inventory {
index = targetIndex = pageItemIndex[page];
head = Input::hmd.head.inverseOrtho();
head.e00 = INF; // mark head matrix as unset
//if (type == TR::Entity::INV_PASSPORT) // toggle after death
// chooseItem();
@ -773,13 +773,29 @@ struct Inventory {
#endif
break;
case TR::VER_TR2 :
#ifdef __EMSCRIPTEN__
passportSlotCount = 2;
passportSlots[0] = TR::LVL_TR2_WALL;
passportSlots[1] = TR::LVL_TR2_BOAT;
#else
passportSlotCount = 0;
for (int i = TR::LVL_TR2_WALL; i <= TR::LVL_TR2_HOUSE; i++)
if (!TR::isCutsceneLevel(TR::LevelID(i))) {
passportSlots[passportSlotCount++] = TR::LevelID(i);
}
#endif
break;
case TR::VER_TR3 :
#ifdef __EMSCRIPTEN__
passportSlotCount = 1;
passportSlots[0] = TR::LVL_TR3_JUNGLE;
#else
passportSlotCount = 0;
for (int i = TR::LVL_TR3_JUNGLE; i <= TR::LVL_TR3_STPAUL; i++)
if (!TR::isCutsceneLevel(TR::LevelID(i))) {
passportSlots[passportSlotCount++] = TR::LevelID(i);
}
#endif
break;
default : ASSERT(false);
}
@ -1292,11 +1308,18 @@ struct Inventory {
}
void renderTitleBG() {
float aspectSrc = float(background[0]->origWidth) / float(background[0]->origHeight);
float aspectDst = float(Core::width) / float(Core::height);
float aspectImg = aspectSrc / aspectDst;
float ax = background[0]->origWidth / float(background[0]->width);
float ay = background[0]->origHeight / float(background[0]->height);
float aspectSrc, aspectDst, aspectImg, ax, ay;
if (background[0]) {
aspectSrc = float(background[0]->origWidth) / float(background[0]->origHeight);
aspectDst = float(Core::width) / float(Core::height);
ax = background[0]->origWidth / float(background[0]->width);
ay = background[0]->origHeight / float(background[0]->height);
} else {
aspectSrc = ax = ay = 1.0f;
aspectDst = float(Core::width) / float(Core::height);
}
aspectImg = aspectSrc / aspectDst;
#ifdef FFP
mat4 m;
@ -1382,7 +1405,14 @@ struct Inventory {
vertices[11].texCoord = short4(0, 0, 0, 0);
game->setShader(Core::passFilter, Shader::DEFAULT, false, false);
background[0]->bind(sDiffuse);
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR || !background[0]) {
for (int i = 0; i < 4; i++)
vertices[i].light.x = vertices[i].light.y = vertices[i].light.z = 0;
Core::whiteTex->bind(sDiffuse); // black background
} else
background[0]->bind(sDiffuse);
game->getMesh()->renderBuffer(indices, COUNT(indices), vertices, COUNT(vertices));
}
@ -1396,26 +1426,21 @@ struct Inventory {
vertices[1].coord = short4( 32767, 32767, 0, 0);
vertices[2].coord = short4( 32767, -32767, 0, 0);
vertices[3].coord = short4(-32767, -32767, 0, 0);
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR) {
vertices[0].light =
vertices[1].light =
vertices[2].light =
vertices[3].light = ubyte4(0, 0, 0, uint8(phaseRing * 255));
} else {
vertices[0].light =
vertices[1].light =
vertices[2].light =
vertices[3].light = ubyte4(255, 255, 255, uint8(phaseRing * 255));
}
vertices[0].light =
vertices[1].light =
vertices[2].light =
vertices[3].light = ubyte4(255, 255, 255, uint8(phaseRing * 255));
vertices[0].texCoord = short4( 0, 32767, 0, 0);
vertices[1].texCoord = short4(32767, 32767, 0, 0);
vertices[2].texCoord = short4(32767, 0, 0, 0);
vertices[3].texCoord = short4( 0, 0, 0, 0);
game->setShader(Core::passFilter, Shader::DEFAULT, false, false);
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR)
Core::whiteTex->bind(sDiffuse); // black background
else
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR || !background[0]) {
for (int i = 0; i < 4; i++)
vertices[i].light.x = vertices[i].light.y = vertices[i].light.z = 0;
Core::whiteTex->bind(sDiffuse); // black background
} else
background[0]->bind(sDiffuse); // blured grayscale image
Core::setBlending(phaseRing < 1.0f ? bmAlpha : bmNone);
@ -1429,19 +1454,15 @@ struct Inventory {
Core::setDepthTest(false);
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR) {
if (game->getLevel()->isTitle()) {
if (background[0]) {
renderTitleBG();
}
} else
if (game->getLevel()->isTitle())
renderTitleBG();
else
renderGameBG();
} else {
if (background[0]) {
if (background[1])
renderGameBG();
else
renderTitleBG();
}
if (background[1])
renderGameBG();
else
renderTitleBG();
}
Core::setBlending(bmAlpha);
@ -1465,8 +1486,12 @@ struct Inventory {
Core::mViewInv = mat4(pos, pos + vec3(0, 0, 1), vec3(0, -1, 0));
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR)
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR) {
if (head.e00 == INF)
head = Input::hmd.head.inverseOrtho();
Core::mViewInv = Core::mViewInv * head * Input::hmd.eye[Core::eye == -1.0f ? 0 : 1];
} else
head.e00 = INF;
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR)
Core::mProj = Input::hmd.proj[Core::eye == -1.0f ? 0 : 1];

View File

@ -88,6 +88,9 @@ JNI_METHOD(void, nativeFrameBegin)(JNIEnv* env) {
}
JNI_METHOD(void, nativeFrameEnd)(JNIEnv* env) {
Core::setBlending(bmNone);
Core::validateRenderState();
Game::frameEnd();
Core::reset();
}

View File

@ -23,6 +23,7 @@ import com.google.vr.sdk.base.GvrActivity;
import com.google.vr.sdk.base.GvrView;
import com.google.vr.sdk.base.HeadTransform;
import com.google.vr.sdk.base.Viewport;
import android.app.Activity;
public class MainActivity extends GvrActivity implements OnTouchListener, OnKeyListener, OnGenericMotionListener {
static GvrView gvrView;
@ -34,17 +35,22 @@ public class MainActivity extends GvrActivity implements OnTouchListener, OnKeyL
gvrView.setStereoModeEnabled(enable);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
super.onCreate(savedInstanceState);
//GLSurfaceView view = new GLSurfaceView(this);
@ -62,9 +68,8 @@ public class MainActivity extends GvrActivity implements OnTouchListener, OnKeyL
view.setOnKeyListener(this);
view.setTransitionViewEnabled(false);
if (view.setAsyncReprojectionEnabled(true)) {
AndroidCompat.setSustainedPerformanceMode(this, true);
}
// if (view.setAsyncReprojectionEnabled(true))
// AndroidCompat.setSustainedPerformanceMode(this, true);
//AndroidCompat.setVrModeEnabled(this, false);
view.setStereoModeEnabled(false);

View File

@ -18,7 +18,7 @@ varying vec4 vColor;
void main() {
vTexCoord = aTexCoord.xy;
vColor = aLight;
vColor = aLight * uMaterial;
gl_Position = uViewProj * vec4(aCoord.xy * uPosScale.zw + uPosScale.xy, 0.0, 1.0);
}
#else

View File

@ -306,9 +306,9 @@ uniform vec4 uMaterial; // x - diffuse, y - ambient, z - specular, w - alpha
p.xy = p.xy * vec2(0.25, 0.5) + tileOffset;
float rShadow =(SHADOW(SHADOW_TEXEL * vec3(-0.5, -0.5, 0.0) + p) +
SHADOW(SHADOW_TEXEL * vec3( 0.5, -0.5, 0.0) + p) +
SHADOW(SHADOW_TEXEL * vec3(-0.5, 0.5, 0.0) + p) +
float rShadow =(SHADOW(SHADOW_TEXEL * vec3(-0.5, -0.5, 0.0) + p) +
SHADOW(SHADOW_TEXEL * vec3( 0.5, -0.5, 0.0) + p) +
SHADOW(SHADOW_TEXEL * vec3(-0.5, 0.5, 0.0) + p) +
SHADOW(SHADOW_TEXEL * vec3( 0.5, 0.5, 0.0) + p)) * 0.25;
float fade = clamp(dot(vLightVec.xyz, vLightVec.xyz), 0.0, 1.0);

View File

@ -477,7 +477,7 @@ namespace UI {
void renderControl(const vec2 &pos, float size, bool active) {
Core::active.shader->setParam(uPosScale, vec4(pos, vec2(size * (active ? 2.0f : 1.0f) / 32767.0f)));
Core::active.shader->setParam(uMaterial, vec4(active ? 0.7f : 0.5f));
Core::active.shader->setParam(uMaterial, vec4(1.0f, 1.0f, 1.0f, active ? 0.7f : 0.5f));
game->getMesh()->renderCircle();
}