# AndroidStudio 3D figure

**URL:** https://discourse.processing.org/t/androidstudio-3d-figure/19039
**Category:** Processing for Android
**Created:** [March 26, 2020, 2:56pm UTC](https://discourse.processing.org/t/androidstudio-3d-figure/19039 "2020-03-26T14:56:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bert\_s](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@bert\_s](https://discourse.processing.org/u/bert_s)
#### Post date: [March 26, 2020, 2:56pm UTC](https://discourse.processing.org/t/androidstudio-3d-figure/19039/1 "2020-03-26T14:56:15Z")

</div>

I am having troubles drawing in 3D in AndroidStudio. This is my code in processing:

```auto
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.math.waves.*;
import toxi.processing.*;
import processing.serial.*;

ToxiclibsSupport gfx;

void setup() {
  size(600,600,P3D);
  gfx=new ToxiclibsSupport(this);
  
  background(255);
  noStroke();
  fill(200,200,200);
}

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.7, 0.5, 0.4,0.316227766);
  
  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);

      // Do some rotates to get oriented "behind" the device
      rotateX(-PI/2);

      // Apply the Matrix that we generated from our IMU Quaternion
      applyMatrix(M1);
      
      //elk vlak ander kleur       
      directionalLight(0, 128, 255, 0, -1, 0); 
      directionalLight(204, 0, 0, 0, 1, 0); 
      directionalLight(0, 0, 0, -1, 0, 0); 
      directionalLight(255, 255, 0, 1, 0, 0); 
      directionalLight(255, 128, 0, 0, 0, -1);
      directionalLight(0, 255, 0, 0, 0, 1);

      // Draw the Cube from a 3D Bounding Box
      cube=new AABB(new Vec3D(0,0,0),new Vec3D(100,100,100));
      gfx.box(cube);
      
      //sphere(100);
      
      
}

```

When I convert this code to AndroidStudio, somehow ‘size(600,600,P3D);’ disappears. When running my code, my figure is just 2D instead of 3D. I think this is because this size(600,600,P3D); isn’t there, but when I add this line I get a null pointer error and my app crashes.  
How can I display my 3D figure as a 3D figure in AndroidStudio?

---

<div class="post-metadata">

### Author: ![bert\_s](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@bert\_s](https://discourse.processing.org/u/bert_s)
#### Post date: [March 26, 2020, 3:12pm UTC](https://discourse.processing.org/t/androidstudio-3d-figure/19039/2 "2020-03-26T15:12:31Z")

</div>

An extra function is made in AndroidStudio (the function public void settings) where size is used:

```auto
public void settings() { size(400,400,P3D); }

```

So size and P3D are being used and still my figure isn’t in 3D, why is this?  
(So it doesn’t disappear, however it is not working apparently.)

---

<div class="post-metadata">

### Author: ![bert\_s](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@bert\_s](https://discourse.processing.org/u/bert_s)
#### Post date: [March 26, 2020, 3:29pm UTC](https://discourse.processing.org/t/androidstudio-3d-figure/19039/3 "2020-03-26T15:29:27Z")

</div>

If it would be necessary, here is the full code of my sketch in AndroidStudio:

```auto
package com.nordicsemi.nrfUARTv2;

import android.content.Intent;

import processing.core.PApplet;
import processing.core.PMatrix;
import toxi.geom.AABB;
import toxi.geom.Quaternion;
import toxi.geom.Vec3D;
import toxi.processing.ToxiclibsSupport;
//import processing.serial.*;

public class sketch_sphere extends PApplet {

ToxiclibsSupport gfx;
Quaternion Rotq = new Quaternion(1/2, 87/100, 0, 0);

    public void settings() {
        size(400,400,P3D);
    }

public void setup() {

        gfx=new ToxiclibsSupport(this);
  background(255);
  noStroke();
  fill(300,300,300);
}

public void draw() {

  float qMatrix[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  PMatrix M1 = getMatrix();

    //Quaternion 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);

      // Do some rotates to get oriented "behind" the device
      rotateX(-PI/2);

      // Apply the Matrix that we generated from our IMU Quaternion
      applyMatrix(M1);
      
      //directionalLight(0, 255, 0, 0, -1, 0);
      //sphere(130);

    //elk vlak ander kleur
    directionalLight(0, 128, 255, 0, -1, 0);
    directionalLight(204, 0, 0, 0, 1, 0);
    directionalLight(255, 0, 0, -1, 0, 0);
    directionalLight(255, 255, 0, 1, 0, 0);
    directionalLight(255, 128, 0, 0, 0, -1);
    directionalLight(0, 255, 0, 0, 0, 1);

    // Draw the Cube from a 3D Bounding Box
    cube=new AABB(new Vec3D(0,0,0),new Vec3D(50,50,50));
    gfx.box(cube);
}

    public void setQuaternion(float[] quat_array){
        Rotq = new Quaternion(quat_array[0], quat_array[1], quat_array[2], quat_array[3]);
        redraw();
    }
}

```

So why is this not in 3D?

---

<div class="post-metadata">

### Author: ![bert\_s](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@bert\_s](https://discourse.processing.org/u/bert_s)
#### Post date: [March 26, 2020, 5:00pm UTC](https://discourse.processing.org/t/androidstudio-3d-figure/19039/4 "2020-03-26T17:00:27Z")

</div>

Could it be because of the redraw when I get new quaternions? That I have to add something more, instead of just redraw. Because, whathever quaternions I give as first, the first image is always a nice sphere. So I think that it could be because of the redraw?
