ever
Scholar
- Joined
- Nov 13, 2008
- Messages
- 886
SCO said:You must be some kind of super coder. I've been making a graphical interface for two years and i'm still finding bugs and ways to avoid them.
Hmm, I' m nota super coder, I didn't create crysis or anything just something like doom. This is what I accomplished in five days with no prior coding experience:
a)Managed to get a defined line segment face with a height variable in the struct drawn by means of ray casting
b)This came with things like a camera rotation of the camera movement of the camera etc.
c)Store all my line segment faces (I called them sides) in a binary space partioning tree (this was the grand daddy it allowed for z-ordering and some backface culling)
d)Draw the bsp with zero chance of error
e)some kind of crappy lighting algorithm where I mess around with the RGB values just based on how far away the camera is from the side being drawn.
f)collision detection using the bsp tree
That is all. No bugs anymore either. If I ever get more free time when I am not running my business I plan to play around with some voxels and A.I on the non geometric side of things.
Code:
Side splitSide (Side side, Side dividingSide, boolean front) {
//Identifies which vertex of the side to be split is infront of the dividingSide and which is behind.
Vertex containedVertex = inlyingVertex (dividingSide, side.segment.vertex1, side.segment.vertex2);
Vertex outlyingVertex = outlyingVertex (dividingSide, side.segment.vertex1, side.segment.vertex2);
//Split coordinates.
float splitX;
float splitY;
Vertex splitVertex; //the vertex at split
LineSegment splitSegmentFront; //lineSegment for front side of split
LineSegment splitSegmentBack; //back side
Side sideBack;
Side sideFront;
//If the lineSegment of the side is perpendicular to the X-axis splitVertex X and Y are determined by substituting one the side's X into the dividing side's segment
//line equation
if (side.segment.perpX) {
splitX = side.segment.vertex1.X;
splitY = dividingSide.segment.gradient * side.segment.vertex1.X + dividingSide.segment.Yintercept;
}
//If the lineSegment of the dividingSide is perpendicular to the X-axis the program does the same as above but vice versa.
else if (dividingSide.segment.perpX) {
splitX = dividingSide.segment.vertex1.X;
splitY = side.segment.gradient * splitX + side.segment.Yintercept;
}
//If neither side segment is perpendicular to the x axis then their line equations are solved simulatenously to give the intercept coordinates.
else {
//Using the identity x = (b2 - b1) / (m1 - m2) to solve X simulatenously, then sbustituting that for the Y solution.
splitX = (dividingSide.segment.Yintercept - side.segment.Yintercept) / (side.segment.gradient - dividingSide.segment.gradient);
splitY = side.segment.gradient * splitX + side.segment.Yintercept;
}
splitVertex = new Vertex(splitX, splitY); //constructs the vertex at split
splitSegmentFront = new LineSegment(splitVertex, containedVertex); //creates the LineSegment for the front Side
splitSegmentBack = new LineSegment(splitVertex, outlyingVertex); //ditto for back Side
//sets height values to be the same as the parent line.
splitSegmentFront.setHeight(side.segment.heightValue);
splitSegmentBack.setHeight(side.segment.heightValue);
//After the lineSegments have been constructed appropriately then the program can finish splitting the side by constructing one of the two resulting sides as ordinated
//by the boolean in argument.
if (front) {
sideFront = new Side(splitSegmentFront, side.sideValue);
sideFront.defineColors(side.R, side.G, side.B);
return sideFront;
}
else {
sideBack = new Side(splitSegmentBack, side.sideValue);
sideBack.defineColors(side.R, side.G, side.B);
return sideBack;
}
}
There have some code used for bsp tree creation.
I am super duper proud of my small accomplishments and I will not have you doubting them!