Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Admiral Pimms

Member Since 29 Apr 2011
Offline Last Active Dec 11 2012 03:44 PM

Topics I've Started

Individual vertex coloring is somehow disabled.

09 September 2012 - 09:15 AM

Edit:

The fix is in:

I had called glShadeModel(GL_FLAT) at some point in my code, because I was trying to derp while herping whilst writing it.

The fix was to change GL_FLAT with GL_SMOOTH. Thanks to Sponji for pointing that out.

---

Good day!

I've been struggling to draw primitives correctly in my engine for quite a few hours, and I've managed to narrow it down to the fact that each vertex I'm passing along isn't colored individually.

The following snippet and screenshot demonstrates my issue.

	glDisable(GL_TEXTURE_2D);
	glBegin(GL_QUADS);
		 glColor3f(0.f,1.f,0.f);				// Green
		 glVertex2f(-50.f, -50.f);
		 glVertex2f(50.f, -50.f);
		 glVertex2f(50.f, 50.f);


		 glColor3f(1.f, 0.f, 0.f);			  // Red
		 glVertex2f(-50.f, 50.f);
	glEnd();
	glEnable(GL_TEXTURE_2D);

This snippet should render a square where the top left vertex is red and the other three are green. However, as can be seen in this screenshot, this is not the case.

Posted Image

Disregard the purple sprites. Whenever I try to draw a primitive of any kind, all vertices get the last color called.

Apart from disabling/enabling GL_TEXTURE_2D, I'm not doing anything unusual.

This issue occurs both when rendering to a texture, and when I'm not.

Hope someone has experienced this issue before and can give me an aiding hand.

Best regards, Pimms.

Vector transformation

08 August 2011 - 05:37 PM

Greetings, GameDev community!

I'm currently working with Box2D, and I'm implementing an explosion-effect.

Therefore, I'm in need of a direction vector to be multiplied by the force (which is based on distance).

In order to make it appear as seamless as possile, I need to first transform the vector so that the highest value of the vector is 1. Let me show you;

A vector of (15, 10) would be (1, 6.67). As would a vector (30,15) be (1, 0.5).

Has anyone done this before and have a code snippet to share? The general theory / principle behind it would be sufficient as well.

Thanks in advance :)

//pimms

Collision Detection behaving strange (jnrdev#1)

29 April 2011 - 08:33 AM

Salutations!

After browsing these forums for about a month, I decided to create an account, because I'm hopelessly stuck, and you guys know your stuff.

I found a link a week ago (or so) to a web archive containing a "Jump n Shoot" tutorial written by jnrdev. I've been trying to build my own library based on his design on class interaction... Some parts are directly stolen, primarily because they work good, and I don't hold the skills to improve it much.

The main problems I am experiencing is that it detecs a collision when starting in the middle of the screen. Only the outer edges are covered in solid tiles. If I start to move using the arrow keys, the player suddenly drops through the map, until the y value exceeds what an int can hold. I've attached a screenshot showing the console and the main game window.

The Pmap class:
Contains an array of type TILE which contains a pointer to an SDL_Surface, and a boolean containing whether it's solid or not.
class Pmap{

public:

    //The only one worth noticing in Pmap
    bool colmapxy( int x, int y )
	{
        return Mtile[x][y].solid;
        }

private:

};

Player class, main function:
Interacts with the Pmap class using the "collision_ver" and "collision_hor" functions, which can be seen below.

void Player::think(SDL_Event &event, Pmap& map, SDL_Surface &screen)
{
    cout<<"\n\nThinking..\n";
    handleInput(event);

    int tilecoord;

    //X-axis first

    //Moving right
    if( xVel > 0)
    {
        printf("Moving right...xVel:%d, yVel:%d, x:%d, y:%d\n", xVel, yVel, x, y);
        if(collision_ver( x+xVel+w, y, tilecoord, map) )
                x = tilecoord*40 -w-1;
        //    else x += xVel;
    }

    //Moving left
    if( xVel < 0)
    {
        printf("Moving left...xVel:%d, yVel:%d, x:%d, y:%d\n", xVel, yVel, x, y);
        if( collision_ver( x+xVel, y, tilecoord, map))
                x = (tilecoord+1) *40+1;
        //    else x += xVel;
    }

    //Caps the xVel at SPEED
    if( xVel > SPEED ) xVel = SPEED;


    //Then Y-axis
    //Moving up
    if( yVel < 0 )
    {
        printf("Moving up...xVel:%d, yVel:%d, x:%d, y:%d\n", xVel, yVel, x, y);

        //Moving up & block in the way
        if( collision_hor( x, y+yVel, tilecoord, map))
        {
                y = (tilecoord+1) *40+1;
                yVel = 0;
        }

        //Moving up through blank spots
        else
        {
            y += yVel;
            yVel += GRAVITATION;
        }

    }

    //yVel > 0, hence falling or on the ground
    else
    {
        printf("Moving down / on ground...xVel:%d, yVel:%d, x:%d, y:%d\n", xVel, yVel, x, y);

        //Moving down, block in the way
        if( collision_hor( x, y+yVel+h, tilecoord, map))
        {
                y = tilecoord*40-h -1;      //On ground
                yVel = 1;
        }
        //Falling / in air
        else
        {
            printf("Falling...xVel:%d, yVel:%d, x:%d, y:%d\n", xVel, yVel, x, y);
            y += yVel;
            yVel += GRAVITATION;

            if( yVel >= TILESIZE )
                    yVel = TILESIZE;

            jumpLock = true;
        }
    }
}


Collision checker function:
Note: there are two of these (_hor and _ver), but they are so similar I choose to only copy in one of them.
Also, this one is identical to jnrdev's function, except for variable names.

bool Player::collision_hor(int x, int y, int &tilecoordy,  Pmap& map){
	int tilexpixels = x-(x%40);	//calculate the x position (pixels!) of the tiles we check against
	int testend = x + w;		//calculate the end of testing (just to save the x+w calculation each for loop)

	tilecoordy = y/40;			//calculate the y position (map coordinates!) of the tiles we want to test

	int tilecoordx = tilexpixels/40;	//calculate map x coordinate for first tile


	//loop while the start point (pixels!) of the test tile is inside the players bounding box
	while(tilexpixels <= testend){
		if(map.colmapxy(tilecoordx, tilecoordy))	//is a solid tile is found at tilecoordx, tilecoordy?
		{
    		printf("Collision(hor) at: X:%d, Y:%d\n", x, y);
			return true;
		}

		tilecoordx++;		//increase tile x map coordinate
		tilexpixels+=40;	//increase tile x pixel coordinate
	}

    cout<<"No hor coll\n";
	return false;
}

Edit:
For some reason, collision_ver() kept returning a wrong value, which I've corrected now, and it appears to be working. If possible, please delete this thread.
The lesson I've learned is that printf / cout will save you tons of time when debugging.


PARTNERS