[Add] Body: GetRadius method.

[Add] Calculate bounding sphere radius from AABB's of geoms.
[Add] Make use of the existing GetRadius methods.
[Change] Moved object viewer key to f10.
[Add] A couple new image icons.
This commit is contained in:
Rtch90 2017-11-25 15:54:23 +00:00
parent 0aee9d7036
commit fe8fedd5b7
18 changed files with 38 additions and 3 deletions

BIN
icons/object_planet_co2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 275 B

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 323 B

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -15,6 +15,7 @@ public:
virtual Object::Type GetType(void) { return Object::BODY; }
virtual void SetPosition(vector3d p) = 0;
virtual vector3d GetPosition(void) = 0; /* Within frame. */
virtual double GetRadius(void) const = 0 ;
virtual void Render(const Frame* camFrame) = 0;
virtual void SetFrame(Frame* f) { m_frame = f; }
/* return true if to we do collision response and apply damage. */

View File

@ -7,6 +7,7 @@
#include <SDL_image.h>
#include <ode/ode.h>
#include <float.h>
#include <limits>
#ifdef _WIN32
#include <windows.h>

View File

@ -154,7 +154,7 @@ void L3D::HandleEvents(void) {
case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_q) L3D::Quit();
if(event.key.keysym.sym == SDLK_F11) SDL_WM_ToggleFullScreen(L3D::scrSurface);
if(event.key.keysym.sym == SDLK_F12) L3D::SetView(L3D::objectViewerView);
if(event.key.keysym.sym == SDLK_F10) L3D::SetView(L3D::objectViewerView);
L3D::keyState[event.key.keysym.sym] = 1;
L3D::onKeyPress.emit(&event.key.keysym);
break;

View File

@ -62,6 +62,32 @@ vector3d ModelBody::GetPosition(void) {
return vector3d(pos[0], pos[1], pos[2]);
}
double ModelBody::GetRadius(void) const {
/* Calculate single AABB containing all geoms. */
dReal aabbAll[6] = {
std::numeric_limits<double>::max(),
std::numeric_limits<double>::min(),
std::numeric_limits<double>::max(),
std::numeric_limits<double>::min(),
std::numeric_limits<double>::max(),
std::numeric_limits<double>::min()
};
for(size_t i = 0; i < geoms.size(); ++i) {
dReal aabbGeom[6];
dGeomGetAABB(geoms[i], aabbGeom);
aabbAll[0] = std::min(aabbAll[0], aabbGeom[0]);
aabbAll[1] = std::max(aabbAll[1], aabbGeom[1]);
aabbAll[2] = std::min(aabbAll[2], aabbGeom[2]);
aabbAll[3] = std::max(aabbAll[3], aabbGeom[3]);
aabbAll[4] = std::min(aabbAll[4], aabbGeom[4]);
aabbAll[5] = std::max(aabbAll[5], aabbGeom[5]);
}
/* Return size of largest dimension. */
return std::max(aabbAll[1] - aabbAll[0], std::max(aabbAll[3] - aabbAll[2], aabbAll[5] - aabbAll[4]));
}
void ModelBody::SetRotation(const matrix4x4d& r) {
dMatrix3 _m;
r.SaveToOdeMatrix(_m);

View File

@ -15,6 +15,7 @@ public:
virtual void SetRotation(const matrix4x4d& r);
/* Not valid to SetVelocity on these. If you want them to move, use a DynamicBody. */
vector3d GetPosition(void);
virtual double GetRadius(void) const;
void TransformToModelCoords(const Frame* camFrame);
void ViewingRotation(void);
void GetRotMatrix(matrix4x4d& m);

View File

@ -60,6 +60,11 @@ void ObjectViewerView::Update(void) {
char buf[128];
Body* body = L3D::player->GetNavTarget();
if(body && body != lastTarget) {
/* Reset view distance for new target. */
viewingDist = body->GetRadius() * 2.0f;
lastTarget = body;
}
snprintf(buf, sizeof(buf), "View dist: %.2f Object: %s", viewingDist, (body ? body->GetLabel().c_str() : "<none>"));
m_infoLabel->SetText(buf);
}

View File

@ -15,5 +15,6 @@ private:
matrix4x4d viewingRotation;
float viewingDist;
Gui::Label* m_infoLabel;
const Body* lastTarget;
};

View File

@ -10,7 +10,7 @@ public:
virtual void SetPosition(vector3d p);
virtual vector3d GetPosition(void);
void SetRadius(double radius);
double GetRadius(void) { return sbody.radius; }
virtual double GetRadius(void) const { return sbody.radius; }
virtual void Render(const Frame* camFrame);
virtual void SetFrame(Frame* f);
virtual bool OnCollision(Body* b, Uint32 flags) { return true; }

View File

@ -11,7 +11,7 @@ public:
virtual void SetPosition(vector3d p);
virtual vector3d GetPosition(void);
void SetRadius(double radius) { this->radius = radius; }
double GetRadius(void) { return radius; }
virtual double GetRadius(void) const { return radius; }
virtual void Render(const Frame* camFrame);
private: