mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-04 05:13:19 +00:00
Improve camera zooming behavior + camera related cleanups
- Now, the camera will now no longer be pulled towards the upper left or lower rigtht corner. - cameraPos was never used as an interpolating vector, cleaned up related code. - Core::invGlobalScale is now updated whenever Core::globalScale is changed (Not a nice solution but it does work) - Increase cull radius by 10%, should prevent tiles from disappearing when zoomed in a lot.
This commit is contained in:
parent
b501ba67e3
commit
2cec85fd05
11 changed files with 50 additions and 119 deletions
|
@ -1319,12 +1319,12 @@ bool Core::initSoundLibrary(const std::string &defaultDevice)
|
|||
|
||||
Vector Core::getGameCursorPosition()
|
||||
{
|
||||
return core->cameraPos + mouse.position * Vector(1/core->globalScale.x, 1/core->globalScale.y, 1);
|
||||
return getGamePosition(mouse.position);
|
||||
}
|
||||
|
||||
Vector Core::getGamePosition(const Vector &v)
|
||||
{
|
||||
return core->cameraPos + (v * Vector(1/core->globalScale.x, 1/core->globalScale.y, 1));
|
||||
return cameraPos + (v * invGlobalScale);
|
||||
}
|
||||
|
||||
bool Core::getMouseButtonState(int m)
|
||||
|
@ -1795,8 +1795,8 @@ void Core::onUpdate(float dt)
|
|||
|
||||
//script.update(dt);
|
||||
|
||||
cameraPos.update(dt);
|
||||
globalScale.update(dt);
|
||||
core->globalScaleChanged();
|
||||
|
||||
if (afterEffectManager)
|
||||
{
|
||||
|
@ -1817,6 +1817,12 @@ void Core::onUpdate(float dt)
|
|||
}
|
||||
}
|
||||
|
||||
void Core::globalScaleChanged()
|
||||
{
|
||||
invGlobalScale = 1.0f/globalScale.x;
|
||||
invGlobalScaleSqr = invGlobalScale * invGlobalScale;
|
||||
}
|
||||
|
||||
Vector Core::getClearColor()
|
||||
{
|
||||
return clearColor;
|
||||
|
@ -2412,7 +2418,7 @@ void Core::setPixelScale(int pixelScaleX, int pixelScaleY)
|
|||
virtualWidth = pixelScaleX;
|
||||
//MAX(virtualWidth, 800);
|
||||
virtualHeight = pixelScaleY;//int((pixelScale*aspectY)/aspectX); //assumes 4:3 aspect ratio
|
||||
this->baseCullRadius = sqrtf(sqr(getVirtualWidth()/2) + sqr(getVirtualHeight()/2));
|
||||
this->baseCullRadius = 1.1f * sqrtf(sqr(getVirtualWidth()/2) + sqr(getVirtualHeight()/2));
|
||||
|
||||
std::ostringstream os;
|
||||
os << "virtual(" << virtualWidth << ", " << virtualHeight << ")";
|
||||
|
@ -3290,7 +3296,7 @@ void Core::setMouseConstraint(bool on)
|
|||
mouseConstraint = on;
|
||||
}
|
||||
|
||||
void Core::setMouseConstraintCircle(int circle)
|
||||
void Core::setMouseConstraintCircle(float circle)
|
||||
{
|
||||
mouseConstraint = true;
|
||||
mouseCircle = circle;
|
||||
|
@ -4051,20 +4057,9 @@ void Core::cacheRender()
|
|||
|
||||
void Core::updateCullData()
|
||||
{
|
||||
// update cull data
|
||||
//this->cullRadius = int((getVirtualWidth())*invGlobalScale);
|
||||
this->cullRadius = baseCullRadius * invGlobalScale;
|
||||
this->cullRadiusSqr = (float)this->cullRadius * (float)this->cullRadius;
|
||||
this->cullCenter = cameraPos + Vector(400.0f*invGlobalScale,300.0f*invGlobalScale);
|
||||
screenCullX1 = cameraPos.x;
|
||||
screenCullX2 = cameraPos.x + 800*invGlobalScale;
|
||||
screenCullY1 = cameraPos.y;
|
||||
screenCullY2 = cameraPos.y + 600*invGlobalScale;
|
||||
|
||||
|
||||
int cx = core->cameraPos.x + 400*invGlobalScale;
|
||||
int cy = core->cameraPos.y + 300*invGlobalScale;
|
||||
screenCenter = Vector(cx, cy);
|
||||
cullRadius = baseCullRadius * invGlobalScale;
|
||||
cullRadiusSqr = cullRadius * cullRadius;
|
||||
screenCenter = cullCenter = cameraPos + Vector(400.0f*invGlobalScale,300.0f*invGlobalScale);
|
||||
}
|
||||
|
||||
void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail)
|
||||
|
@ -4079,12 +4074,11 @@ void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail)
|
|||
endLayer = overrideEndLayer;
|
||||
}
|
||||
|
||||
globalScaleChanged();
|
||||
|
||||
if (core->minimized) return;
|
||||
onRender();
|
||||
|
||||
invGlobalScale = 1.0f/globalScale.x;
|
||||
invGlobalScaleSqr = invGlobalScale * invGlobalScale;
|
||||
|
||||
RenderObject::lastTextureApplied = 0;
|
||||
|
||||
updateCullData();
|
||||
|
|
13
BBGE/Core.h
13
BBGE/Core.h
|
@ -1037,7 +1037,7 @@ public:
|
|||
void removeRenderObject(RenderObject *r, RemoveRenderObjectFlag flag = DESTROY_RENDER_OBJECT);
|
||||
|
||||
void setMouseConstraint(bool on);
|
||||
void setMouseConstraintCircle(int mouseCircle);
|
||||
void setMouseConstraintCircle(float mouseCircle);
|
||||
|
||||
void setReentryInputGrab(int on);
|
||||
|
||||
|
@ -1130,7 +1130,7 @@ public:
|
|||
|
||||
virtual void onPlayedVoice(const std::string &name){}
|
||||
|
||||
InterpolatedVector cameraPos;
|
||||
Vector cameraPos;
|
||||
|
||||
int fps;
|
||||
bool loopDone;
|
||||
|
@ -1174,13 +1174,14 @@ public:
|
|||
|
||||
bool minimized;
|
||||
std::string getEnqueuedJumpState();
|
||||
int cullRadius;
|
||||
float cullRadius;
|
||||
float cullRadiusSqr;
|
||||
Vector cullCenter;
|
||||
int screenCullX1, screenCullY1, screenCullX2, screenCullY2;
|
||||
unsigned int renderObjectCount, processedRenderObjectCount, totalRenderObjectCount;
|
||||
float invGlobalScale, invGlobalScaleSqr;
|
||||
|
||||
void globalScaleChanged();
|
||||
|
||||
void screenshot();
|
||||
|
||||
void clearRenderObjects();
|
||||
|
@ -1348,13 +1349,13 @@ protected:
|
|||
|
||||
std::string appName;
|
||||
bool mouseConstraint;
|
||||
int mouseCircle;
|
||||
float mouseCircle;
|
||||
|
||||
bool doMouseConstraint();
|
||||
|
||||
virtual void onMouseInput(){}
|
||||
bool doScreenshot;
|
||||
int baseCullRadius;
|
||||
float baseCullRadius;
|
||||
bool initSoundLibrary(const std::string &defaultDevice);
|
||||
bool initInputLibrary();
|
||||
bool initJoystickLibrary(int numSticks=1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue