Thread: 2D rotating map in 3D game C

  1. #1
    Registered User
    Join Date
    Mar 2018
    Posts
    7

    2D rotating map in 3D game C

    2D rotating map in 3D game C-map1-png
    2D rotating map in 3D game C-map2-png

    I have a 3D game with a simple opengl game engine. Each object in the game has an X,Y,Z position.

    I want to make a rotating map of an overview of the objects positions. I can make this work fine for a simple non rotating model.

    I would like to rotate the 2D overview map as the player rotates but I don't seem to be able to get it correct.

    Viewed from above the positions of the map points would be X and Z (Y is height in the game). The center point is 0 with negative values to the left.

    The angle is 0 to 359 inclusive.

    The 2D map (or angle=0) of the mapR() version give the fist "flat" image, but rotation gives the second image.

    Can anyone see what I am doing wrong ?
    Thanks,
    Jon

    C Source ...

    Code:
    void rotate2d(JSGEfloat angle, JSGEfloat* X, JSGEfloat* Y)
    {
            float   ra;
            ra = (angle/360) * (2*M_PI);
            *X = *X * cos(ra) - *Y * sin(ra);
            *Y = *Y * cos(ra) + *X * sin(ra);
    }

    Code:
    void instr_mapR(JSGEfloat angle, JSGEfloat ox, JSGEfloat oy, int w, int h, int clearbackground, JSGEfloat bRf, JSGEfloat bGf, JSGEfloat bBf,
                   JSGEfloat xmin, JSGEfloat ymin, JSGEfloat xmax, JSGEfloat ymax)
    {
            int oi=0;
            JSGEfloat X,Z;
    
            if (clearbackground==TRUE)
                    draw_2d_line_pretend_rectange(ox, oy, w, h, -xmin*6, -ymin*6, xmax*6, ymax*6, bRf, bGf, bBf);
    
            for (oi=0;oi<jsge_obj_top;oi++)                                                         // for all possible objects
            {                                                                                       // in use and not a star ?
                    if (sgeo[oi].inuse==TRUE && (sgeo[oi].visible==TRUE || sgeo[oi].tagnum==8000))  // Object active or the player itself
                    {
                            if (sgeo[oi].instr_map_show==TRUE)
                            {
                                    X=sgeo[oi].posrot.X;                                            // lr
                                    //Y=sgeo[oi].posrot.Y;                                          // ud
                                    Z=sgeo[oi].posrot.Z;                                            // fb
    
                                    //printf("X=%f\tZ=%f\n",X,Z); fflush(stdout);
                                    rotate2d(angle, &X, &Z);
                                    draw_2d_cross_pretend_pixels(ox, oy, w, h, X*6, -Z*6,
                                                                 sgeo[oi].instr_map_clr_Rf, sgeo[oi].instr_map_clr_Gf, sgeo[oi].instr_map_clr_Bf,
                                                                 xmin, ymin, xmax, ymax);
                            }
                    }
            }
    }
    Last edited by jonshouse; 01-12-2023 at 07:27 PM.

  2. #2
    Registered User
    Join Date
    Mar 2018
    Posts
    7

    Fixed

    Wrong type of rotation, this fixed it.

    Code:
    void rotatesp(JSGEfloat angle, JSGEfloat* X, JSGEfloat* Y)
    {
            float   ra;
            ra = (angle/360) * (2*M_PI);
    
            float normalx=*X;
            float normaly=*Y;
            *X = normalx * cos(ra) - normaly * sin(ra);
            *Y = normalx * sin(ra) + normaly * cos(ra);
    }
    This forum section seems empty, maybe I posted this in the wrong place?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rotating a Cube
    By spencerjack in forum C++ Programming
    Replies: 1
    Last Post: 06-30-2010, 11:17 PM
  2. Rotating Log
    By BobS0327 in forum C Programming
    Replies: 4
    Last Post: 09-08-2005, 05:08 AM
  3. Rotating Bitmaps with SDL
    By SmashBro in forum Game Programming
    Replies: 1
    Last Post: 03-23-2003, 02:37 PM
  4. Rotating a string?
    By Silverdream in forum C Programming
    Replies: 13
    Last Post: 02-14-2002, 10:20 PM

Tags for this Thread