Posted: 18th Jun 2007 19:32
Hello again everyone.

In this thread, I'd like to know how I could do the following with nothing more than algebra, the core commands, and the "dot" command:
Draw a line between any 2 points
Draw a loaded 2D image
Draw a 3D wireframe

I feel that could I do this, I could use the line to draw the wireframe for the 3D object and morph the 2D image to texture it.

No one seems to be able to tell me how things are actually textured at the level I'm looking for, they just keep telling me that you use the "texture object" command. And thats not what I'm looking for.

I also can't make a 3D wireframe without using the line command.

Surely someone is a good enough programmer here to be able to help me...

Cowbox
Soharix HQ
http://www.soharix.homestead.com/
Posted: 18th Jun 2007 20:21
So what you want is, Oh about the equivalent of the first 12 chapters of the book 'Tricks of the 3D Game Programming Gurus' posted here to the forum ... actually, it's not quite that bad, but it's close

Rather than start with an all-in-one post like this, you might find it better to learn in smaller steps:
1, Positioning and rotating a point in 3D space in relation to a viewpoint (ie, the camera)
2, Drawing a line between 2 dots in 3D space
3, Clipping a line to the display
4, Assembling a 3D wireframe object from multiple lines, including clipping
5, Implementing a flat-colour rasteriser to fill your object
6, Implementing a z-buffer to ensure object is rendered correctly.
7, Implementing a gourand-shaded rasteriser to fill your object using vertex colouring (basic interpolation)
8, Implementing a texture rasteriser (interpolating uv coords to get a texture coordinate)

These steps get bigger and harder as you work through them (actually, the jump from step 7 to step 8 isn't too difficult).

Somewhere in there you'll probably want to extend the line clipping to include full object clipping within the viewing frustrum, but that's only (!) a speed optimisation, and you don't need to know it to actually render.
Posted: 18th Jun 2007 20:46
Wireframe 3D stuff from 2D lines;

http://forum.thegamecreators.com/?m=forum_view&t=99092&b=6
Posted: 18th Jun 2007 21:00
The simple way is...

SET OBJECT WIREFRAME ObjectNum, 1

I wonder if you can guess what film I was recreting here?

Posted: 18th Jun 2007 22:18
In this thread, I'd like to know how I could do the following with nothing more than algebra, the core commands, and the "dot" command:
Draw a line between any 2 points
Draw a loaded 2D image


How are the line endpoints specified?
What do you mean by "draw"?
Posted: 19th Jun 2007 0:48
@IanM Yes I suppose they are what I was looking for, and those chapters word it better than the way I was describing it.

@spooky I shall have a look at that.

@Gatorhex I don't want to know how to make an object made elsewhere look like a wireframe in DBP. (Thats easy) I want to create my own.

@heartbone I don't know what you mean by endpoints and by draw I mean light up pixels on the screen relating to something saved as data.

Cowbox
Soharix HQ
http://www.soharix.homestead.com/
Posted: 19th Jun 2007 15:31
I think he's asking how you are expecting your vertices to relate to the game world - I suggest that you stick with the well methods.

Vertex as an offset to the object origin, rotated around that origin.
Offset by the world coordinates.
Offset by the camera coordinates, rotated about the camera.

So, take your point, rotate it by the camera angles, add the objects world coordinates, subtract the camera coordinates, rotate by the reverse of the camera angles, transform to screen space.

If you can get that running for a dot, you can do it for a collection of dots, then you can draw lines between them etc.
Posted: 19th Jun 2007 17:58


My, thats aweful complex. I think I understand it, I just don't really get how to implement it or create it in the first place.

Are there any examples of code similar to this concept?

And I agree (as I thought last night) if I can calculate a 2D line between 2 dots and I can calculate 3D dots I can make an accurate wireframe. (Then I just need to get how to texture that.)

Any more help would be apreciated.

Cowbox
Soharix HQ
http://www.soharix.homestead.com/
Posted: 20th Jun 2007 15:36
My, thats aweful complex


That's the territory. I'll see if I can come up with something for you to work with - I hope you don't mind me using the built-in vector/matrix maths as I've go no intention of going lower-level than that.
Posted: 20th Jun 2007 16:29
There's been a few examples of software renderers in DB/Dbpro over the years.

This thread has links to few threads with examples. http://forum.thegamecreators.com/?m=forum_view&t=102348&b=6
Posted: 20th Jun 2007 17:34
If you're not avoiding dll's then you could use Cloggy's d3d_func for it's "d3d_line3d" command. This would make it a lot simpler to draw a wireframe because you do not have to consider the camera's position and angle.
Posted: 20th Jun 2007 19:06
@Daemon Well I recon I'd disclude DLLs mainly because it wouldn't be entirely my engine (say I made it).

@Ian Thanks and yeh I'm not bothered about the 3D maths commands because that'd probably confuse me even more.

Cowbox
Soharix HQ
http://www.soharix.homestead.com/
Posted: 20th Jun 2007 21:12
@C0wbox
1) If the 3d maths commands confuse you, there is NO WAY you are going to be able to convert 3d points to 2d.
2) Try wikipedia on 'graphics pipeline' It has everything you need to know about it.
3) Learn what matrices are, and what euler angles are (wikipedia again)
4) Learn about rasterization (The process of drawing a filled triangle)

