Share My Creation Simple 3D Wireframe Object

Discussion in 'Share Your Creations' started by lucas heer, Apr 26, 2015.

  1. lucas heer

    lucas heer New Member Licensed User

    Hello! This is one of my first B4A apps I have made. This app allows you to display a set of nodes, faces in wireframe. You can also rotate the object by dragging your finger across the screen. It was a little difficult to make, mainly cause I don't know the little differences between B4A and .Net Basic.

    Pretty sloppy code, only took me a few hours.

    Uses RotateX to rotate Y-Nodes, Uses RotateY to rotate X-Nodes. Loops through the nodes in the array of objects held by the object structure and edit their values. Pretty simple. Although, I don't know much trig or geomety, im only in pre-algebra. If anyone wants to help me shade the object, I already made faces instead of edges, but I'm only in pre-algebra so I don't know much trigonometry or geometry and I can't really figure it out :D Thank you

    wonder, ilan and Erel like this.
  2. lucas heer

    lucas heer New Member Licensed User

    I finally got shading to work, using Painters Algorithm. Which is basically adding up all the y-values and ordering the nodes or vertices from lowest to highest and displaying back sides first. Its a little glichy, on the cube, the 2 sides other than the most-facing front side switch colors. Still trying to figure out why :( It works in .net though. I used list in .net vb to organize Z values from low to high so that might be why. Thanks :D

    Still sloppy code :

    Mashiane and Peter Simpson like this.
  3. sorex

    sorex Expert Licensed User

    @lucas heer : there are several ways to get it done right, but z-sorting is indeed the way to go to get some neat effects.

    here is a screenshot of what I wrote 3 years ago as a sort of Android speed test to see how fast my low end phone was.
    ran quite well knowing that it (3DS dolphin) contains 562 polygons (285 vertices) and used only the core drawing routines.

    Using openGL would be a lot faster but I never got to that so far.

    inakigarm, JordiCP and Peter Simpson like this.
  4. Peter Simpson

    Peter Simpson Expert Licensed User

  5. sorex

    sorex Expert Licensed User

    this is the most important part of the routine which recalculates vertices positions

    For n=0 To vertices.Size-1
    Dim co As coord
    x3d = v.x
    y3d = v.y
    z3d = v.z      
    ty = ((y3d * 
    Cos(vx)) - (z3d * Sin(vx)))
    tz = ((y3d * 
    Sin(vx)) + (z3d * Cos(vx)))
    tx = ((x3d * 
    Cos(vy)) - (tz * Sin(vy)))
    tz = ((x3d * 
    Sin(vy)) + (tz * Cos(vy)))
    ox = tx
    tx = ((tx * 
    Cos(vz)) - (ty * Sin(vz)))
    ty = ((ox * 
    Sin(vz)) + (ty * Cos(vz)))
    co.x  = (
    500* (tx) / (distance - (tz))) +135
    co.y  = (
    135 - (500 * ty) / (distance - (tz)))
    c=( ( tz+
    lucas heer, ilan and Peter Simpson like this.
  6. Peter Simpson

    Peter Simpson Expert Licensed User

    I was not expecting that @sorex :D
  7. Douglas Farias

    Douglas Farias Expert Licensed User

    This is b4a xD????????
  8. lucas heer

    lucas heer New Member Licensed User

    I was wondering what your coord structure looked like, and sorry for noobiness, I'm only at pre-algebra math level lol, but what are 135 and 500 for? Also, how would u go about calculating Z-locations for ordering the order of drawing faces? Thanks :D
  9. sorex

    sorex Expert Licensed User

    sure, it's just math ;)

    @lucas heer :

    the coord is just a type

    Type coord (x As Int, y As Int,z As Int, col As Int)
    I sum the 3 z values and divide it by 3 to get the avarage and sort on that.

    the odd values is to center/scale it. the inital data looks like

    2.229 9.601 0.4095
    1.96 9.639 2.145e-005
    3.905 11.39 2.389e-005
    4.288 11.33 0.3073
    5.567 12.19 2.486e-005
    5.734 12.04 0.1793
    7.156 12.31 2.486e-005
    7.241 12.1 0.06399
    8.06 12.07 2.486e-005
    7.182 9.113 0.4991
    7.156 10.02 2.194e-005
    7.689 8.768 2.047e-005
    so that would be a very tiny dolphin if you stick to that ;)
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice