ftp.nice.ch/pub/next/graphics/3d/Hidden.0.01.README

This is the README for Hidden.0.01.NI.b.tar.gz [Download] [Browse] [Up]

Hidden	V0.01 alpha Preliminary
© 1992 by Stefan Holzinger

Overview

This program is only a demo. Its mainly use was to teach me the use of this machine. You may freely copy it as long as you don't delete my copyright message. It was quite a lot of work. So just be kind to this code!
I don't know if this program is of any use for anyone. I guarantee for the existence for a great number of bugs, ill-designed algorithms and especially runtime inefficiencies.
If you use this program you do it on your own risk!
If you decide to use some of the sourcecode be aware of the deficiencies and please insert my name in your copyright message. Keep in mind that this code is copyrighted!
If you haven't got the sourcecode contact me at:

	Stefan Holzinger
	Klitschgasse 20/B
	1130 Wien
	AUSTRIA
	% ((USA:01143) 222) 84 57 464

Sorry, I'm working on a single machine, no ethernet and not even a modem in sight (sigh!). So please write me or phone me if you are interested on code, updates (??) or if you want to help my billfold.

As the name of the program suggests it tries to draw objects (note the lower letter 'o' to distinguish from Objective-C Objects) as we see them in the natural way we see them every day. Note that I don't have the knowledge to implement a hidden surface algorithm or something even better ± I settled down with a hidden line algorithm. Don't boo me ± I'm really proud I got that far!

This program works on following data:
	a list of points
	a list of lines (two indices of points)
	a list of facettes (a list of indices of lines)
