code stringlengths 73 34.1k | label stringclasses 1 value |
|---|---|
public IntervalFrequency getRefreshFrequency() {
switch (mRefreshInterval) {
case REALTIME_REFRESH_INTERVAL:
return IntervalFrequency.REALTIME;
case HIGH_REFRESH_INTERVAL:
return IntervalFrequency.HIGH;
case LOW_REFRESH_INTERVAL:
return IntervalFrequency.LOW;
case MEDIUM_REFRESH_INTERVAL:
return IntervalFrequency.MEDIUM;
default:
return IntervalFrequency.NONE;
}
} | java |
private float[] generateParticleVelocities()
{
float velocities[] = new float[mEmitRate * 3];
for ( int i = 0; i < mEmitRate * 3; i +=3 )
{
Vector3f nexVel = getNextVelocity();
velocities[i] = nexVel.x;
velocities[i+1] = nexVel.y;
velocities[i+2] = nexVel.z;
}
return velocities;
} | java |
private float[] generateParticleTimeStamps(float totalTime)
{
float timeStamps[] = new float[mEmitRate * 2];
for ( int i = 0; i < mEmitRate * 2; i +=2 )
{
timeStamps[i] = totalTime + mRandom.nextFloat();
timeStamps[i + 1] = 0;
}
return timeStamps;
} | java |
public static WidgetLib init(GVRContext gvrContext, String customPropertiesAsset)
throws InterruptedException, JSONException, NoSuchMethodException {
if (mInstance == null) {
// Constructor sets mInstance to ensure the initialization order
new WidgetLib(gvrContext, customPropertiesAsset);
}
return mInstance.get();
} | java |
public void BuildInteractiveObjectFromAnchor(Sensor anchorSensor, String anchorDestination) {
InteractiveObject interactiveObject = new InteractiveObject();
interactiveObject.setSensor(anchorSensor, anchorDestination);
interactiveObjects.add(interactiveObject);
} | java |
private void RunScript(InteractiveObject interactiveObject, String functionName, Object[] parameters) {
boolean complete = false;
if ( V8JavaScriptEngine) {
GVRJavascriptV8File gvrJavascriptV8File = interactiveObject.getScriptObject().getGVRJavascriptV8File();
String paramString = "var params =[";
for (int i = 0; i < parameters.length; i++ ) {
paramString += (parameters[i] + ", ");
}
paramString = paramString.substring(0, (paramString.length()-2)) + "];";
final GVRJavascriptV8File gvrJavascriptV8FileFinal = gvrJavascriptV8File;
final InteractiveObject interactiveObjectFinal = interactiveObject;
final String functionNameFinal = functionName;
final Object[] parametersFinal = parameters;
final String paramStringFinal = paramString;
gvrContext.runOnGlThread(new Runnable() {
@Override
public void run() {
RunScriptThread (gvrJavascriptV8FileFinal, interactiveObjectFinal, functionNameFinal, parametersFinal, paramStringFinal);
}
});
} // end V8JavaScriptEngine
else {
// Mozilla Rhino engine
GVRJavascriptScriptFile gvrJavascriptFile = interactiveObject.getScriptObject().getGVRJavascriptScriptFile();
complete = gvrJavascriptFile.invokeFunction(functionName, parameters);
if (complete) {
// The JavaScript (JS) ran. Now get the return
// values (saved as X3D data types such as SFColor)
// stored in 'localBindings'.
// Then call SetResultsFromScript() to set the GearVR values
Bindings localBindings = gvrJavascriptFile.getLocalBindings();
SetResultsFromScript(interactiveObject, localBindings);
} else {
Log.e(TAG, "Error in SCRIPT node '" + interactiveObject.getScriptObject().getName() +
"' running Rhino Engine JavaScript function '" + functionName + "'");
}
}
} | java |
public Quaternionf ConvertDirectionalVectorToQuaternion(Vector3f d) {
d.negate();
Quaternionf q = new Quaternionf();
// check for exception condition
if ((d.x == 0) && (d.z == 0)) {
// exception condition if direction is (0,y,0):
// straight up, straight down or all zero's.
if (d.y > 0) { // direction straight up
AxisAngle4f angleAxis = new AxisAngle4f(-(float) Math.PI / 2, 1, 0,
0);
q.set(angleAxis);
} else if (d.y < 0) { // direction straight down
AxisAngle4f angleAxis = new AxisAngle4f((float) Math.PI / 2, 1, 0, 0);
q.set(angleAxis);
} else { // All zero's. Just set to identity quaternion
q.identity();
}
} else {
d.normalize();
Vector3f up = new Vector3f(0, 1, 0);
Vector3f s = new Vector3f();
d.cross(up, s);
s.normalize();
Vector3f u = new Vector3f();
d.cross(s, u);
u.normalize();
Matrix4f matrix = new Matrix4f(s.x, s.y, s.z, 0, u.x, u.y, u.z, 0, d.x,
d.y, d.z, 0, 0, 0, 0, 1);
q.setFromNormalized(matrix);
}
return q;
} | java |
public static void count() {
long duration = SystemClock.uptimeMillis() - startTime;
float avgFPS = sumFrames / (duration / 1000f);
Log.v("FPSCounter",
"total frames = %d, total elapsed time = %d ms, average fps = %f",
sumFrames, duration, avgFPS);
} | java |
public static void startCheck(String extra) {
startCheckTime = System.currentTimeMillis();
nextCheckTime = startCheckTime;
Log.d(Log.SUBSYSTEM.TRACING, "FPSCounter" , "[%d] startCheck %s", startCheckTime, extra);
} | java |
public static void timeCheck(String extra) {
if (startCheckTime > 0) {
long now = System.currentTimeMillis();
long diff = now - nextCheckTime;
nextCheckTime = now;
Log.d(Log.SUBSYSTEM.TRACING, "FPSCounter", "[%d, %d] timeCheck: %s", now, diff, extra);
}
} | java |
public void animate(GVRHybridObject object, float animationTime)
{
GVRMeshMorph morph = (GVRMeshMorph) mTarget;
mKeyInterpolator.animate(animationTime * mDuration, mCurrentValues);
morph.setWeights(mCurrentValues);
} | java |
public synchronized void addRange(final float range, final GVRSceneObject sceneObject)
{
if (null == sceneObject) {
throw new IllegalArgumentException("sceneObject must be specified!");
}
if (range < 0) {
throw new IllegalArgumentException("range cannot be negative");
}
final int size = mRanges.size();
final float rangePow2 = range*range;
final Object[] newElement = new Object[] {rangePow2, sceneObject};
for (int i = 0; i < size; ++i) {
final Object[] el = mRanges.get(i);
final Float r = (Float)el[0];
if (r > rangePow2) {
mRanges.add(i, newElement);
break;
}
}
if (mRanges.size() == size) {
mRanges.add(newElement);
}
final GVRSceneObject owner = getOwnerObject();
if (null != owner) {
owner.addChildObject(sceneObject);
}
} | java |
public void onDrawFrame(float frameTime) {
final GVRSceneObject owner = getOwnerObject();
if (owner == null) {
return;
}
final int size = mRanges.size();
final GVRTransform t = getGVRContext().getMainScene().getMainCameraRig().getCenterCamera().getTransform();
for (final Object[] range : mRanges) {
((GVRSceneObject)range[1]).setEnable(false);
}
for (int i = size - 1; i >= 0; --i) {
final Object[] range = mRanges.get(i);
final GVRSceneObject child = (GVRSceneObject) range[1];
if (child.getParent() != owner) {
Log.w(TAG, "the scene object for distance greater than " + range[0] + " is not a child of the owner; skipping it");
continue;
}
final float[] values = child.getBoundingVolumeRawValues();
mCenter.set(values[0], values[1], values[2], 1.0f);
mVector.set(t.getPositionX(), t.getPositionY(), t.getPositionZ(), 1.0f);
mVector.sub(mCenter);
mVector.negate();
float distance = mVector.dot(mVector);
if (distance >= (Float) range[0]) {
child.setEnable(true);
break;
}
}
} | java |
public static Shell createConsoleShell(String prompt, String appName, Object... handlers) {
ConsoleIO io = new ConsoleIO();
List<String> path = new ArrayList<String>(1);
path.add(prompt);
MultiMap<String, Object> modifAuxHandlers = new ArrayHashMultiMap<String, Object>();
modifAuxHandlers.put("!", io);
Shell theShell = new Shell(new Shell.Settings(io, io, modifAuxHandlers, false),
new CommandTable(new DashJoinedNamer(true)), path);
theShell.setAppName(appName);
theShell.addMainHandler(theShell, "!");
theShell.addMainHandler(new HelpCommandHandler(), "?");
for (Object h : handlers) {
theShell.addMainHandler(h, "");
}
return theShell;
} | java |
public static Shell createConsoleShell(String prompt, String appName, Object mainHandler) {
return createConsoleShell(prompt, appName, mainHandler, new EmptyMultiMap<String, Object>());
} | java |
public static Shell createSubshell(String pathElement, Shell parent, String appName, Object mainHandler,
MultiMap<String, Object> auxHandlers) {
List<String> newPath = new ArrayList<String>(parent.getPath());
newPath.add(pathElement);
Shell subshell = new Shell(parent.getSettings().createWithAddedAuxHandlers(auxHandlers),
new CommandTable(parent.getCommandTable().getNamer()), newPath);
subshell.setAppName(appName);
subshell.addMainHandler(subshell, "!");
subshell.addMainHandler(new HelpCommandHandler(), "?");
subshell.addMainHandler(mainHandler, "");
return subshell;
} | java |
public static Shell createSubshell(String pathElement, Shell parent, String appName, Object mainHandler) {
return createSubshell(pathElement, parent, appName, mainHandler, new EmptyMultiMap<String, Object>());
} | java |
public void animate(float animationTime, Matrix4f mat)
{
mRotInterpolator.animate(animationTime, mRotKey);
mPosInterpolator.animate(animationTime, mPosKey);
mSclInterpolator.animate(animationTime, mScaleKey);
mat.translationRotateScale(mPosKey[0], mPosKey[1], mPosKey[2], mRotKey[0], mRotKey[1], mRotKey[2], mRotKey[3], mScaleKey[0], mScaleKey[1], mScaleKey[2]);
} | java |
public void setAmbientIntensity(float r, float g, float b, float a) {
setVec4("ambient_intensity", r, g, b, a);
} | java |
public void setDiffuseIntensity(float r, float g, float b, float a) {
setVec4("diffuse_intensity", r, g, b, a);
} | java |
public void setSpecularIntensity(float r, float g, float b, float a) {
setVec4("specular_intensity", r, g, b, a);
} | java |
private float getQuaternionW(float x, float y, float z) {
return (float) Math.cos(Math.asin(Math.sqrt(x * x + y * y + z * z)));
} | java |
public void shutdown() {
debugConnection = null;
shuttingDown = true;
try {
if (serverSocket != null) {
serverSocket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} | java |
@Override
public void run() {
ExecutorService executorService = Executors.newFixedThreadPool(maxClients);
try {
serverSocket = new ServerSocket(port, maxClients);
while (!shuttingDown) {
try {
Socket socket = serverSocket.accept();
debugConnection = new DebugConnection(socket);
executorService.submit(debugConnection);
} catch (SocketException e) {
// closed
debugConnection = null;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
debugConnection = null;
serverSocket.close();
} catch (Exception e) {
}
executorService.shutdownNow();
}
} | java |
public synchronized void removeAllSceneObjects() {
final GVRCameraRig rig = getMainCameraRig();
final GVRSceneObject head = rig.getOwnerObject();
rig.removeAllChildren();
NativeScene.removeAllSceneObjects(getNative());
for (final GVRSceneObject child : mSceneRoot.getChildren()) {
child.getParent().removeChildObject(child);
}
if (null != head) {
mSceneRoot.addChildObject(head);
}
final int numControllers = getGVRContext().getInputManager().clear();
if (numControllers > 0)
{
getGVRContext().getInputManager().selectController();
}
getGVRContext().runOnGlThread(new Runnable() {
@Override
public void run() {
NativeScene.deleteLightsAndDepthTextureOnRenderThread(getNative());
}
});
} | java |
public void setPickRay(float ox, float oy, float oz, float dx, float dy, float dz)
{
synchronized (this)
{
mRayOrigin.x = ox;
mRayOrigin.y = oy;
mRayOrigin.z = oz;
mRayDirection.x = dx;
mRayDirection.y = dy;
mRayDirection.z = dz;
}
} | java |
public void onDrawFrame(float frameTime)
{
if (isEnabled() && (mScene != null) && mPickEventLock.tryLock())
{
// Don't call if we are in the middle of processing another pick
try
{
doPick();
}
finally
{
mPickEventLock.unlock();
}
}
} | java |
public void processPick(boolean touched, MotionEvent event)
{
mPickEventLock.lock();
mTouched = touched;
mMotionEvent = event;
doPick();
mPickEventLock.unlock();
} | java |
protected void propagateOnNoPick(GVRPicker picker)
{
if (mEventOptions.contains(EventOptions.SEND_PICK_EVENTS))
{
if (mEventOptions.contains(EventOptions.SEND_TO_LISTENERS))
{
getGVRContext().getEventManager().sendEvent(this, IPickEvents.class, "onNoPick", picker);
}
if (mEventOptions.contains(EventOptions.SEND_TO_SCENE) && (mScene != null))
{
getGVRContext().getEventManager().sendEvent(mScene, IPickEvents.class, "onNoPick", picker);
}
}
} | java |
protected void propagateOnMotionOutside(MotionEvent event)
{
if (mEventOptions.contains(EventOptions.SEND_TOUCH_EVENTS))
{
if (mEventOptions.contains(EventOptions.SEND_TO_LISTENERS))
{
getGVRContext().getEventManager().sendEvent(this, ITouchEvents.class, "onMotionOutside", this, event);
}
if (mEventOptions.contains(EventOptions.SEND_TO_SCENE) && (mScene != null))
{
getGVRContext().getEventManager().sendEvent(mScene, ITouchEvents.class, "onMotionOutside", this, event);
}
}
} | java |
protected void propagateOnEnter(GVRPickedObject hit)
{
GVRSceneObject hitObject = hit.getHitObject();
GVREventManager eventManager = getGVRContext().getEventManager();
if (mEventOptions.contains(EventOptions.SEND_TOUCH_EVENTS))
{
if (mEventOptions.contains(EventOptions.SEND_TO_LISTENERS))
{
eventManager.sendEvent(this, ITouchEvents.class, "onEnter", hitObject, hit);
}
if (mEventOptions.contains(EventOptions.SEND_TO_HIT_OBJECT))
{
eventManager.sendEvent(hitObject, ITouchEvents.class, "onEnter", hitObject, hit);
}
if (mEventOptions.contains(EventOptions.SEND_TO_SCENE) && (mScene != null))
{
eventManager.sendEvent(mScene, ITouchEvents.class, "onEnter", hitObject, hit);
}
}
if (mEventOptions.contains(EventOptions.SEND_PICK_EVENTS))
{
if (mEventOptions.contains(EventOptions.SEND_TO_LISTENERS))
{
eventManager.sendEvent(this, IPickEvents.class, "onEnter", hitObject, hit);
}
if (mEventOptions.contains(EventOptions.SEND_TO_HIT_OBJECT))
{
eventManager.sendEvent(hitObject, IPickEvents.class, "onEnter", hitObject, hit);
}
if (mEventOptions.contains(EventOptions.SEND_TO_SCENE) && (mScene != null))
{
eventManager.sendEvent(mScene, IPickEvents.class, "onEnter", hitObject, hit);
}
}
} | java |
protected void propagateOnTouch(GVRPickedObject hit)
{
if (mEventOptions.contains(EventOptions.SEND_TOUCH_EVENTS))
{
GVREventManager eventManager = getGVRContext().getEventManager();
GVRSceneObject hitObject = hit.getHitObject();
if (mEventOptions.contains(EventOptions.SEND_TO_LISTENERS))
{
eventManager.sendEvent(this, ITouchEvents.class, "onTouchStart", hitObject, hit);
}
if (mEventOptions.contains(EventOptions.SEND_TO_HIT_OBJECT))
{
eventManager.sendEvent(hitObject, ITouchEvents.class, "onTouchStart", hitObject, hit);
}
if (mEventOptions.contains(EventOptions.SEND_TO_SCENE) && (mScene != null))
{
eventManager.sendEvent(mScene, ITouchEvents.class, "onTouchStart", hitObject, hit);
}
}
} | java |
protected GVRPickedObject findCollider(GVRPickedObject[] pickList, GVRCollider findme)
{
if (pickList == null)
{
return null;
}
for (GVRPickedObject hit : pickList)
{
if ((hit != null) && (hit.hitCollider == findme))
{
return hit;
}
}
return null;
} | java |
public static final GVRPickedObject[] pickObjects(GVRScene scene, float ox, float oy, float oz, float dx,
float dy, float dz) {
sFindObjectsLock.lock();
try {
final GVRPickedObject[] result = NativePicker.pickObjects(scene.getNative(), 0L, ox, oy, oz, dx, dy, dz);
return result;
} finally {
sFindObjectsLock.unlock();
}
} | java |
static GVRPickedObject makeHitMesh(long colliderPointer, float distance, float hitx, float hity, float hitz,
int faceIndex, float barycentricx, float barycentricy, float barycentricz,
float texu, float texv, float normalx, float normaly, float normalz)
{
GVRCollider collider = GVRCollider.lookup(colliderPointer);
if (collider == null)
{
Log.d(TAG, "makeHit: cannot find collider for %x", colliderPointer);
return null;
}
return new GVRPicker.GVRPickedObject(collider, new float[] { hitx, hity, hitz }, distance, faceIndex,
new float[] {barycentricx, barycentricy, barycentricz},
new float[]{ texu, texv },
new float[]{normalx, normaly, normalz});
} | java |
public static List<GVRAtlasInformation> loadAtlasInformation(InputStream ins) {
try {
int size = ins.available();
byte[] buffer = new byte[size];
ins.read(buffer);
return loadAtlasInformation(new JSONArray(new String(buffer, "UTF-8")));
} catch (JSONException je) {
je.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
} | java |
public void setSpeed(float newValue) {
if (newValue < 0) newValue = 0;
this.pitch.setValue( newValue );
this.speed.setValue( newValue );
} | java |
public String getUniformDescriptor(GVRContext ctx)
{
if (mShaderTemplate == null)
{
mShaderTemplate = makeTemplate(ID, ctx);
ctx.getShaderManager().addShaderID(this);
}
return mShaderTemplate.getUniformDescriptor();
} | java |
public GVRShader getTemplate(GVRContext ctx)
{
if (mShaderTemplate == null)
{
mShaderTemplate = makeTemplate(ID, ctx);
ctx.getShaderManager().addShaderID(this);
}
return mShaderTemplate;
} | java |
GVRShader makeTemplate(Class<? extends GVRShader> id, GVRContext ctx)
{
try
{
Constructor<? extends GVRShader> maker = id.getDeclaredConstructor(GVRContext.class);
return maker.newInstance(ctx);
}
catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException ex)
{
try
{
Constructor<? extends GVRShader> maker = id.getDeclaredConstructor();
return maker.newInstance();
}
catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException ex2)
{
ctx.getEventManager().sendEvent(ctx, IErrorEvents.class, "onError", new Object[] {ex2.getMessage(), this});
return null;
}
}
} | java |
public void start(GVRAccessibilitySpeechListener speechListener) {
mTts.setSpeechListener(speechListener);
mTts.getSpeechRecognizer().startListening(mTts.getSpeechRecognizerIntent());
} | java |
public void setVertexBuffer(GVRVertexBuffer vbuf)
{
if (vbuf == null)
{
throw new IllegalArgumentException("Vertex buffer cannot be null");
}
mVertices = vbuf;
NativeMesh.setVertexBuffer(getNative(), vbuf.getNative());
} | java |
public void setIndexBuffer(GVRIndexBuffer ibuf)
{
mIndices = ibuf;
NativeMesh.setIndexBuffer(getNative(), (ibuf != null) ? ibuf.getNative() : 0L);
} | java |
public static void rebuild(final MODE newMode) {
if (mode != newMode) {
mode = newMode;
TYPE type;
switch (mode) {
case DEBUG:
type = TYPE.ANDROID;
Log.startFullLog();
break;
case DEVELOPER:
type = TYPE.PERSISTENT;
Log.stopFullLog();
break;
case USER:
type = TYPE.ANDROID;
break;
default:
type = DEFAULT_TYPE;
Log.stopFullLog();
break;
}
currentLog = getLog(type);
}
} | java |
public static int e(ISubsystem subsystem, String tag, String msg) {
return isEnabled(subsystem) ?
currentLog.e(tag, getMsg(subsystem,msg)) : 0;
} | java |
public static void d(ISubsystem subsystem, String tag, String pattern, Object... parameters) {
if (!isEnabled(subsystem)) return;
d(subsystem, tag, format(pattern, parameters));
} | java |
private static void deleteOldAndEmptyFiles() {
File dir = LOG_FILE_DIR;
if (dir.exists()) {
File[] files = dir.listFiles();
for (File f : files) {
if (f.length() == 0 ||
f.lastModified() + MAXFILEAGE < System.currentTimeMillis()) {
f.delete();
}
}
}
} | java |
public boolean load(GVRScene scene)
{
GVRAssetLoader loader = getGVRContext().getAssetLoader();
if (scene == null)
{
scene = getGVRContext().getMainScene();
}
if (mReplaceScene)
{
loader.loadScene(getOwnerObject(), mVolume, mImportSettings, scene, null);
}
else
{
loader.loadModel(getOwnerObject(), mVolume, mImportSettings, scene);
}
return true;
} | java |
public void load(IAssetEvents handler)
{
GVRAssetLoader loader = getGVRContext().getAssetLoader();
if (mReplaceScene)
{
loader.loadScene(getOwnerObject(), mVolume, mImportSettings, getGVRContext().getMainScene(), handler);
}
else
{
loader.loadModel(mVolume, getOwnerObject(), mImportSettings, true, handler);
}
} | java |
public String[] parseMFString(String mfString) {
Vector<String> strings = new Vector<String>();
StringReader sr = new StringReader(mfString);
StreamTokenizer st = new StreamTokenizer(sr);
st.quoteChar('"');
st.quoteChar('\'');
String[] mfStrings = null;
int tokenType;
try {
while ((tokenType = st.nextToken()) != StreamTokenizer.TT_EOF) {
strings.add(st.sval);
}
} catch (IOException e) {
Log.d(TAG, "String parsing Error: " + e);
e.printStackTrace();
}
mfStrings = new String[strings.size()];
for (int i = 0; i < strings.size(); i++) {
mfStrings[i] = strings.get(i);
}
return mfStrings;
} | java |
private static Point getScreenSize(Context context, Point p) {
if (p == null) {
p = new Point();
}
WindowManager windowManager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
display.getSize(p);
return p;
} | java |
public float get(int row, int col) {
if (row < 0 || row > 3) {
throw new IndexOutOfBoundsException("Index: " + row + ", Size: 4");
}
if (col < 0 || col > 3) {
throw new IndexOutOfBoundsException("Index: " + col + ", Size: 4");
}
return m_data[row * 4 + col];
} | java |
public PeriodicEvent runAfter(Runnable task, float delay) {
validateDelay(delay);
return new Event(task, delay);
} | java |
public PeriodicEvent runEvery(Runnable task, float delay, float period) {
return runEvery(task, delay, period, null);
} | java |
public PeriodicEvent runEvery(Runnable task, float delay, float period,
int repetitions) {
if (repetitions < 1) {
return null;
} else if (repetitions == 1) {
// Better to burn a handful of CPU cycles than to churn memory by
// creating a new callback
return runAfter(task, delay);
} else {
return runEvery(task, delay, period, new RunFor(repetitions));
}
} | java |
public PeriodicEvent runEvery(Runnable task, float delay, float period,
KeepRunning callback) {
validateDelay(delay);
validatePeriod(period);
return new Event(task, delay, period, callback);
} | java |
@SuppressWarnings("unchecked")
public <V3, M4, C, N, Q> N getSceneRoot(AiWrapperProvider<V3, M4, C, N, Q>
wrapperProvider) {
return (N) m_sceneRoot;
} | java |
public void enableClipRegion() {
if (mClippingEnabled) {
Log.w(TAG, "Clipping has been enabled already for %s!", getName());
return;
}
Log.d(Log.SUBSYSTEM.WIDGET, TAG, "enableClipping for %s [%f, %f, %f]",
getName(), getViewPortWidth(), getViewPortHeight(), getViewPortDepth());
mClippingEnabled = true;
GVRTexture texture = WidgetLib.getTextureHelper().getSolidColorTexture(Color.YELLOW);
GVRSceneObject clippingObj = new GVRSceneObject(mContext, getViewPortWidth(), getViewPortHeight(), texture);
clippingObj.setName("clippingObj");
clippingObj.getRenderData()
.setRenderingOrder(GVRRenderData.GVRRenderingOrder.STENCIL)
.setStencilTest(true)
.setStencilFunc(GLES30.GL_ALWAYS, 1, 0xFF)
.setStencilOp(GLES30.GL_KEEP, GLES30.GL_KEEP, GLES30.GL_REPLACE)
.setStencilMask(0xFF);
mSceneObject.addChildObject(clippingObj);
for (Widget child : getChildren()) {
setObjectClipped(child);
}
} | java |
public float getLayoutSize(final Layout.Axis axis) {
float size = 0;
for (Layout layout : mLayouts) {
size = Math.max(size, layout.getSize(axis));
}
Log.d(Log.SUBSYSTEM.LAYOUT, TAG, "getLayoutSize [%s] axis [%s] size [%f]", getName(), axis, size);
return size;
} | java |
public float getBoundsWidth() {
if (mSceneObject != null) {
GVRSceneObject.BoundingVolume v = mSceneObject.getBoundingVolume();
return v.maxCorner.x - v.minCorner.x;
}
return 0f;
} | java |
public float getBoundsHeight(){
if (mSceneObject != null) {
GVRSceneObject.BoundingVolume v = mSceneObject.getBoundingVolume();
return v.maxCorner.y - v.minCorner.y;
}
return 0f;
} | java |
public float getBoundsDepth() {
if (mSceneObject != null) {
GVRSceneObject.BoundingVolume v = mSceneObject.getBoundingVolume();
return v.maxCorner.z - v.minCorner.z;
}
return 0f;
} | java |
public void rotateWithPivot(float w, float x, float y, float z,
float pivotX, float pivotY, float pivotZ) {
getTransform().rotateWithPivot(w, x, y, z, pivotX, pivotY, pivotZ);
if (mTransformCache.rotateWithPivot(w, x, y, z, pivotX, pivotY, pivotZ)) {
onTransformChanged();
}
} | java |
public boolean setVisibility(final Visibility visibility) {
if (visibility != mVisibility) {
Log.d(Log.SUBSYSTEM.WIDGET, TAG, "setVisibility(%s) for %s", visibility, getName());
updateVisibility(visibility);
mVisibility = visibility;
return true;
}
return false;
} | java |
public boolean setViewPortVisibility(final ViewPortVisibility viewportVisibility) {
boolean visibilityIsChanged = viewportVisibility != mIsVisibleInViewPort;
if (visibilityIsChanged) {
Visibility visibility = mVisibility;
switch(viewportVisibility) {
case FULLY_VISIBLE:
case PARTIALLY_VISIBLE:
break;
case INVISIBLE:
visibility = Visibility.HIDDEN;
break;
}
mIsVisibleInViewPort = viewportVisibility;
updateVisibility(visibility);
}
return visibilityIsChanged;
} | java |
public Widget findChildByName(final String name) {
final List<Widget> groups = new ArrayList<>();
groups.add(this);
return findChildByNameInAllGroups(name, groups);
} | java |
protected final boolean isGLThread() {
final Thread glThread = sGLThread.get();
return glThread != null && glThread.equals(Thread.currentThread());
} | java |
protected void update(float scale) {
// Updates only when the plane is in the scene
GVRSceneObject owner = getOwnerObject();
if ((owner != null) && isEnabled() && owner.isEnabled())
{
convertFromARtoVRSpace(scale);
}
} | java |
public void setCastShadow(boolean enableFlag)
{
GVRSceneObject owner = getOwnerObject();
if (owner != null)
{
GVRShadowMap shadowMap = (GVRShadowMap) getComponent(GVRRenderTarget.getComponentType());
if (enableFlag)
{
if (shadowMap != null)
{
shadowMap.setEnable(true);
}
else
{
GVRCamera shadowCam = GVRShadowMap.makeOrthoShadowCamera(
getGVRContext().getMainScene().getMainCameraRig().getCenterCamera());
shadowMap = new GVRShadowMap(getGVRContext(), shadowCam);
owner.attachComponent(shadowMap);
}
}
else if (shadowMap != null)
{
shadowMap.setEnable(false);
}
}
mCastShadow = enableFlag;
} | java |
public synchronized void delete(String name) {
if (isEmpty(name)) {
indexedProps.remove(name);
} else {
synchronized (context) {
int scope = context.getAttributesScope(name);
if (scope != -1) {
context.removeAttribute(name, scope);
}
}
}
} | java |
public synchronized Object[] getIds() {
String[] keys = getAllKeys();
int size = keys.length + indexedProps.size();
Object[] res = new Object[size];
System.arraycopy(keys, 0, res, 0, keys.length);
int i = keys.length;
// now add all indexed properties
for (Object index : indexedProps.keySet()) {
res[i++] = index;
}
return res;
} | java |
public boolean hasInstance(Scriptable instance) {
// Default for JS objects (other than Function) is to do prototype
// chasing.
Scriptable proto = instance.getPrototype();
while (proto != null) {
if (proto.equals(this)) return true;
proto = proto.getPrototype();
}
return false;
} | java |
public void setLoop(boolean doLoop, GVRContext gvrContext) {
if (this.loop != doLoop ) {
// a change in the loop
for (GVRNodeAnimation gvrKeyFrameAnimation : gvrKeyFrameAnimations) {
if (doLoop) gvrKeyFrameAnimation.setRepeatMode(GVRRepeatMode.REPEATED);
else gvrKeyFrameAnimation.setRepeatMode(GVRRepeatMode.ONCE);
}
// be sure to start the animations if loop is true
if ( doLoop ) {
for (GVRNodeAnimation gvrKeyFrameAnimation : gvrKeyFrameAnimations) {
gvrKeyFrameAnimation.start(gvrContext.getAnimationEngine() );
}
}
this.loop = doLoop;
}
} | java |
public void setCycleInterval(float newCycleInterval) {
if ( (this.cycleInterval != newCycleInterval) && (newCycleInterval > 0) ) {
for (GVRNodeAnimation gvrKeyFrameAnimation : gvrKeyFrameAnimations) {
//TODO Cannot easily change the GVRAnimation's GVRChannel once set.
}
this.cycleInterval = newCycleInterval;
}
} | java |
public ExecutionChain setErrorCallback(ErrorCallback callback) {
if (state.get() == State.RUNNING) {
throw new IllegalStateException(
"Invalid while ExecutionChain is running");
}
errorCallback = callback;
return this;
} | java |
public void execute() {
State currentState = state.getAndSet(State.RUNNING);
if (currentState == State.RUNNING) {
throw new IllegalStateException(
"ExecutionChain is already running!");
}
executeRunnable = new ExecuteRunnable();
} | java |
public boolean isHomeKeyPresent() {
final GVRApplication application = mApplication.get();
if (null != application) {
final String model = getHmtModel();
if (null != model && model.contains("R323")) {
return true;
}
}
return false;
} | java |
public void addAuxHandler(Object handler, String prefix) {
if (handler == null) {
throw new NullPointerException();
}
auxHandlers.put(prefix, handler);
allHandlers.add(handler);
addDeclaredMethods(handler, prefix);
inputConverter.addDeclaredConverters(handler);
outputConverter.addDeclaredConverters(handler);
if (handler instanceof ShellDependent) {
((ShellDependent)handler).cliSetShell(this);
}
} | java |
public void commandLoop() throws IOException {
for (Object handler : allHandlers) {
if (handler instanceof ShellManageable) {
((ShellManageable)handler).cliEnterLoop();
}
}
output.output(appName, outputConverter);
String command = "";
while (true) {
try {
command = input.readCommand(path);
if (command.trim().equals("exit")) {
if (lineProcessor == null)
break;
else {
path = savedPath;
lineProcessor = null;
}
}
processLine(command);
} catch (TokenException te) {
lastException = te;
output.outputException(command, te);
} catch (CLIException clie) {
lastException = clie;
if (!command.trim().equals("exit")) {
output.outputException(clie);
}
}
}
for (Object handler : allHandlers) {
if (handler instanceof ShellManageable) {
((ShellManageable)handler).cliLeaveLoop();
}
}
} | java |
@Override
public void addVariable(String varName, Object value) {
synchronized (mGlobalVariables) {
mGlobalVariables.put(varName, value);
}
refreshGlobalBindings();
} | java |
@Override
public void attachScriptFile(IScriptable target, IScriptFile scriptFile) {
mScriptMap.put(target, scriptFile);
scriptFile.invokeFunction("onAttach", new Object[] { target });
} | java |
@Override
public void detachScriptFile(IScriptable target) {
IScriptFile scriptFile = mScriptMap.remove(target);
if (scriptFile != null) {
scriptFile.invokeFunction("onDetach", new Object[] { target });
}
} | java |
public void bindScriptBundleToScene(GVRScriptBundle scriptBundle, GVRScene scene) throws IOException, GVRScriptException {
for (GVRSceneObject sceneObject : scene.getSceneObjects()) {
bindBundleToSceneObject(scriptBundle, sceneObject);
}
} | java |
public void bindBundleToSceneObject(GVRScriptBundle scriptBundle, GVRSceneObject rootSceneObject)
throws IOException, GVRScriptException
{
bindHelper(scriptBundle, rootSceneObject, BIND_MASK_SCENE_OBJECTS);
} | java |
protected void bindHelper(GVRScriptBundle scriptBundle, GVRSceneObject rootSceneObject, int bindMask)
throws IOException, GVRScriptException
{
for (GVRScriptBindingEntry entry : scriptBundle.file.binding) {
GVRAndroidResource rc;
if (entry.volumeType == null || entry.volumeType.isEmpty()) {
rc = scriptBundle.volume.openResource(entry.script);
} else {
GVRResourceVolume.VolumeType volumeType = GVRResourceVolume.VolumeType.fromString(entry.volumeType);
if (volumeType == null) {
throw new GVRScriptException(String.format("Volume type %s is not recognized, script=%s",
entry.volumeType, entry.script));
}
rc = new GVRResourceVolume(mGvrContext, volumeType).openResource(entry.script);
}
GVRScriptFile scriptFile = (GVRScriptFile)loadScript(rc, entry.language);
String targetName = entry.target;
if (targetName.startsWith(TARGET_PREFIX)) {
TargetResolver resolver = sBuiltinTargetMap.get(targetName);
IScriptable target = resolver.getTarget(mGvrContext, targetName);
// Apply mask
boolean toBind = false;
if ((bindMask & BIND_MASK_GVRSCRIPT) != 0 && targetName.equalsIgnoreCase(TARGET_GVRMAIN)) {
toBind = true;
}
if ((bindMask & BIND_MASK_GVRACTIVITY) != 0 && targetName.equalsIgnoreCase(TARGET_GVRAPPLICATION)) {
toBind = true;
}
if (toBind) {
attachScriptFile(target, scriptFile);
}
} else {
if ((bindMask & BIND_MASK_SCENE_OBJECTS) != 0) {
if (targetName.equals(rootSceneObject.getName())) {
attachScriptFile(rootSceneObject, scriptFile);
}
// Search in children
GVRSceneObject[] sceneObjects = rootSceneObject.getSceneObjectsByName(targetName);
if (sceneObjects != null) {
for (GVRSceneObject sceneObject : sceneObjects) {
GVRScriptBehavior b = new GVRScriptBehavior(sceneObject.getGVRContext());
b.setScriptFile(scriptFile);
sceneObject.attachComponent(b);
}
}
}
}
}
} | java |
private long doMemoryManagementAndPerFrameCallbacks() {
long currentTime = GVRTime.getCurrentTime();
mFrameTime = (currentTime - mPreviousTimeNanos) / 1e9f;
mPreviousTimeNanos = currentTime;
/*
* Without the sensor data, can't draw a scene properly.
*/
if (!(mSensoredScene == null || !mMainScene.equals(mSensoredScene))) {
Runnable runnable;
while ((runnable = mRunnables.poll()) != null) {
try {
runnable.run();
} catch (final Exception exc) {
Log.e(TAG, "Runnable-on-GL %s threw %s", runnable, exc.toString());
exc.printStackTrace();
}
}
final List<GVRDrawFrameListener> frameListeners = mFrameListeners;
for (GVRDrawFrameListener listener : frameListeners) {
try {
listener.onDrawFrame(mFrameTime);
} catch (final Exception exc) {
Log.e(TAG, "DrawFrameListener %s threw %s", listener, exc.toString());
exc.printStackTrace();
}
}
}
return currentTime;
} | java |
protected void capture3DScreenShot(GVRRenderTarget renderTarget, boolean isMultiview) {
if (mScreenshot3DCallback == null) {
return;
}
final Bitmap[] bitmaps = new Bitmap[6];
renderSixCamerasAndReadback(mMainScene.getMainCameraRig(), bitmaps, renderTarget, isMultiview);
returnScreenshot3DToCaller(mScreenshot3DCallback, bitmaps, mReadbackBufferWidth, mReadbackBufferHeight);
mScreenshot3DCallback = null;
} | java |
private void captureEye(GVRScreenshotCallback callback, GVRRenderTarget renderTarget, GVRViewManager.EYE eye, boolean useMultiview) {
if (null == callback) {
return;
}
readRenderResult(renderTarget,eye,useMultiview);
returnScreenshotToCaller(callback, mReadbackBufferWidth, mReadbackBufferHeight);
} | java |
protected void captureCenterEye(GVRRenderTarget renderTarget, boolean isMultiview) {
if (mScreenshotCenterCallback == null) {
return;
}
// TODO: when we will use multithreading, create new camera using centercamera as we are adding posteffects into it
final GVRCamera centerCamera = mMainScene.getMainCameraRig().getCenterCamera();
final GVRMaterial postEffect = new GVRMaterial(this, GVRMaterial.GVRShaderType.VerticalFlip.ID);
centerCamera.addPostEffect(postEffect);
GVRRenderTexture posteffectRenderTextureB = null;
GVRRenderTexture posteffectRenderTextureA = null;
if(isMultiview) {
posteffectRenderTextureA = mRenderBundle.getEyeCapturePostEffectRenderTextureA();
posteffectRenderTextureB = mRenderBundle.getEyeCapturePostEffectRenderTextureB();
renderTarget = mRenderBundle.getEyeCaptureRenderTarget();
renderTarget.cullFromCamera(mMainScene, centerCamera ,mRenderBundle.getShaderManager());
renderTarget.beginRendering(centerCamera);
}
else {
posteffectRenderTextureA = mRenderBundle.getPostEffectRenderTextureA();
posteffectRenderTextureB = mRenderBundle.getPostEffectRenderTextureB();
}
renderTarget.render(mMainScene,centerCamera, mRenderBundle.getShaderManager(), posteffectRenderTextureA, posteffectRenderTextureB);
centerCamera.removePostEffect(postEffect);
readRenderResult(renderTarget, EYE.MULTIVIEW, false);
if(isMultiview)
renderTarget.endRendering();
final Bitmap bitmap = Bitmap.createBitmap(mReadbackBufferWidth, mReadbackBufferHeight, Bitmap.Config.ARGB_8888);
mReadbackBuffer.rewind();
bitmap.copyPixelsFromBuffer(mReadbackBuffer);
final GVRScreenshotCallback callback = mScreenshotCenterCallback;
Threads.spawn(new Runnable() {
public void run() {
callback.onScreenCaptured(bitmap);
}
});
mScreenshotCenterCallback = null;
} | java |
public boolean runOnMainThreadNext(Runnable r) {
assert handler != null;
if (!sanityCheck("runOnMainThreadNext " + r)) {
return false;
}
return handler.post(r);
} | java |
private void showSettingsMenu(final Cursor cursor) {
Log.d(TAG, "showSettingsMenu");
enableSettingsCursor(cursor);
context.runOnGlThread(new Runnable() {
@Override
public void run() {
new SettingsView(context, scene, CursorManager.this,
settingsCursor.getIoDevice().getCursorControllerId(), cursor, new
SettingsChangeListener() {
@Override
public void onBack(boolean cascading) {
disableSettingsCursor();
}
@Override
public int onDeviceChanged(IoDevice device) {
// we are changing the io device on the settings cursor
removeCursorFromScene(settingsCursor);
IoDevice clickedDevice = getAvailableIoDevice(device);
settingsCursor.setIoDevice(clickedDevice);
addCursorToScene(settingsCursor);
return device.getCursorControllerId();
}
});
}
});
} | java |
private void updateCursorsInScene(GVRScene scene, boolean add) {
synchronized (mCursors) {
for (Cursor cursor : mCursors) {
if (cursor.isActive()) {
if (add) {
addCursorToScene(cursor);
} else {
removeCursorFromScene(cursor);
}
}
}
}
} | java |
public List<Widget> getAllViews() {
List<Widget> views = new ArrayList<>();
for (Widget child: mContent.getChildren()) {
Widget item = ((ListItemHostWidget) child).getGuest();
if (item != null) {
views.add(item);
}
}
return views;
} | java |
public boolean clearSelection(boolean requestLayout) {
Log.d(Log.SUBSYSTEM.LAYOUT, TAG, "clearSelection [%d]", mSelectedItemsList.size());
boolean updateLayout = false;
List<ListItemHostWidget> views = getAllHosts();
for (ListItemHostWidget host: views) {
if (host.isSelected()) {
host.setSelected(false);
updateLayout = true;
if (requestLayout) {
host.requestLayout();
}
}
}
clearSelectedItemsList();
return updateLayout;
} | java |
public boolean updateSelectedItemsList(int dataIndex, boolean select) {
boolean done = false;
boolean contains = isSelected(dataIndex);
if (select) {
if (!contains) {
if (!mMultiSelectionSupported) {
clearSelection(false);
}
Log.d(Log.SUBSYSTEM.LAYOUT, TAG, "updateSelectedItemsList add index = %d", dataIndex);
mSelectedItemsList.add(dataIndex);
done = true;
}
} else {
if (contains) {
Log.d(Log.SUBSYSTEM.LAYOUT, TAG, "updateSelectedItemsList remove index = %d", dataIndex);
mSelectedItemsList.remove(dataIndex);
done = true;
}
}
return done;
} | java |
private void onScrollImpl(final Vector3Axis offset, final LayoutScroller.OnScrollListener listener) {
if (!isScrolling()) {
mScroller = new ScrollingProcessor(offset, listener);
mScroller.scroll();
}
} | java |
protected void recycleChildren() {
for (ListItemHostWidget host: getAllHosts()) {
recycle(host);
}
mContent.onTransformChanged();
mContent.requestLayout();
} | java |
private void onChangedImpl(final int preferableCenterPosition) {
for (ListOnChangedListener listener: mOnChangedListeners) {
listener.onChangedStart(this);
}
Log.d(Log.SUBSYSTEM.LAYOUT, TAG, "onChangedImpl(%s): items [%d] views [%d] mLayouts.size() = %d " +
"preferableCenterPosition = %d",
getName(), getDataCount(), getViewCount(), mContent.mLayouts.size(), preferableCenterPosition);
// TODO: selectively recycle data based on the changes in the data set
mPreferableCenterPosition = preferableCenterPosition;
recycleChildren();
} | java |
static Shell createTerminalConsoleShell(String prompt, String appName,
ShellCommandHandler mainHandler, InputStream input, OutputStream output) {
try {
PrintStream out = new PrintStream(output);
// Build jline terminal
jline.Terminal term = TerminalFactory.get();
final ConsoleReader console = new ConsoleReader(input, output, term);
console.setBellEnabled(true);
console.setHistoryEnabled(true);
// Build console
BufferedReader in = new BufferedReader(new InputStreamReader(
new ConsoleReaderInputStream(console)));
ConsoleIO.PromptListener promptListener = new ConsoleIO.PromptListener() {
@Override
public boolean onPrompt(String prompt) {
console.setPrompt(prompt);
return true; // suppress normal prompt
}
};
return createConsoleShell(prompt, appName, mainHandler, in, out, out, promptListener);
} catch (Exception e) {
// Failover: use default shell
BufferedReader in = new BufferedReader(new InputStreamReader(input));
PrintStream out = new PrintStream(output);
return createConsoleShell(prompt, appName, mainHandler, in, out, out, null);
}
} | java |
static Shell createTelnetConsoleShell(String prompt, String appName,
ShellCommandHandler mainHandler, InputStream input, OutputStream output) {
try {
// Set up nvt4j; ignore the initial clear & reposition
final nvt4j.impl.Terminal nvt4jTerminal = new nvt4j.impl.Terminal(input, output) {
private boolean cleared;
private boolean moved;
@Override
public void clear() throws IOException {
if (this.cleared)
super.clear();
this.cleared = true;
}
@Override
public void move(int row, int col) throws IOException {
if (this.moved)
super.move(row, col);
this.moved = true;
}
};
nvt4jTerminal.put(nvt4j.impl.Terminal.AUTO_WRAP_ON);
nvt4jTerminal.setCursor(true);
// Have JLine do input & output through telnet terminal
final InputStream jlineInput = new InputStream() {
@Override
public int read() throws IOException {
return nvt4jTerminal.get();
}
};
final OutputStream jlineOutput = new OutputStream() {
@Override
public void write(int value) throws IOException {
nvt4jTerminal.put(value);
}
};
return createTerminalConsoleShell(prompt, appName, mainHandler, jlineInput, jlineOutput);
} catch (Exception e) {
// Failover: use default shell
BufferedReader in = new BufferedReader(new InputStreamReader(input));
PrintStream out = new PrintStream(output);
return createConsoleShell(prompt, appName, mainHandler, in, out, out, null);
}
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.