I am a student and I don’t have any experience in Java/Processing. For a project I am making a Fitness Tracker. On the screen, I would like to to show data from the tracker (e.g. number of steps) and in the bottom right corner I want to show a sphere, which uses the quaternions from the tracker to rotate.
To draw the sphere, I used Processing. However, I am having problems chosing the location of my sketch. How can I put my sketch in the bottom right corner?
My sketch class (the sphere):
package processing.test.voorbeeld_sfeer;
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.math.waves.*;
import toxi.processing.*;
//import processing.serial.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class voorbeeld_sfeer extends PApplet {
ToxiclibsSupport gfx;
public void setup() {
gfx=new ToxiclibsSupport(this);
background(255);
noStroke();
fill(300,300,300);
}
public void draw() {
Quaternion RotQ = new Quaternion(1,0,0,0);
float qMatrix[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
PMatrix M1 = getMatrix();
RotQ = new Quaternion(0.4f, 0.5f, 0.7f,0.316227766f);
RotQ.toMatrix4x4().toFloatArray(qMatrix);
M1.set(
qMatrix[0],
qMatrix[1],
qMatrix[2],
qMatrix[3],
qMatrix[4],
qMatrix[5],
qMatrix[6],
qMatrix[7],
qMatrix[8],
qMatrix[9],
qMatrix[10],
qMatrix[11],
qMatrix[12],
qMatrix[13],
qMatrix[14],
qMatrix[15]
);
AABB cube;
background(255);
// Set some mood lighting
ambientLight(128, 128, 128);
directionalLight(128, 128, 128, 0, 0, 1);
lightFalloff(1, 0, 0);
lightSpecular(0, 0, 0);
// Get to the middle of the screen
translate(width/2,height/2,0);
//translate(width/2,0,0);
// Do some rotates to get oriented "behind" the device
rotateX(-PI/2);
// Apply the Matrix that we generated from our IMU Quaternion
applyMatrix(M1);
// Draw the Cube from a 3D Bounding Box
//cube=new AABB(new Vec3D(0,0,0),new Vec3D(100,100,100));
//gfx.box(cube);
directionalLight(0, 255, 0, 0, -1, 0);
sphere(100);
}
public void settings() { size(400,400,P3D); }
}
Main class:
package processing.test.voorbeeld_sfeer;
import android.os.Bundle;
import android.content.Intent;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.support.v7.app.AppCompatActivity;
import processing.android.PFragment;
import processing.android.CompatUtils;
import processing.core.PApplet;
public class MainActivity extends AppCompatActivity {
private PApplet sketch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout frame = new FrameLayout(this);
frame.setId(CompatUtils.getUniqueViewId());
setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
sketch = new voorbeeld_sfeer();
PFragment fragment = new PFragment(sketch);
fragment.setView(frame, this);
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (sketch != null) {
sketch.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
@Override
public void onNewIntent(Intent intent) {
if (sketch != null) {
sketch.onNewIntent(intent);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (sketch != null) {
sketch.onActivityResult(requestCode, resultCode, data);
}
}
@Override
public void onBackPressed() {
if (sketch != null) {
sketch.onBackPressed();
}
}
}
Main xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="tutorials.androidstudio.fragmentsv3.MainActivity" >
<FrameLayout
android:id="@+id/container"
android:layout_width="177dp"
android:layout_height="162dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="521dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" />
</RelativeLayout>
Maybe I can somehow link my sketch to this FrameLayout? How can I do this?