Point-Triangle Collision

I am creating a 3D engine that does not use wireframe, but rendering the triangles Is the problem! I have seen other code but I don’t understand it. https://www.openprocessing.org/sketch/6380#

What you don’t understand? Your question is really generic. It does not help anybody to ask this type of questions. Instead, try to provide a bit more context of what you want to do and what is your difficulty. Also, provide some code as it shows your current approach to your problem, and it shows your Processing code level. It really helps to provide more efficient feedback at the end.

Kf

3 Likes

I have 0 lines of code… I was already lost before I even tried to write a single letter, although here is the rest of my code : https://pastebin.com/m5B6fEZd

Hi Odermonicon,

The thing is that what you want to do is not clear enough.

I did not understand that sentence at all.

Please explain the context, then what you are trying to do and then what problem you are facing.

2 Likes

@Odermonicon – thank you for sharing your code. People on the forum have a fair amount of experience with 3D rendering, and are interested in your problem and would like to help you. However, you need to provide many more details and be more concrete. Consider if you asked this question about some other topic:

Eggs-Flour combination
I am creating a cake that does not use sugar, but beating the eggs is a problem. I have seen other recipes but I do not understand them.

or

Engine-Camshaft connection
I am creating a car that does not use gas, but camshaft rotation is a problem. I have seen other motor designs but I do not understand them.

Some example questions:

  • What is “a problem”, specifically? Which step doesn’t work, and how can you tell – what should happen, and what happens instead?
  • If it doesn’t use something, what does it use instead – or is that not relevant?
  • You have seen other examples – what are they? Can you link to them? Is one of them the inspiration for this project?
2 Likes

I would like a simple algorithm to draw a triangle pixel by pixel so I can draw triangles that are in front of each other. I honestly don’t know what else to say, I’m just lost.

I honestly still can’t tell if you are asking for a line drawing algorithm or if you don’t know how to draw a triangle in P3D.

  • Can you use PShape.vertex()?
  • Can you use beginShape(TRIANGLE_STRIP)?
  • Can you use beginShape(TRIANGLE_FAN)?

If you cannot use any of these things, and you are not allowed to or do not wish to for some reason…

…do you already have the algorithm for drawing your “pixel by pixel” line? if so, share it – and we can use that line algorithm to build the triangle algorithm. If not, you need to learn how to draw a line. Can you use PVector.lerp(), or do you need to write line rendering from scratch?

Here is an example of a few of the many ways you can draw triangles in P3D. Hopefully one of them is helpful!

PShape s;
PShape strip;

void setup() {
  size(200, 200, P3D);

  // make a triangle with PShape
  s = createShape();
  s.beginShape();
  s.vertex( 0, 0, 0);
  s.vertex(25, 50, 0);
  s.vertex(50, 0, 0);
  s.endShape(CLOSE);

  // make multiple triangles
  // using TRIANGLE_STRIP
  strip = createShape();
  strip.beginShape(TRIANGLE_STRIP);
  strip.vertex(  0, 0, 0);
  strip.vertex( 25, 50, 0);
  strip.vertex( 50, 0, 0);
  strip.vertex( 75, 50, 0);
  strip.vertex(100, 0, 0);
  strip.vertex(125, 50, 0);
  strip.vertex(150, 0, 0);
  strip.vertex(175, 50, 0);
  strip.endShape();
}

void draw() {
  background(192);

  // draw the triangle shape
  shape(s, width/2 - 45, height/2 - 45);

  // draw a copy of the triangle shape
  // that moves in z-depth according to
  // the mouse position.
  pushMatrix();
  translate(0, 0, mouseX);
  shape(s, width/2 - 45, height/2 - 45);
  popMatrix();

  // draw the strip of triangles
  // multiple times
  // ... rotate them in space
  pushMatrix();
  translate(10, height/2 + 45);
  rotateX(-QUARTER_PI/2);
  for (int i=0; i<5; i++) {
    translate(0, 0, -25);
    shape(strip, 0, 0);
  }
  popMatrix();

  // draw a triangle using lines
  pushMatrix();
  translate(180, 10);
  rotateZ(HALF_PI);
  rotateY(QUARTER_PI);
  line( 0,  0, 25, 50);
  line(25, 50, 50,  0);
  line(50,  0,  0,  0);
  popMatrix();
}

You may also be interested in Processing examples and tutorials like: