Hi
So, I'm trying to make a 3d multiplayer soccer game. It would be like each player sees from the POV of his own football guy. The graphics will be very simple so I don't need to use OpenGL (although maybe it would be more simple, I don't know ). The problem is I don't get all that Allegro 3D stuff. What I need is a very basic textured plane drawing function (for the 3D rectangular football pitch floating in space :], it will be only visible from the top) and a 3D sprite drawing function for the ball and the players -- I don't need models. Just that kind of sprites like you see in the old Doom game, guys predrawn from 8 sides (Problems: How to check which side relatively to the camera should be drawn? How to scale the sprites relatively to the camera position and like put them in the right places?). Also camera stuff etc. I think I don't need also depth-cueing, because it might look okay -- all in all everything in a football match is fully lit . Maybe there's someone here who could help me with this dirty work. If someone comes up with some actual source code he will be very nicely credited in the game . I know I'm freaking lazy. Doh ;]
Greets.
I'm trying to make a 3d
.....
The graphics will be very simple so I don't need to use OpenGL
Wah! Contradiction!
The problem is I don't get all that Allegro 3D stuff.
Me neither.
What I mean is, you should use OpenGL because it's faster and the calculations would be done for you and all. The camera solution is there for you in related tutorials plus there is lots of help. I'm not sure if Allegro's 3D functions will be around in the future.
Look up 'billboarding' if you are still doing Doom-style character drawings.
Moving the camera around is a breeze. You just need to move everything else the opposite of where you want to go (because they appear to move like that).
I actually did something but doesn't work. What's wrong? ;<
1 | #include <allegro.h> |
2 | |
3 | typedef struct |
4 | { |
5 | fixed x, y, z; |
6 | } VTX; |
7 | |
8 | typedef struct |
9 | { |
10 | VTX vertices[4]; |
11 | BITMAP *texture; |
12 | } PLANE; |
13 | |
14 | void init(); |
15 | void deinit(); |
16 | |
17 | volatile int timer = 0; |
18 | |
19 | void increment_timer() |
20 | { |
21 | timer++; |
22 | } |
23 | |
24 | int main() |
25 | { |
26 | |
27 | |
28 | BITMAP *double_buffer; |
29 | |
30 | PLANE pitch; |
31 | |
32 | init(); |
33 | |
34 | double_buffer = create_bitmap( SCREEN_W, SCREEN_H ); |
35 | |
36 | pitch.vertices[0].x = -60 << 16; |
37 | pitch.vertices[0].y = -45 << 16; |
38 | pitch.vertices[0].z = 0 << 16; |
39 | pitch.vertices[1].x = 60 << 16; |
40 | pitch.vertices[1].y = -45 << 16; |
41 | pitch.vertices[1].z = 0 << 16; |
42 | pitch.vertices[2].x = 60 << 16; |
43 | pitch.vertices[2].y = 45 << 16; |
44 | pitch.vertices[2].z = 0 << 16; |
45 | pitch.vertices[3].x = 60 << 16; |
46 | pitch.vertices[3].y = -45 << 16; |
47 | pitch.vertices[3].z = 0 << 16; |
48 | pitch.texture = load_bitmap( "murawa.bmp", NULL ); |
49 | |
50 | while (!key[KEY_ESC]) |
51 | { |
52 | MATRIX camera_matrix; |
53 | int i; |
54 | V3D pitch_v3d[4]; |
55 | |
56 | while (timer) |
57 | { |
58 | } |
59 | |
60 | get_camera_matrix( &camera_matrix, 0, 0, 0, 1 << 16, 0, 0, 0, 0, 1 << 16, 32 << 16, 1 << 16); |
61 | |
62 | for ( i = 0; i < 4; i++ ) |
63 | { |
64 | apply_matrix( &camera_matrix, pitch.vertices<i>.x, pitch.vertices<i>.y, pitch.vertices<i>.z, |
65 | &pitch_v3d<i>.x, &pitch_v3d<i>.y, &pitch_v3d<i>.z); |
66 | pitch_v3d<i>.u = pitch_v3d<i>.v = 0; |
67 | } |
68 | |
69 | |
70 | |
71 | clear_to_color(double_buffer, makecol(0,0,0)); |
72 | |
73 | polygon3d(screen, POLYTYPE_PTEX, pitch.texture, 4, pitch_v3d); |
74 | blit(double_buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); |
75 | } |
76 | |
77 | deinit(); |
78 | return 0; |
79 | } |
80 | END_OF_MAIN(); |
81 | |
82 | void init() |
83 | { |
84 | int depth, res; |
85 | allegro_init(); |
86 | depth = desktop_color_depth(); |
87 | if (depth == 0) depth = 32; |
88 | set_color_depth(depth); |
89 | res = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0); |
90 | if (res != 0) |
91 | { |
92 | allegro_message(allegro_error); |
93 | exit(-1); |
94 | } |
95 | |
96 | install_timer(); |
97 | install_keyboard(); |
98 | install_mouse(); |
99 | |
100 | srand( time(NULL) ); |
101 | |
102 | LOCK_VARIABLE( timer ); |
103 | LOCK_FUNCTION( increment_timer ); |
104 | install_int_ex( increment_timer, BPS_TO_TIMER(200) ); |
105 | |
106 | set_projection_viewport (0, 0, SCREEN_W, SCREEN_H); |
107 | } |
108 | |
109 | void deinit() { |
110 | clear_keybuf(); |
111 | } |
Matt Smith posted starter code which could give you a boost in the right direction -- it sets up the ball and the pitch for you. He posted it over in this thread ...
edits:
Oh, and for your code, I didn't read over it closely but in the main loop you have:
while (timer) { }
and it doesn't look like you ever decrement timer, only increment. You probably meant
while (timer) { // logic to go here later timer--; }
Maybe you can use "mode7" trick to render the grass and render sprites using pivot_scaled_sprite.
Pixwiki still broken so I've attached (again) the tutorial that explains "mode7" using Allegro.
I looked at that mode 7 stuff and seems it would fit here. Maybe instead of that textured plane or stretch sprite I could just line by line draw it, using that divide by z, so it would be like a little perspective correct.
Pixwiki [pixwiki.bafsoft.com] still broken so...
Fixed.
Thanks for the mode 7 suggestion. All works like it should.