home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac / raycst.zip / README.TXT < prev    next >
Text File  |  1994-05-13  |  6KB  |  149 lines

  1. HEIGHT MAPPING
  2. --------------
  3. Leo Sutic [100040,600]
  4.  
  5. DISCLAIMER/LEGAL STUFF/IT'S NOT MY FAULT DEPT.:
  6. This is provided as an example of height mapping on the pc. Use it at your own
  7. risk. If it destroys your hard drive, then that is your problem. Feel free to
  8. modify it, use it in your own programs and distribute it.
  9. All product names are trademarks or registered trademarks of their respective
  10. holders.
  11.  
  12. DESCRIPTION
  13. -----------
  14. This is my height mapping engine. It is written in Borland C++ with some
  15. assembler parts.
  16.  
  17. HOW IT WORKS
  18. ------------
  19. The screen is divided into 320 columns. If you think about it, a ray that is
  20. sent away from your eye through column 0 (the leftmost) won't be parallell to
  21. a ray that goes through column 319. Now, what the mapper does is to trace all
  22. 320 rays as they come from the horizon into your eye.
  23.  
  24. _____________________________
  25. | \   Visible area      /   |  Suppose that we followed the middle ray from the
  26. |  \                   /    |  horizon to the user, and plotted the altitude
  27. |   \                 /     |  on a diagram as we went along.
  28. |    \    Looking    /      |
  29. |     \   this way  /       |  The result would be something like this:
  30. |      \     ^     /        |
  31. |Rest   \    |    /         |  |                       ____
  32. |of the  \   |   /          |  |      _               /####\__
  33. |world    \  |  /           |  |     /#\   ____      /########\      _
  34. |          \ | /            |  | _  /###\_/####\    /##########\_   /#\
  35. |           \|/             |  |/#\/############\__/#############\_/###\______
  36. |            o <- User      |  |##############################################
  37. |___________________________|  |^--------------------------------------------^
  38.                    Horizon                                     User
  39.  
  40. Now imagine that you cut out the filled parts of the diagram, and repeated the
  41. process for ALL rays. Then looked at the diagrams head on. This is what the
  42. height mapper does.
  43.  
  44. I know that this description isn't very good, so if you have any questions,
  45. please contact me.
  46.  
  47. THE FUNCTIONS
  48. -------------
  49.  
  50. Remember, RAYCAST.CPP uses a 1280 (320*4) degree system. 320 degrees is
  51. a quarter of a circle.
  52.  
  53. void DrawSky (int Angle,int l)
  54. Draws the correct column of the sky image. Angle is the angle of the column
  55. you want to draw, and l is the screen x coordinate do draw it at.
  56. DrawSky (320,160) would draw the sky as seen at 320 degrees at column 160.
  57.  
  58. void DrawIt(int startpos, int r, int xpos, int OldPos, unsigned char c)
  59. Draws ONE "height line". This function is called only be DrawLine.
  60. Startpos is the y coordinate to start drawing on, r is the distance to
  61. that point, xpos is the x coordinate to draw it at, OldPos is the last
  62. startpos value and c is the color.
  63.  
  64. void DrawLine (int xpos)
  65. Height maps the column xpos. To create the entire image, call DrawLine in
  66. a for loop like this:
  67.  
  68. for (int i=0;i<320;i++)
  69. {
  70.   DrawLine (i);
  71. };
  72. BlitBuffer();
  73.  
  74. void InitSinCos(void)
  75. Initializes the sine and cosine tables used in DrawLine.
  76.  
  77. void InitStartPosTable(void)
  78. Creates a lookup table for perspective transforms. Used only in DrawLine.
  79.  
  80. void DupCols(void)
  81. Duplicates the columns on the screen. Column 1 will be identical to
  82. column 0, column 3 to column 2 and so on.
  83.  
  84. void BlitBuffer (void)
  85. Transfers Buffer to the screen.
  86.  
  87. void DrawCockpit(void)
  88. Ovarlays the static instrument panel image on top of the landscape image.
  89. Color 9 is transparent.
  90.  
  91. THE DATA FILES
  92. --------------
  93. The data files are standard Windows bitmaps. The mapper will skip the first
  94. 1078 bytes and read in the binary data. COLOR.BMP contains the color
  95. information, and ALTITUDE.BMP contains the altitude data. SKY.BMP is the sky,
  96. and RAYCAST.COL contains the palette. Both COLOR.BMP and ALTITUDE.BMP must be
  97. 256x256x256.
  98.  
  99. HOW I CREATED THE DATA FILES
  100. ----------------------------
  101. Mostly, I used Fractint. First of all, I created a plasma cloud with a
  102. resolution of 320x200x256. This was used for altitude data. Next, I did a
  103. 3D transform with "Light source after transformation" and Targa output. The
  104. main thing here is to set the X Scale and Y Scale to 100 and to turn off
  105. perspective transformations. If you do this, fractint will output an image
  106. of the "world" as seen from above with shading etc. This image can then be used
  107. as a COLOR.BMP.
  108.  
  109. Then I loaded the Targa file and the sky image into Photo Styler, and placed
  110. them beside each other on the same image. Then I reduced the color depth to
  111. 8 bits (256 colors). This gave me a palette that I could use for both Color.BMP
  112. and SKY.BMP. After that I splitted the image into two and saved them as 
  113. COLOR.BMP and SKY.BMP. Ooops! Almost forgot... Before saving COLOR.BMP and 
  114. ALTITUDE.BMP, I scaled them to 256x256.
  115.  
  116. OPTIMIZING
  117. ----------
  118. Yes, yes, yes! I know it is a slow program! Ways to optimize it would be
  119. 1. Bresenham's algorithm is currently written in C (oh dear). I'm currently
  120.    porting it to assembler.
  121. 2. When drawing every other column, use stosw instead of stosb, and skip
  122.    DupCols().
  123. 3. Write it all in 386 assembler. Perhaps 386 Flat mode.
  124. 4. Disassemble Comanche and see how they do it.
  125.  
  126. VOXELS
  127. ------
  128. What is a voxel? When you divide a plane in negative/positive parts you end
  129. up with quadrants, right? Now, when you divide a cube the same way you'll get
  130. octants. Imagine the following structure:
  131.  
  132. struct Voxel
  133. {
  134.   Voxel* Octants[8]
  135. };
  136.  
  137. Every octant contains a pointer to another voxel, whose octants in turn
  138. contains pointers to more voxels and so on. If an octant is empty, it doesn't
  139. point to another voxel. This is repeated until every octant represents one
  140. pixel.
  141.  
  142. From this description it is pretty obvious that any flight sim using voxels
  143. would be terribly slow. The term "Voxel space" is actually misleading, since
  144. Comanche doesn't use voxels (as far as I know).
  145. ______________________________________________________________________
  146. Leo Sutic
  147. CIS ID:[100040,600]
  148. Internet: [100040.600@compuserve.com]
  149.