This site requires JavaScript, please enable it in your browser!
Greenfoot back
wabuilderman
wabuilderman wrote ...

2014/12/5

Still need help on 3d

wabuilderman wabuilderman

2014/12/5

#
Ok, so I have everything worked out, including a one stop hypot3d(x1,y1,z1,x2,y2,z2) (the x1 being the x of the point in question, the x2 being the x of the camera) method. BUT, It still boils down to rendering. From what I understand, I have to do a raycast to each point on the screen. How would I go about doing this? I have faces, which contain three vertices (no normals, but since there is no backface culling, I don't see how they are very relevant). I also have the image that is going to be displayed on the screen. What would I do to that image to tell it what to draw? Before, I would simply try and draw triangles in what ever order my code could come up with. Now I am just more confused. To strip it down to its basics, heres the stuff I have:
public GreenfootImage DrawSolid(GreenfootImage ImageToRender, ArrayList<Face> faces)
    {
        //render
        return ImageToRender;
    }
... yeah... as far as rendering goes, thats as advanced as I can get... How would I go about using those faces in an array, to be able to get the image I need in order to display?
davmac davmac

2014/12/6

#
I don't understand your method. It has a GreenfootImage parameter, but also returns a GreenfootImage - can you explain the purpose of the image that is passed in, and the purpose of the image returned? (Or are they meant to be the same image?) In any case, I think step one is sorting the faces in the arraylist according to depth. As I said earlier this is not exactly the same as "average distance from the camera" although that is a good approximation. To compare the depth of two faces you need to:
  • Consider the first face as a plane
  • Check whether all three points from the second face are in front of or behind the plane defined by the first face. There are several possible outcomes:
    • All points lie on the plane. In this case neither face is in front of the other.
    • Points are all in front of the plane (some may lie on the plane). In this case the second face is in front of the first.
    • Points are all behind the plane (some may lie on the plane). In this case the second face is behind the first.
    • Some points are in front and some points are behind. If this is the case, you need to perform the comparison the other way around (i.e. treat face 2 as a plane and check where face 1 points lie in relation to it). As long as your faces don't intersect you will get a resolution this time.
Next question: do you really want do raycasting? It seems like it would be much easier just to draw your faces directly (after depth-sorting them). In this case you just need to do a perspective transform on each point in each face, and render the face as a triangle on the screen. This might be a good first step anyway, as it will give you a visual result.
wabuilderman wabuilderman

2014/12/6

#
Thanks! As far as what the image is supposed to be, it is pretty much the screen. What I would do is then use Greenfoot's 2d Image tools to draw triangles on it. Pretty much: Image goes into method -> Image comes out with 3d components rendered to it.
wabuilderman wabuilderman

2014/12/6

#
Oh, but yes, I do want to do raycast. This project is primarily for the learning experience, and just in general, trying to master the art of 3d rendering. I will probably copy my code and try doing it another way.
You need to login to post a reply.