Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » 3D problem, drawing a plane, sprites, camera

This thread is locked; no one can reply to it. rss feed Print
3D problem, drawing a plane, sprites, camera
giewueron
Member #7,433
July 2006

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 ;D). 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 :D. 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.

Archon
Member #4,195
January 2004
avatar

Quote:

I'm trying to make a 3d
.....
The graphics will be very simple so I don't need to use OpenGL

Wah! Contradiction!

Quote:

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).

giewueron
Member #7,433
July 2006

I actually did something but doesn't work. What's wrong? ;<

1#include <allegro.h>
2 
3typedef struct
4{
5 fixed x, y, z;
6} VTX;
7 
8typedef struct
9{
10 VTX vertices[4];
11 BITMAP *texture;
12} PLANE;
13 
14void init();
15void deinit();
16 
17volatile int timer = 0;
18 
19void increment_timer()
20{
21 timer++;
22}
23 
24int 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}
80END_OF_MAIN();
81 
82void 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 
109void deinit() {
110 clear_keybuf();
111}

Zaphos
Member #1,468
August 2001

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--;
        }

Niunio
Member #1,975
March 2002
avatar

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.

-----------------
Current projects: Allegro.pas | MinGRo

giewueron
Member #7,433
July 2006

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.

BAF
Member #2,981
December 2002
avatar

Quote:

Pixwiki [pixwiki.bafsoft.com] still broken so...

Fixed.

giewueron
Member #7,433
July 2006

Thanks for the mode 7 suggestion. All works like it should.

Go to: