GameMakerHelpBlog

Thursday, April 15, 2010

Drawing a 3D line

Now heres a interesting topic i found on the GMC 3D Techniques and i was baffled to find a answer till i actually put in some effort to thinking about it. It was how to draw a 3D line. Now we all know that you use a primitive (and for those who didn't this is for you, don't worry no need to put up your hand(s)).

A extermely simple way and the way most people would know is

[CODE]

d3d_primitive_begin(pr_linelist);


d3d_vertex(x1,y1,z1);

d3d_vertex(x2,y2,z2);

d3d_primitive_end();
 
[/CODE]

simple huh? But Slayer 64 (whom i may not consider myself to be on very good terms but that is between me and a certain incident), he is a genius at 3D aspects of GM and bought up a very good point of making the line look much nicer. And i wanted to distrubute it with his name branded on it.

[CODE]

d3d_transform_set_identity()


d3d_transform_add_rotation_y(point_direction(0,z1-z2,point_distance(x2,y2,x1,y1),0)

d3d_transform_add_rotation_z(point_direction(x1,y1,x2,y2))

d3d_transform_add_translation(x1,y1,z1)

d3d_draw_floor(0,-.5,0,point_distance(x1,y1,x2,y2),.5,0,background_get_texture(background0))
[/CODE]

But millzy, what is the point of all this? Well Slayer explained it better than anyone ever could by using a example

" it's highly neceessary if you want lines to look good. like the rails in quake 3. pr_linewhatever doesn't look good in 3d because it's width doesn't change "

And included this image to show you exactly the evidence of how we would wnat it to look rather than a simple pr_linestrip which frankly would be something you'd only poke your eye out with.


Anyway i hope this has has lined some people up with some good ideas for their games (see what i did there :P )

Labels:

The GM3D Snail

Take a ride on the Snail my friends. When it comes to 3D, sooner or later your gonna hit this one trust me. I was looking last night at my experimental project of creating a 3D world and just trying out different things. I had some nice cartoony trees with reeeaaallllyyy nice shading on it. I was so happy with my efforts i actually smiled (gosh i made sound like i never smile, no i just rarely take pride in my work before the end). But on a second look i found that uh-oh snail trail, my game had dropped to 19 FPS. Now my computer is by no means old. Infact it is brand new just less than a week old with a lovely 9800GT 1GB in it. So i was a bit stumped to find this happening. Of course the trees, being about 40 of them drawing 2 shapes and with lighting was causing the lag.

But what to do.... I don't want to less the amount of trees and deactivation is definately out of the question. Of course if you haven't got the answer yet, stay on the snail it is currently travelling faster than your brains thinking (just a bit of wit in there please don't be put down by it).

So if you thought of the following:

- Don't draw outside of the sight of the camera (eg. fog)
- Don't draw them behind objects
- Don't use lighting for objects furthur away
- Turn culling on
- Billboarding.

Now that i have search the gmc you can find ALL these techniques but the third one here:
Speeding up 3D

The third one is simple:

[CODE]

if (distance_to_point(Camera.x,Camera.y)
{
 //Draw normally
}
else
{
d3d_set_lighting(false)
//Draw object
d3d_set_lighting(true)
}

[/CODE]

Simple but it may save you 1 or 2 FPS but hey, 1 or 2 can be the difference between a good review and bad. For the rest, that topic shows it FAR better than i ever would.

Have fun peeps :P

Labels:

3D Lighting tips

With my return to using the new Game maker 8 (very good if you ask me) i have being experimenting with the 3D aspect of Game Maker 8. One thing i noticed which could be called intolerable was (and probably included with all Game Makers which have 3D) that some of my shapes and such were kept black (example: floors, cylinders). This is because they have no normals to put light onto (or something similar to this). The solutions are found to be the following:

(REMEMBER: [CODE] tags aren't included ;) )
[CODE]

d3d_set_lighting(false)
//shape
d3d_set_lighting(true)

[/CODE]

Basically this disables lights while drawing this object causing no light to affect the object itself.
The simple way of avoiding this problem

2.

Get a modelling program (for something as simple as shapes i would suggest anim8or as it requires the simplest amount of knowledge, however for more harder models go for blender, sketchup or milkshape). Draw your shape and load it into the game, these models will have the ability for light to be shown but is the harder way.

3.

Fake lighting. The hardest to pull off. Pulled it off once on my old computer before it got formatted ; The idea and limitation of Fake lighting is that the light source can't change position. Better for lighting in rooms rather than a day/night system. It requires a texture of gradient type (which has a dark and light source. Light being on one side and dark of the other. HOWEVER, there must be normal (or unaffected by lighting colour) on the background seperating it. It is a matter of trail and error really.


I preferbly go for number one. If your good go for number two. Number three is for more of the smart graphic artists which could have a chance of pulling it off :P

Catch ya later.

Labels:

Long time no see

I abandoned this blog a while ago to finish my website. Unfortunately now the fact that my website has blown up (or being taken off the net due to my provider going off the net), i am tempoarily coming back to this blog until i have another means of communication.

Labels: