public void onUpdate() { distanceToAnchorPoint = Math.abs(getTransform().getPositionY() - Y_ANCHOR_POINT); if (distanceToAnchorPoint <= Y_ANCHOR_POINT_THRESHOLD) { this.heightSyncLocked = true; } GVREyePointeeHolder[] eyePointeeHolders = GVRPicker.pickScene(getGVRContext().getMainScene()); float[] lookAt = getGVRContext().getMainScene().getMainCameraRig().getLookAt(); deltaY = lookAt[1] - lastY; lastY = lookAt[1]; onFocus = false; for (GVREyePointeeHolder eph : eyePointeeHolders) { if (eph.getOwnerObject().hashCode() == hashCode()) { onFocus = true; } } }
@Override public void onStep() { FPSCounter.tick(); boolean isButtonDown = mIsButtonDown; boolean isSingleTapped = mIsSingleTapped; mIsButtonDown = false; mIsSingleTapped = false; if (isButtonDown) mGVRContext.getMainScene().getMainCameraRig().resetYaw(); // ---------------------------------------thumbnail motion boolean MoveActive = false; if (Math.abs( ThumbnailTargetPosition[ThumbnailTargetIndex[0]][0] - ThumbnailCurrentPosition[0][0]) < 0.2f) MoveActive = true; if (SelectionActive && MoveActive) { if (ThumbnailCurrentPosition[ThumbnailSelected][0] < -0.5f) { for (int i = 0; i < THUMBNAIL_NUM; i++) { ThumbnailTargetIndex[i]++; if (ThumbnailTargetIndex[i] >= THUMBNAIL_NUM) ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] - THUMBNAIL_NUM; if (ThumbnailTargetIndex[i] < 0) ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] + THUMBNAIL_NUM; } } else if (ThumbnailCurrentPosition[ThumbnailSelected][0] > 0.5f) { for (int i = 0; i < THUMBNAIL_NUM; i++) { ThumbnailTargetIndex[i]--; if (ThumbnailTargetIndex[i] >= THUMBNAIL_NUM) ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] - THUMBNAIL_NUM; if (ThumbnailTargetIndex[i] < 0) ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] + THUMBNAIL_NUM; } } } for (int i = 0; i < THUMBNAIL_NUM; i++) { float speed = 0.08f; for (int j = 0; j < 3; j++) ThumbnailCurrentPosition[i][j] += speed * (ThumbnailTargetPosition[ThumbnailTargetIndex[i]][j] - ThumbnailCurrentPosition[i][j]); ThumbnailObject[i] .getTransform() .setPosition( ThumbnailCurrentPosition[i][0], ThumbnailCurrentPosition[i][1], ThumbnailCurrentPosition[i][2]); } // if( // Math.abs(ThumbnailTargetPosition[ThumbnailTargetIndex[0]][0]-ThumbnailCurrentPosition[0][0]) // > 0.02f ) // { // if( THUMBNAIL_ROT > 180.0f ) // THUMBNAIL_ROT += 0.05f*( 360.0f - THUMBNAIL_ROT ); // else // THUMBNAIL_ROT += 0.05f*( 0.0f - THUMBNAIL_ROT ); // } // else // { // THUMBNAIL_ROT += -1.0f; // if( THUMBNAIL_ROT > 360.0f ) THUMBNAIL_ROT = THUMBNAIL_ROT - 360.0f; // } THUMBNAIL_ROT = -1.0f; for (int i = 0; i < THUMBNAIL_NUM; i++) ThumbnailRotation[i].getTransform().rotateByAxis(THUMBNAIL_ROT, 0.0f, 1.0f, 0.0f); // ---------------------------------------object motion OBJECT_ROT = -1.0f; for (int i = 0; i < THUMBNAIL_NUM; i++) Objects[i].getTransform().rotateByAxis(OBJECT_ROT, 0.0f, 1.0f, 0.0f); float[] light = new float[4]; light[0] = 6.0f; light[1] = 10.0f; light[2] = 10.0f; light[3] = 1.0f; float[] eye = new float[4]; eye[0] = 0.0f; eye[1] = 0.0f; eye[2] = 3.0f * EYE_TO_OBJECT; eye[3] = 1.0f; float[] matT = ThumbnailRotation[0].getTransform().getModelMatrix(); float[] matO = Objects[ThumbnailSelected].getTransform().getModelMatrix(); // ---------------------------- watch, jar float x = matO[0] * light[0] + matO[1] * light[1] + matO[2] * light[2] + matO[3] * light[3]; float y = matO[4] * light[0] + matO[5] * light[1] + matO[6] * light[2] + matO[7] * light[3]; float z = matO[8] * light[0] + matO[9] * light[1] + matO[10] * light[2] + matO[11] * light[3]; float mag = (float) Math.sqrt(x * x + y * y + z * z); mMetalMaterial.setVec3(MetalOnlyShader.LIGHT_KEY, x / mag, y / mag, z / mag); mDiffuseMaterial.setVec3(DiffuseShader.LIGHT_KEY, x / mag, y / mag, z / mag); mGlassMaterial.setVec3(GlassShader.LIGHT_KEY, x / mag, y / mag, z / mag); mPhongMaterial.setVec3(PhongShader.LIGHT_KEY, x / mag, y / mag, z / mag); x = matO[0] * eye[0] + matO[1] * eye[1] + matO[2] * eye[2] + matO[3] * eye[3]; y = matO[4] * eye[0] + matO[5] * eye[1] + matO[6] * eye[2] + matO[7] * eye[3]; z = matO[8] * eye[0] + matO[9] * eye[1] + matO[10] * eye[2] + matO[11] * eye[3]; mag = (float) Math.sqrt(x * x + y * y + z * z); mMetalMaterial.setVec3(MetalOnlyShader.EYE_KEY, x / mag, y / mag, z / mag); mDiffuseMaterial.setVec3(DiffuseShader.EYE_KEY, x / mag, y / mag, z / mag); mGlassMaterial.setVec3(GlassShader.EYE_KEY, x / mag, y / mag, z / mag); mPhongMaterial.setVec3(PhongShader.EYE_KEY, x / mag, y / mag, z / mag); // ---------------------------- robot mRobotHeadMaterial.setVec4(PhongShader3.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mRobotHeadMaterial.setVec4(PhongShader3.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mRobotHeadMaterial.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mRobotHeadMaterial.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mRobotHeadMaterial.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]); mRobotHeadMaterial.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]); mRobotMetalMaterial.setVec4(MetalShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mRobotMetalMaterial.setVec4(MetalShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mRobotMetalMaterial.setVec4(MetalShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mRobotMetalMaterial.setVec4(MetalShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mRobotMetalMaterial.setVec3(MetalShader2.LIGHT_KEY, light[0], light[1], light[2]); mRobotMetalMaterial.setVec3(MetalShader2.EYE_KEY, eye[0], eye[1], eye[2]); mRobotBodyMaterial.setVec4(PhongShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mRobotBodyMaterial.setVec4(PhongShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mRobotBodyMaterial.setVec4(PhongShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mRobotBodyMaterial.setVec4(PhongShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mRobotBodyMaterial.setVec3(PhongShader2.LIGHT_KEY, light[0], light[1], light[2]); mRobotBodyMaterial.setVec3(PhongShader2.EYE_KEY, eye[0], eye[1], eye[2]); mRobotRubberMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mRobotRubberMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mRobotRubberMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mRobotRubberMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mRobotRubberMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]); mRobotRubberMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]); // ---------------------------- leaf mLeafBodyMaterial.setVec4(MetalShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mLeafBodyMaterial.setVec4(MetalShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mLeafBodyMaterial.setVec4(MetalShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mLeafBodyMaterial.setVec4(MetalShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mLeafBodyMaterial.setVec3(MetalShader2.LIGHT_KEY, light[0], light[1], light[2]); mLeafBodyMaterial.setVec3(MetalShader2.EYE_KEY, eye[0], eye[1], eye[2]); mLeafBoxMaterial.setVec4(PhongShader3.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mLeafBoxMaterial.setVec4(PhongShader3.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mLeafBoxMaterial.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mLeafBoxMaterial.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mLeafBoxMaterial.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]); mLeafBoxMaterial.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]); // ---------------------------- car eye[0] = 4.0f; eye[1] = 0.0f; eye[2] = 3.0f * EYE_TO_OBJECT; eye[3] = 1.0f; mCarBodyMaterial.setVec4(PhongShader3.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarBodyMaterial.setVec4(PhongShader3.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarBodyMaterial.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarBodyMaterial.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarBodyMaterial.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]); mCarBodyMaterial.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]); mCarTireMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarTireMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarTireMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarTireMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarTireMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarTireMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarGlassMaterial.setVec4(GlassShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarGlassMaterial.setVec4(GlassShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarGlassMaterial.setVec4(GlassShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarGlassMaterial.setVec4(GlassShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarGlassMaterial.setVec3(GlassShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarGlassMaterial.setVec3(GlassShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarWheelMaterial.setVec4(MetalShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarWheelMaterial.setVec4(MetalShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarWheelMaterial.setVec4(MetalShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarWheelMaterial.setVec4(MetalShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarWheelMaterial.setVec3(MetalShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarWheelMaterial.setVec3(MetalShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarBackMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarBackMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarBackMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarBackMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarBackMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarBackMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarGrillMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarGrillMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarGrillMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarGrillMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarGrillMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarGrillMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarLightMaterial.setVec4(GlassShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarLightMaterial.setVec4(GlassShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarLightMaterial.setVec4(GlassShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarLightMaterial.setVec4(GlassShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarLightMaterial.setVec3(GlassShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarLightMaterial.setVec3(GlassShader2.EYE_KEY, eye[0], eye[1], eye[2]); mCarInsideMaterial.setVec4(PhongShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]); mCarInsideMaterial.setVec4(PhongShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]); mCarInsideMaterial.setVec4(PhongShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]); mCarInsideMaterial.setVec4(PhongShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]); mCarInsideMaterial.setVec3(PhongShader2.LIGHT_KEY, light[0], light[1], light[2]); mCarInsideMaterial.setVec3(PhongShader2.EYE_KEY, eye[0], eye[1], eye[2]); // ---------------------------- thumbnail glasses eye[0] = 0.0f; eye[1] = 0.0f; eye[2] = EYE_TO_OBJECT; eye[3] = 1.0f; mReflectionMaterial.setVec4(ReflectionShader.MAT1_KEY, matT[0], matT[4], matT[8], matT[12]); mReflectionMaterial.setVec4(ReflectionShader.MAT2_KEY, matT[1], matT[5], matT[9], matT[13]); mReflectionMaterial.setVec4(ReflectionShader.MAT3_KEY, matT[2], matT[6], matT[10], matT[14]); mReflectionMaterial.setVec4(ReflectionShader.MAT4_KEY, matT[3], matT[7], matT[11], matT[15]); mReflectionMaterial.setVec3(ReflectionShader.LIGHT_KEY, light[0], light[1], light[2]); mReflectionMaterial.setVec3(ReflectionShader.EYE_KEY, eye[0], eye[1], eye[2]); GVREyePointeeHolder pickedHolders[] = GVRPicker.pickScene(mGVRContext.getMainScene()); if (SelectionMode && pickedHolders.length > 0) { GVRSceneObject pickedObject = pickedHolders[0].getOwnerObject(); for (int i = 0; i < THUMBNAIL_NUM; ++i) if (ThumbnailObject[i].equals(pickedObject)) { ThumbnailSelected = i; break; } SelectionActive = true; } else SelectionActive = false; if (isSingleTapped) { SelectionMode = !SelectionMode; if (SelectionMode) { for (int i = 0; i < THUMBNAIL_NUM; ++i) { ThumbnailGlasses[i].setRenderMask(GVRRenderMaskBit.Left | GVRRenderMaskBit.Right); Thumbnails[i] .getRenderData() .setRenderMask(GVRRenderMaskBit.Left | GVRRenderMaskBit.Right); } for (int I = 0; I < THUMBNAIL_NUM; I++) for (int i = 0; i < Objects[I].getChildrenCount(); i++) Objects[I].getChildByIndex(i).getRenderData().setRenderMask(0); } else { for (int i = 0; i < THUMBNAIL_NUM; ++i) { ThumbnailGlasses[i].setRenderMask(0); Thumbnails[i].getRenderData().setRenderMask(0); } for (int I = 0; I < THUMBNAIL_NUM; I++) for (int i = 0; i < Objects[I].getChildrenCount(); i++) Objects[I].getChildByIndex(i).getRenderData().setRenderMask(0); for (int i = 0; i < Objects[ThumbnailSelected].getChildrenCount(); i++) Objects[ThumbnailSelected] .getChildByIndex(i) .getRenderData() .setRenderMask(GVRRenderMaskBit.Left | GVRRenderMaskBit.Right); } } }