mirror of
https://github.com/edubart/otclient.git
synced 2025-12-02 16:06:51 +01:00
Rotate, translate and scale added to ogl2
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "game.h"
|
||||
#include "tile.h"
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
|
||||
LocalPlayer::LocalPlayer()
|
||||
{
|
||||
@@ -56,6 +57,41 @@ LocalPlayer::LocalPlayer()
|
||||
m_totalCapacity = -1;
|
||||
}
|
||||
|
||||
void LocalPlayer::draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView)
|
||||
{
|
||||
Creature::draw(dest, scaleFactor, animate, lightView);
|
||||
|
||||
// This is a test to rotation, translate and scale transformations.
|
||||
/*
|
||||
g_painter->saveAndResetState();
|
||||
g_painter->rotate(dest.x, dest.y, Fw::pi / 4.);
|
||||
Creature::draw(dest, scaleFactor, animate, lightView);
|
||||
g_painter->restoreSavedState();
|
||||
*/
|
||||
|
||||
// This depends on rotation to get done.
|
||||
// Textured arrow pointing to desired position.
|
||||
/*
|
||||
Position pos = Position(1029, 997, 7);
|
||||
|
||||
int radius = 8;
|
||||
double angle = m_position.getAngleFromPosition(pos);
|
||||
if(angle < 0) {
|
||||
radius = 0;
|
||||
angle = 0;
|
||||
}
|
||||
|
||||
Point animationOffset = animate ? m_walkOffset : Point(0,0);
|
||||
Point center = Point(dest + (animationOffset - getDisplacement() -8 + Otc::TILE_PIXELS)*scaleFactor);
|
||||
g_painter->setColor(Color::red);
|
||||
g_painter->drawFilledRect(Rect(center, Size(3, 3)*scaleFactor));
|
||||
center.x += radius * cos(angle);
|
||||
center.y -= radius * sin(angle);
|
||||
g_painter->setColor(Color::white);
|
||||
g_painter->drawFilledRect(Rect(center, Size(3, 3)*scaleFactor));
|
||||
*/
|
||||
}
|
||||
|
||||
void LocalPlayer::lockWalk(int millis)
|
||||
{
|
||||
m_walkLockExpiration = std::max(m_walkLockExpiration, (ticks_t) g_clock.millis() + millis);
|
||||
|
||||
@@ -35,6 +35,8 @@ class LocalPlayer : public Player
|
||||
public:
|
||||
LocalPlayer();
|
||||
|
||||
virtual void draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView = nullptr);
|
||||
|
||||
void unlockWalk() { m_walkLockExpiration = 0; }
|
||||
void lockWalk(int millis = 250);
|
||||
void stopAutoWalkUpdate();
|
||||
|
||||
@@ -108,6 +108,20 @@ public:
|
||||
return pos;
|
||||
}
|
||||
|
||||
double getAngleFromPosition(const Position& position) const {
|
||||
// Returns angle in radians from 0 to 2Pi. -1 means positions are equal.
|
||||
int dx = position.x - x;
|
||||
int dy = position.y - y;
|
||||
if(dx == 0 && dy == 0)
|
||||
return -1;
|
||||
|
||||
float angle = std::atan2(dy * -1, dx);
|
||||
if(angle < 0)
|
||||
angle += 2 * Fw::pi;
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
Otc::Direction getDirectionFromPosition(const Position& position) const {
|
||||
int dx = position.x - x;
|
||||
int dy = position.y - y;
|
||||
|
||||
Reference in New Issue
Block a user