Drawing a Skybox that rotates and loops correctly.

Started by Scavenger, Sun 31/01/2016 22:23:22

Previous topic - Next topic

Scavenger

I'm trying to draw a skybox correctly based off of the player's angle, but I don't think I'm doing it right, and I couldn't find anything on google to show me how to draw it properly. I have to start with a direction vector, and I think you're supposed to use atan2 on that to get the radians, but...

Currently I have:

Code: C++

        double playerrad = atan2 (dirY,dirX);
	if (!sbBm) engine->AbortGame ("Raycast_Render: No valid skybox sprite.");
	if (skybox > 0)
	{
		int xoffset = (int)(playerrad*320.0);
		BITMAP *virtsc = engine->GetVirtualScreen ();
		engine->SetVirtualScreen (screen);
		xoffset = abs(xoffset % w);
		if (xoffset > 0)
		{
			engine->BlitBitmap (xoffset-320,1,sbBm,false);
		}
		engine->BlitBitmap (xoffset,1,sbBm,false);
		engine->SetVirtualScreen (virtsc);
	}


But it only works for half of the angles, the other half makes the skybox move in reverse, and it looks terrible. How are you supposed to do it correctly? Math with angles has always been my weakpoint.

Grok

I can't really follow what happens in your code and I'm not much of a programmer or mathematician (certainly not advanced), but I've done something that I believe is somewhat similar to what I believe your problem is about, determining at what angle from point A that point B is.

A is at the coordinates (iAX, iAY)  and point B at (iBX, iBY).

The distance between point A and B is fDistance (calculated using Pythagoras' theorem).


Using that I calculating the angle (fAngle) this way.


if(iAX>iBX)
  fAngle= 180.0 + Maths.RadiansToDegrees(Maths.ArcCos(IntToFloat(iAY-iBY)/fDistance));
else if(iAX<iBX)
  fAngle= 180.0 - Maths.RadiansToDegrees(Maths.ArcCos(IntToFloat(iAY-iBY)/fDistance));


The point being that to get the angle to go a full turn and not go backwards after a half turn I needed a different calculation if point A is to the left or the right of point B.

I don't know if this is in any way helpful to you.
If nothing else it might get someone else to come around and tell you how it really should be done.:)

Khris

I suspect the problem is that x % w for x < 0 is calculated as -(-x % w), as in, it doesn't wrap around like you expect it to.

Try
Code: c
    double playerrad = atan2(dirY, dirX) + M_PI;

Scavenger

Khris: This works perfectly! The skybox is scrolling just like it should. Thankyou!

SMF spam blocked by CleanTalk