Skip to content

Commit 00e1ce9

Browse files
committed
Implemented MOSprite:GetPixelIndex(), implemented first take on MOSprite:GetAllPixelPositions()
1 parent cd6b982 commit 00e1ce9

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Source/Entities/MOSprite.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,23 @@ Vector MOSprite::UnRotateOffset(const Vector& offset) const {
351351
return rotOff;
352352
}
353353

354+
std::vector<Vector>* MOSprite::GetAllPixelPositions(const Vector& origin, float angle, bool hflipped, bool includeTransparency, unsigned int whichFrame) {
355+
std::vector<Vector>* posList = new std::vector<Vector>();
356+
CLAMP(m_FrameCount - 1, 0, whichFrame);
357+
BITMAP* sprite = m_aSprite[whichFrame];
358+
for (int y = 0; y < GetSpriteHeight(); y++) {
359+
for (int x = 0; x < GetSpriteWidth(); x++) {
360+
int pixelIndex = GetPixelIndex(x, y, whichFrame);
361+
if (includeTransparency || pixelIndex > 0) {
362+
Vector pixelPos = (Vector(x, y) + m_SpriteOffset).FlipX(hflipped).RadRotate(angle) + origin;
363+
posList->push_back(pixelPos.GetRounded());
364+
}
365+
}
366+
}
367+
368+
return posList;
369+
}
370+
354371
void MOSprite::Update() {
355372
MovableObject::Update();
356373

Source/Entities/MOSprite.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ namespace RTE {
9090
/// Ownership is NOT transferred!
9191
BITMAP* GetSpriteFrame(unsigned int whichFrame = 0) const { return (whichFrame < m_FrameCount) ? m_aSprite[whichFrame] : 0; }
9292

93+
int GetPixelIndex(int x, int y, unsigned int whichFrame = 0) const { return getpixel(m_aSprite[CLAMP(m_FrameCount - 1, 0, whichFrame)], x, y); }
94+
95+
std::vector<Vector>* GetAllPixelPositions(const Vector& origin, float angle, bool hflipped, bool includeTransparency, unsigned int whichFrame);
96+
9397
/// Gets the width of the bitmap of this MOSprite
9498
/// @return Sprite width if loaded.
9599
int GetSpriteWidth() const { return m_aSprite[0] ? m_aSprite[0]->w : 0; }

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,8 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, MOSprite) {
836836
.def("SetExitWound", &MOSprite::SetExitWound)
837837
.def("GetEntryWoundPresetName", &MOSprite::GetEntryWoundPresetName)
838838
.def("GetExitWoundPresetName", &MOSprite::GetExitWoundPresetName)
839+
.def("GetPixelIndex", &MOSprite::GetPixelIndex)
840+
.def("GetAllPixelPositions", &MOSprite::GetAllPixelPositions, luabind::return_stl_iterator)
839841

840842
.enum_("SpriteAnimMode")[luabind::value("NOANIM", SpriteAnimMode::NOANIM),
841843
luabind::value("ALWAYSLOOP", SpriteAnimMode::ALWAYSLOOP),

0 commit comments

Comments
 (0)