To display an object  the program first calculates a transformation (based on various user definable parameters). If you selected to display just a wire frame the rest is easy: run through all the lines and draw them (the facettes aren't even touched!). If you selected to draw the objects as if they were massive it's getting more involved:
	for every line:
		for every facette:
			look if facette hides some part of this line. if it does mark the part
		draw the (parts of the) line

Things start growing more complicated when you allow form multiple objects, multiple windows...
The algorithm should work fine with multiple parts of a line invisible and parts in between still visible.
Note that this program does no checking on input data. It is of great importance to validate your data or you will end up with a lot of rubbish. Note also that this program was written light-handed ± I didn't have enough time to debug it thorougly. 


Parameters:

Parallel projection:
alpha:	horizontal rotation.
0 degrees:	you're looking parallel to x-axis
90 degrees:	you're looking parallel to y-axis.
beta: 	vertical rotation (elevation).
0 degrees:	you're looking exactly horizontal
90 degrees:	you're looking straight down.
All other parameters should have no effect.

Zentral (normal) projection:
alpha:	horizontal rotation.
0 degrees:	you're looking parallel to x-axis
90 degrees:	you're looking parallel to y-axis.
beta: 	vertical rotation (elevation). [isn't shown in View Direction Panel]
0 degrees:	you're looking exactly horizontal
90 degrees:	you're looking straight down.
X displacement,
Y displacement:	horizontal movement of reference point.
Z displacement:	distance of eyes from the floor.
eye distance:	distance of eyes from your object(s). If you get closer you'll get a stronger effect.
eye separation:	distance between the eyes. This is useful for stereo projection only.

Reference Point:
The lowest nearest and rightmost point for alpha >= 0 else leftmost. Note that this leads to some 'jumping' when changing sign of alpha.


Examples:

I've included a few examples. They are:

Koordinaten.hide	x, y, z axis for better reference
Pyramide.hide	a six-sided pyramid
Tetraeder.hide	a tetraeder
Wörfel.hide	a cube
Bröcke.hide	a bridge; well, no facettes included
Multi.hide	3 objects (beautifully assembled)

Note that it's possible to store multiple objects in one file! When saving the program looks for selected objects ± not for drawn objects.


File Format:

The file format for a single object is:

Hidden   version number (currently 1.01)
SingleFile
Name of object
number of points
number of lines
number of facettes
for each point:	x 	y	z
for each line:	index of first point	index of second point	line width	line type	 color (R G B A)
for each facette:
number of lines in this facette
for each line in this facette:	index of line

The file format for multiple objects is:

Hidden   version number (currently 1.01)
Multiple file:   number of objects    name of collection
Name of object
number of points
number of lines
number of facettes
for each point:	x 	y	z
	for each line:	index of first point	index of second point	line width	line type	 color (R G B A)
for each facette:
number of lines in this facette
for each line in this facette:	index of line
< this body is repeated for every object >

Tip: look into example files


Caveats:

·	Facettes have to be contiguous and convex (i.e. no holes, no gulfs etc).
	Workaround: separate these facettes into multiple facettes using invisible lines if you wish (just set alpha to 0). This problem is inherent to the algorithm.
·	Alpha not being opaque or completely transparent is ignored. 
·	Avoid objects intersecting one another. 
·	Unknown results for points behind the eye (think of something behind your head).
·	This program should be a editor for objects not just a viewer. You'll have to create your objects manually until the next release of Hidden.


Known Bugs:

Massive mode doesn't work for all angels for natural (and stereo) projection.
Here I know where to look at ± I didn't have time to fix this. Increase eye distance to avoid this.
Command-number doesn't work when Inspector wasn't displayed before.
I think I should add something to Menu to fix this. Does anyone have a good idea?
Editing of Objects not fully implemented (insertion and deletion, cut & paste,... missing)
Objects cannot be copied, pasted, deleted...
Multiple windows should be allowed.
It isn't (yet) possible to save your drawing into an .eps file.
Program should start without displaying an object (the cube).

Note: I won't change anything on this code until NeXTstep 3.0.


Important classes within Hidden

StoreObject class
This is the Controller Object. This is currently only able to store one ObjStorage (i.e. one window). It will be added a support for multiple windows.

ObjStorage class
This Object stores a list of an array of a struct containing ids pointing to the arrays of Punkte (points; a Storage containing the coordinates of the points), Geraden (lines; a Storage containing the indices of 2 points each), Facetten (facettes; a D2Storage containing indices of lines), ZweiDim (a Storage containing the transformed coordinates of the points) and a name. To do so it uses a Storage object.
Additionally it is able to manage a selection: The transformation and display modules like to see only a single array of points, lines and facettes regardless of the selection by the User  (He can do so in the Inspector). The difficulty lies in the dealing with 'holes' in the selection and the need to update the indices.

D2Storage class
As Storage but uses a List to hold the ids of Storage Objects. Note the ease of doing so!

ResultView class
This is used to display the results. Includes the hidden lines algorithm.

BildebeneView class
This is used to select the viewing direction.

ProjectType class
This controls the panel to select the type of the projection.

ProjectBer class
Does the real calculation.

Inspector class
This is the controller of the Inspectors. It uses .nib files like the IB. It also uses NiftyMatrix and NiftyMatrixCell classes for the ScrollView to select the object.

InspectorObject class
InspectorPunkte class
InspectorGeraden class
InspectorFacetten class
used by Inspector to inspect various things.

InspectorMove class
InspectorScale class
InspectorRotate class
same as above but allows multiple selection.

InspectorNoAvail class
What would you think?

NiftyMatrix class (stolen from ScrollDoodScroll)
The NiftyMatrix class differs from the Matrix class in that a NiftyMatrix allows the user to rearrange cells, as InterfaceBuilder lets you do with menu items.  If a user control-clicks on a cell, that cell will follow the mouse as the user drags it, leaving a ªwellº in its place.  When the user releases the cell over another cell in the matrix, the NiftyMatrix places the control-dragged cell in that location and slides the other cells up or down in order to fill the vacant spot.  
Has to be added a connection to the objects themselves. (StoreObject)

NiftyMatrixCell class (stolen from ScrollDoodScroll: CustomCell)
The CustomCell class demonstrates how, by overriding the drawInside:inView: method, you can display graphics and/or text at different locations within the cell.  CustomCells place a TIFF image at the cell's left-hand side, followed by a right-justified, dark-gray number, followed by a text string.

LanguageApp class (stolen from Mandelbrot)
Marvellous! See there! Should be standard in Version 3.0. (Some addings are needed for soundfiles)


Interesting Stuff

ObjStorage class
How to manage a selection reindexing the database.

CustomCell
How to draw whatever you want within a cell

Inspector
How to load .nib files and how to change subviews.
	
NiftyMatrix
How to implement autoscrolling
Using off-screen image buffers for fast drawing

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.