How to combine 2d and 3d?

edited January 2017 in Questions about Code

Here is two sketches - one of them is 2d and the other is 3d. The question is how to combine 2d and 3d, how to hold red brush and text in 2d, and let the sphere rotate? My problem is that red brush and text rotating with 3d objects.

2d sketch:

void setup()
{
  size(800,800);
}

void draw()
{
  background(150);

  noFill();
  stroke(255,0,0);
  ellipse(mouseX,mouseY,100,100);
  ellipse(mouseX,mouseY,50,50);
  ellipse(mouseX,mouseY,2,2);

  text("some text",20,30);
  text("some text",width-80,30);
  text("some text",20,height-30);
  text("some text",width-80,height-30);
}

And 3d sketch (requires PeasyCam library):

import peasy.*;
PeasyCam jcam;

void setup()
{
  jcam = new PeasyCam(this,200);
  size(800,800,P3D);
}

void draw()
{
  background(150);

  sphereDetail(10,10);
  sphere(50);
}
Tagged:

Answers

  • edited January 2017 Answer ✓

    yeah it's called a HUD - see wikipedia

    in draw first do all stuff 3D

    then end draw() with the 2D stuff:

              //---- HUD
    
              camera(); 
              noLights();
    
              hint(DISABLE_DEPTH_TEST);
              noLights();
              textMode(MODEL);
    
    
              // ALL 2D stuff    ...................
    
              // prepare to return to 3D 
              hint(ENABLE_DEPTH_TEST);
    
    
        } // end of draw() 
    
  • edited January 2017

    All I need is hint(DISABLE_DEPTH_TEST)? For some reason not working. Here is new code:

    import peasy.*;
    PeasyCam jcam;
    
    void setup()
    {
      jcam = new PeasyCam(this,200);
      size(800,800,P3D);
    }
    
    void draw()
    {
      background(150);
    
      stroke(100);
      fill(255);
      sphereDetail(10,10);
      sphere(50);
    
      hint(DISABLE_DEPTH_TEST);
      textMode(MODEL);
    
      noFill();
      stroke(255,0,0);
      ellipse(mouseX,mouseY,100,100);
      ellipse(mouseX,mouseY,50,50);
      ellipse(mouseX,mouseY,2,2);
    
      text("some text",20,30);
      text("some text",width-80,30);
      text("some text",20,height-30);
      text("some text",width-80,height-30);
    
      hint(ENABLE_DEPTH_TEST);
    }
    
  • no.

    you need all my lines

  • edited January 2017

    Working, but strange - sphere is jumping to the upper left corner. And another question - is it possible to compare 3d object and red brush coordinates, when one of them is in 3d, and another in 2d?

    import peasy.*;
    PeasyCam jcam;
    
    void setup()
    {
      jcam = new PeasyCam(this,200);
      size(800,800,P3D);
    }
    
    void draw()
    {
      background(150);
    
      stroke(100);
      fill(255);
      sphereDetail(10,10);
      sphere(50);
    
      camera(); 
      noLights();
    
      hint(DISABLE_DEPTH_TEST);
      noLights();
      textMode(MODEL);
    
      noFill();
      stroke(255,0,0);
      ellipse(mouseX,mouseY,100,100);
      ellipse(mouseX,mouseY,50,50);
      ellipse(mouseX,mouseY,2,2);
    
      text("some text",20,30);
      text("some text",width-80,30);
      text("some text",20,height-30);
      text("some text",width-80,height-30);
    
      hint(ENABLE_DEPTH_TEST);
    }
    
  • size should always be first line in setup

    also can't you call peasycam at begin of draw?

    also peasy has its own hud which is much better than mine (mine is rather when you don't work with peasy)

    see peasy reference

  • Thanks, I will see. And what about my question about coordinates?

  • Anyway, thanks for a quick response!

  • is it possible to compare 3d object and red brush coordinates, when one of them is in 3d, and another in 2d?

    Good one.

    Hm.....

  • I want to create something like deform or sculpting brush, so comparing of coordinates is important.

  • I don't know...

  • Of course there is screenX, screenY to get the 2D coords of something to compare to mouse

  • yes, I thinking of screenX and screenY too.

  • These are actual commands

    Look them up in the reference

  • I already used them in another projects, but now I begin to learn programming of 3d, and a lot of questions again)

  • @Chrisir Is it nescessary to call noLights() twice, once before and once after hint()? (Line 4 and 7 of ur code).

Sign In or Register to comment.