Shop OBEX P1 Docs P2 Docs Learn Events
Wire frame graphics, how does it work? — Parallax Forums

Wire frame graphics, how does it work?

science_geekscience_geek Posts: 247
edited 2009-08-14 03:46 in General Discussion
I am wondering how a computer program like autocad or solidworks can do wire frame graphics and then be able to rotate the object. My biggest concern is with perception. I know how 2 point perspectives and isometric views can be drawn, but how can they be moved and rotated in "space". Is there some grand algorithm that allows an object to be drawn and then all points are moved? Any info on wire frame graphics is appreciated. My plan is to experiment with the propellor and a display i have lying around to make an uber basic cad program, nothing to fancy...yet.

Comments

  • PhilldapillPhilldapill Posts: 1,283
    edited 2009-08-10 05:09
    It's all about the linear transformations... [noparse]:D[/noparse]
  • LeonLeon Posts: 7,620
    edited 2009-08-10 10:03
    Use quaternions!

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-10 17:48
    I did a 3D wireframe graphics object, which you can download here: http://forums.parallax.com/showthread.php?p=814675. The math is pretty much undocumented, but you might be able to glean something from the source code.

    -Phil
  • Agent420Agent420 Posts: 439
    edited 2009-08-13 19:59
    Jed Margolin, a former Atari engineer who worked on such vector classics as Asteroids, Battlezone and Star Wars, has a good article on Unit Vector Math for 3D Graphics.· If you poke around his site you'll find great articles on xy vector monitors and other topics.

    Post Edited (Agent420) : 8/13/2009 8:12:39 PM GMT
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2009-08-14 00:35
    Phil Pilgrim (PhiPi) said...
    I did a 3D wireframe graphics object, which you can download here: http://forums.parallax.com/showthread.php?p=814675. The math is pretty much undocumented, but you might be able to glean something from the source code.

    -Phil
    Hi science_geek,·

    this is an interesting subject.

    If you've not looked at it yet,·Phil's 3d_graphics.spin file (in the zip in the link above) has some nice, clean examples of matrix transforms.
    ( @Phil, nice·work·! )

    I'd also second Leon's suggestions of using quaternions - they·avoid rotation 'gimble lock' and jumping.· They are actually easier to use than to pronounce. [noparse]:)[/noparse]··

    And as Agent420 mentions, you really have the choice of using vectors, matrices, quaternions, or (my favorite) homogeneous cooridinates. Really, under the hood, these critters are nothing more than arrays of numbers with rules (looping algorithms) for adding, multiplying etc. If you want to dig in, read up on all of these. (Homogeneous coords are the hardest to visualize but are essential to projective geometry. When you see an object rotating in 3d on a screen, you are really using projective geo - the focal point is not really the flat screen.)

    For simple x,y, and z systems·you have (essentially) 3 dimensions in your array. Quaternions and/or Homogeneous coordinates add more -·I'm fudging a bit·here to keep it simple (Quaternions·use 'complex' numbers, and homogeneous coordinates can have any number of dimensions [noparse][[/noparse]degrees of freedom], with 4 typical for basic projection of 3d objects.)

    The trick really is figuring out which of these will best meet your needs - if it's simple motion and the illusion of 3d rotation and depth changes, then study/use Phil's code - at first glance, I'd say his matrix function 'scale' is the one doing the depth changes.· If you need something more sophisticated, you might want to jump right into quaternions and homogeneous coordinates.· Quaternions have been used for > 150 years for representing mechanical motion and in physics extensively.

    from Phil's code, line 210, this is a good example of 3 dimensions, 'delta' being change
    PUB translate(deltax, deltay, deltaz)
    ' Translate the next points and lines by (deltax, deltay, deltaz).
      tmatrix[noparse][[/noparse]3] += deltax
      tmatrix[noparse][[/noparse]7] += deltay
      tmatrix[noparse][[/noparse]11] += deltaz
      _transform
    

    For a *very nice* software package that can teach us all a thing or two about projective geometry and non-euclidean geometries, take a look at this application:

    http://www.cinderella.de/tiki-index.php

    Under the hood,·that app is·all done with homogeneous coordinates.

    cheers,
    - Howard

    PS the wiki articles are good, IMO· (When you start to get a headache reading this stuff, just remember it's merely the manipulation of numbers with code!)

    http://en.wikipedia.org/wiki/Quaternion
    http://en.wikipedia.org/wiki/Projective_geometry
    http://en.wikipedia.org/wiki/Homogeneous_coordinates


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Post Edited (CounterRotatingProps) : 8/14/2009 12:40:15 AM GMT
  • pharseidpharseid Posts: 192
    edited 2009-08-14 03:46
    · It doesn't end at wire-frame either. Instead of drawing the lines of your polygons, you can use the result of your line drawing routines to find the starting and ending point for doing a horizontal line fill to fill your polygons. While the existing Propellor boards don't offer many colors, you could use dithering to do shading. And you can add texture coordinates to your vertex coordinates that will allow you to do texture mapping. I'm sure you won't want to start with all these goodies, but once you have the wire-frame done, each of these is just another step of add-on.

    -phar
Sign In or Register to comment.