I will help you a bit, by giving you the code to draw a line between two points:
+ Code Snippet
function Line2D(x1 as float,y1 as float,x2 as float,y2 as float)
xd as float
yd as float
mx as float
xi as float
yi as float
xd = x2-x1
yd = y2-y1
if yd>xd
mx = yd
else
mx = xd
endif
xi = xd/mx
yi = yd/mx
for i = 0 to mx
x = (xi*i)+x1
y = (yi*i)+y1
dot x,y
next i
endfunction


I just wrote that in the post window, so there may be a few errors, and you should be able to make it more efficient.
Posted: 20th Jun 2007 21:38
I didn't say I'd get confused with the 3D maths commands, I said that if I went any deeper into this than those commands then I would start to get confused. (But I'd probably get confused initially with the 3D maths commands (having never used them before).)

Also, what am I meant to do with that function?

Cowbox
Soharix HQ
http://www.soharix.homestead.com/
Posted: 20th Jun 2007 22:01
[edited]
Posted: 21st Jun 2007 0:29
<Edited out because it is now erelevant.>

Cowbox
Soharix HQ
http://www.soharix.homestead.com/
Posted: 21st Jun 2007 0:33
@C0wbox
My function draws a line between two points. x1,y1 and x2,y2 are the two points.
A float is a number which can have a decimal point.
An integer is the same, but you can't have a decimal point.
Posted: 21st Jun 2007 0:41
Thank you.

So basically your code replaced the "line" command.

And it doesn't do the 3D stuff as well?

(So I still have to work out how to calculate a 3D point?)

Cowbox
Soharix HQ
http://www.soharix.homestead.com/
Posted: 21st Jun 2007 21:20
Here is a link to the wikipedia page all about converting 3d points to 2d ones.
The process is called 3D Projection. You need to read all of it.

Here is a wikipedia link explaining all about matrices. (No, not the very slow grids used by noobs for terrains in DBPro j/k)

The important topics in that to read are:
Definitions and notations
Scalar multiplication
Matrix multiplication

That is the minimum you need to know about matrices in order to do 3D Projection.
Posted: 22nd Jun 2007 0:47
Lol, I'd tried reading that before. It didn't seem to make much sense to me.

The four matrices are multiplied together,


"How" are they multiplied together? And surely 0s and 1s would only come out with 0,0,0 or 1.

<Is confused.>

Cowbox
Soharix HQ
http://www.soharix.homestead.com/