To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.cadOpen lugnet.cad in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 CAD / 5674
5673  |  5675
Subject: 
Re: VB - parts and transformation matrices, Z-ordering, optional lines, bow-tied quads - help!
Newsgroups: 
lugnet.cad
Date: 
Mon, 26 Mar 2001 16:13:29 GMT
Viewed: 
414 times
  
In lugnet.cad, Daniel Crichton wrote:

1). If I load up 3626bp01.dat everything looks fine except the eyes, the
disc and cut-out primitives are placed in the middle of the head and
slightly rotated. I've toyed with the idea that the matrix I'm using is
wrong but it works for every other subpart and primitive, so I'm a bit
stuck. And it happens with all heads with eyes, and makes a complete mess of
torsos with patterns. I'll post some outputs to Brickshelf if anyone is
interested in helping and needs to see what is happening.

Sounds like it's a problem in your code to handle type-1 lines.  Could you
post some images of the problem renders?

2). Z-ordering. At the moment I'm just drawing the polygons in the order
they appear in the DAT files, but obviously I need to handle Z-ordering so
that the parts are rendered correctly. Any idea on where I might find some
sample VB code that could be applied to DAT files easily, or a pointer to
algorithms I could write in VB to handle this?

You can't completely sort polygons by z-order -- some polygons cross each
other in z-depth.

Are you using a z-buffer to track the z-depth of each pixel in the x-y
raster?  The basic, non-optimized approach is something like this:

' Module RenderLDraw
Private aZBuf() As Long  ' Distance from viewer values
Private aImage() As Long ' RGB values or LDraw color codes
Private Const MaxDepth = 2147483647

Sub InitImage(iWidth, iHeight)
   Dim i As Long, j As Long
   Redim aZBuf(iWidth, iHeight) As Single
   Redim aImage(iWidth, iHeight) As Single
   For i = 0 to iWidth
      For j = 0 to iHeight
         aZBuf(i, j) = MaxDepth
      Next j
   Next i
End Sub

Sub DrawPoint(iColor, X, Y, Z)
   ' Is voxel(XYZ) closer to the viewer than the previous voxel
   ' which was mapped to pixel(XY)?
   If Z < aZBuf(X, Y) Then
      aImage(X, Y) = iColor
      aZBuf(X, Y) = Z
   End If
End Sub

Sub ProcessFile(whatever_params_are_necessary)
' Clear the scene
   InitImage iWidth, iHeight
' Process the file. Whenever a voxel needs to be rendered, call DrawPoint.
End Sub

3). Any sample VB code on handling optional lines? At the moment I just have
an option to turn them on and off, but if they're on I'm just drawing all
the lines indicated by the points which makes a bit of a mess, and I'm
having trouble sorting out the equations needed to work out which lines to
draw (it's been over 10 years since I left school and my memory's going).

Basically, you transform all 4 points into the screen-world, and then use
the just the XY components for testing.  One way to do the testing is to
construct a line-equation for P1P2, solve the equation using the P3X and
P4X, and see if P3Y and P4Y are both less or both more than the Y values
you solved for.

That's the long way around, there must be faster ways, but that's one
solution.

4). Any algorithms for sorting out bow-tied quads? I've found a few parts
that don't render well at all, and it appears that the points are not stored
in a clockwise/anti-clockwise direction, so my filled polygons come out as 2
triangles meeting at vertices.

LDraw sorts the 4 vertices (mapped into the screen-world) by ascending Y,
then increments from min(Y) to max(Y), drawing horizontal lines between the
outermost X values at each Y.  It's ugly and slow, but it does the job.

Steve



Message has 2 Replies:
  Re: VB - parts and transformation matrices, Z-ordering, optional lines, bow-tied quads - help!
 
(...) ... (...) Once upon a time I attempted to describe the 3D (world coordinate) algorithm for this. Try this link. (URL) that helps. Otherwise, you can look at the ldglite source code if you don't mind C. It uses the 2D screen coordinate method (...) (23 years ago, 26-Mar-01, to lugnet.cad)
  Re: VB - parts and transformation matrices, Z-ordering, optional lines, bow-tied quads - help!
 
(...) Posted to (URL) . The problem I have is with the eyes - the front view looks fine, it's just the side and top views where you can see the problem. This is 3626bp01.dat (the one with the POV definitions included, I just ignored them). The funny (...) (23 years ago, 26-Mar-01, to lugnet.cad)

Message is in Reply To:
  VB - parts and transformation matrices, Z-ordering, optional lines, bow-tied quads - help!
 
I've been messing with some VB code to read DAT files and draw them on the screen, and have been surprised at how quickly I managed to pull it together (esp. after spending some time poring over the LDraw FAQ trying to work out the transformation (...) (23 years ago, 26-Mar-01, to lugnet.cad)

8 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR