Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some stuff to fix up the z-ordering issues using widgets, pending fix…

…es to the GUI system by robn
  • Loading branch information...
commit 33ee7eb0c503ce6c56ebd69b9081cec9d7de0528 1 parent 9b1e75e
@Dessimat0r authored
Showing with 142 additions and 115 deletions.
  1. +126 −111 src/WorldView.cpp
  2. +16 −4 src/WorldView.h
View
237 src/WorldView.cpp
@@ -55,6 +55,9 @@ void WorldView::InitObject()
m_labelsOn = true;
SetTransparency(true);
+ m_navTunnel = new NavTunnelWidget(this);
+ Add(m_navTunnel, 0, 0);
+
m_commsOptions = new Fixed(size[0], size[1]/2);
m_commsOptions->SetTransparency(true);
Add(m_commsOptions, 10, 200);
@@ -123,8 +126,6 @@ void WorldView::InitObject()
#endif
Gui::Screen::PushFont("ConsoleFont");
- m_altDebugInfo = (new Gui::Label(""))->Color(0.8f, 0.8f, 0.8f);
- Add(m_altDebugInfo, Gui::Screen::GetWidth() - 400, 10);
Gui::Screen::PopFont();
m_hudVelocity = (new Gui::Label(""))->Color(s_hudTextColor);
@@ -218,6 +219,7 @@ WorldView::~WorldView()
delete m_rearCamera;
delete m_externalCamera;
delete m_siderealCamera;
+ delete m_navTunnel;
m_onHyperspaceTargetChangedCon.disconnect();
m_onPlayerChangeTargetCon.disconnect();
@@ -1408,99 +1410,6 @@ void WorldView::Draw()
// nav target square
DrawTargetSquare(m_navTargetIndicator, green);
- //if (m_navTargetIndicator.side == INDICATOR_ONSCREEN) {
- Body *navtarget = Pi::player->GetNavTarget();
- if (navtarget != NULL) {
- vector2f indvec = vector2f(m_navTargetIndicator.pos[0], m_navTargetIndicator.pos[1]);
- double distToDest = Pi::player->GetPositionRelTo(navtarget).Length();
-
- vector3d navpos = navtarget->GetPositionRelTo(Pi::player);
- matrix4x4d rotmat; Pi::player->GetRotMatrix(rotmat); rotmat.ClearToRotOnly();
- vector3d eyevec = rotmat * m_activeCamera->GetOrientation() * vector3d(0.0, 0.0, 1.0);
- double dot = eyevec.Dot(navpos);
- bool front = dot < 0.0;
-
- //double anglerad = acos(eyevec.Normalized().Dot(navpos.Normalized())) / (eyevec.Length() * navpos.Length());
-
- double scalingFactor = 1.6;
- double dist = 0.0;
- double d1 = 10.0;
- int i = 1;
- int maxSquareHeight = std::max(Gui::Screen::GetWidth(), Gui::Screen::GetHeight()) / 2;
- double angle = atan(maxSquareHeight / distToDest);
- const float tpos[2] = { m_navTargetIndicator.realpos[0], m_navTargetIndicator.realpos[1] };
- const float distDiffX = tpos[0] - (Gui::Screen::GetWidth() / 2.0f);
- const float distDiffY = tpos[1] - (Gui::Screen::GetHeight() / 2.0f);
-
- /*
- char buf2[1024];
-
- snprintf(
- buf2,
- sizeof(buf2),
- "distToDest: %.3f, distDiffX: %.3f, distDiffY: %.3f\n"
- "navTgtRPosX: %.3f, navTgtRPosY: %.3f\n"
- "camSpacePosX: %.3f, camSpacePosY: %.3f, camSpacePosZ: %.3f\n"
- "dot: %.3f\n"
- "destvecX: %.3f, destvecY: %.3f, destvecZ: %.3f\n"
- "navposX: %.3f, navposY: %.3f, navPosZ: %.3f\n"
- "eyevecX: %.3f, eyevecY: %.3f, eyevecZ: %.3f\n"
- ,
- distToDest, distDiffX, distDiffY,
- m_navTargetIndicator.realpos[0], m_navTargetIndicator.realpos[1],
- m_cameraSpacePos.x, m_cameraSpacePos.y, m_cameraSpacePos.z,
- dot,
- destvec.x, destvec.y, destvec.z,
- navpos.x, navpos.y, navpos.z,
- eyevec.x, eyevec.y, eyevec.z
- );
-
- Gui::Screen::RenderString(
- buf2,
- 60.0, 60.0
- );
- */
-
- if (front) {
- while (true) {
- dist = getSquareDistance(d1, scalingFactor, i);
- if (dist > distToDest) {
- break;
- }
- double sqh = getSquareHeight(dist, angle);
- if (sqh >= 10) {
- float ox = distDiffX * (dist / distToDest);
- float oy = distDiffY * (dist / distToDest);
-
- const float sqpos[2] = { tpos[0] - ox, tpos[1] - oy };
- DrawTargetGuideSquare(sqpos, sqh, green);
-
- /*
- snprintf(
- buf2,
- sizeof(buf2),
- "%.3f, %.3f%%\n" "ox: %.3f, oy: %.3f\n"
- "x: %.3f, y: %.3f",
- dist, ((dist / distToDest) * 100.0),
- ox, oy, sqpos[0], sqpos[1]
- );
-
- Gui::Screen::RenderString(
- buf2,
- sqpos[0] + sqh + 1.0,
- sqpos[1] + sqh + 1.0
- );
- */
- }
- i++;
- }
- }
- } else {
- m_altDebugInfo->SetText("No active target");
- m_altDebugInfo->Show();
- }
- //}
-
glLineWidth(1.0f);
// velocity indicators
@@ -1617,22 +1526,6 @@ void WorldView::DrawTargetSquare(const Indicator &marker, const Color &c)
m_renderer->DrawLines2D(4, vts, c, Graphics::LINE_LOOP);
}
-void WorldView::DrawTargetGuideSquare(const float pos[2], const float size, const Color &c)
-{
- const float x1 = float(pos[0] - size);
- const float x2 = float(pos[0] + size);
- const float y1 = float(pos[1] - size);
- const float y2 = float(pos[1] + size);
-
- const vector2f vts[] = {
- vector2f(x1, y1),
- vector2f(x2, y1),
- vector2f(x2, y2),
- vector2f(x1, y2)
- };
- m_renderer->DrawLines2D(4, vts, c, Graphics::LINE_LOOP);
-}
-
void WorldView::DrawVelocityIndicator(const Indicator &marker, const Color &c)
{
if (marker.side == INDICATOR_HIDDEN) return;
@@ -1717,3 +1610,125 @@ void WorldView::MouseButtonDown(int button, int x, int y)
m_activeCamera->ZoomIn(ft);
}
}
+NavTunnelWidget::NavTunnelWidget(WorldView *worldview) :
+Widget(), m_worldview(worldview)
+{
+ m_worldview = worldview;
+}
+
+void NavTunnelWidget::Draw() {
+ Body *navtarget = Pi::player->GetNavTarget();
+ if (navtarget != NULL) {
+ const Color green = Color(0.f, 1.f, 0.f, 0.8f);
+
+ vector2f indvec = vector2f(m_worldview->m_navTargetIndicator.pos[0], m_worldview->m_navTargetIndicator.pos[1]);
+ double distToDest = Pi::player->GetPositionRelTo(navtarget).Length();
+
+ vector3d navpos = navtarget->GetPositionRelTo(Pi::player);
+ matrix4x4d rotmat; Pi::player->GetRotMatrix(rotmat); rotmat.ClearToRotOnly();
+ vector3d eyevec = rotmat * m_worldview->m_activeCamera->GetOrientation() * vector3d(0.0, 0.0, 1.0);
+ double dot = eyevec.Dot(navpos);
+ bool front = dot < 0.0;
+
+ //double anglerad = acos(eyevec.Normalized().Dot(navpos.Normalized())) / (eyevec.Length() * navpos.Length());
+
+ double scalingFactor = 1.6;
+ double dist = 0.0;
+ double d1 = 10.0;
+ int i = 1;
+ int maxSquareHeight = std::max(Gui::Screen::GetWidth(), Gui::Screen::GetHeight()) / 2;
+ double angle = atan(maxSquareHeight / distToDest);
+ const float tpos[2] = { m_worldview->m_navTargetIndicator.realpos[0],m_worldview->m_navTargetIndicator.realpos[1] };
+ const float distDiffX = tpos[0] - (Gui::Screen::GetWidth() / 2.0f);
+ const float distDiffY = tpos[1] - (Gui::Screen::GetHeight() / 2.0f);
+
+ /*
+ char buf2[1024];
+
+ snprintf(
+ buf2,
+ sizeof(buf2),
+ "distToDest: %.3f, distDiffX: %.3f, distDiffY: %.3f\n"
+ "navTgtRPosX: %.3f, navTgtRPosY: %.3f\n"
+ "camSpacePosX: %.3f, camSpacePosY: %.3f, camSpacePosZ: %.3f\n"
+ "dot: %.3f\n"
+ "destvecX: %.3f, destvecY: %.3f, destvecZ: %.3f\n"
+ "navposX: %.3f, navposY: %.3f, navPosZ: %.3f\n"
+ "eyevecX: %.3f, eyevecY: %.3f, eyevecZ: %.3f\n"
+ ,
+ distToDest, distDiffX, distDiffY,
+ m_navTargetIndicator.realpos[0], m_navTargetIndicator.realpos[1],
+ m_cameraSpacePos.x, m_cameraSpacePos.y, m_cameraSpacePos.z,
+ dot,
+ destvec.x, destvec.y, destvec.z,
+ navpos.x, navpos.y, navpos.z,
+ eyevec.x, eyevec.y, eyevec.z
+ );
+
+ Gui::Screen::RenderString(
+ buf2,
+ 60.0, 60.0
+ );
+ */
+
+ if (front) {
+ while (true) {
+ dist = getSquareDistance(d1, scalingFactor, i);
+ if (dist > distToDest) {
+ break;
+ }
+ double sqh = getSquareHeight(dist, angle);
+ if (sqh >= 10) {
+ float ox = distDiffX * (dist / distToDest);
+ float oy = distDiffY * (dist / distToDest);
+
+ const float sqpos[2] = { tpos[0] - ox, tpos[1] - oy };
+ DrawTargetGuideSquare(sqpos, sqh, green);
+
+ /*
+ snprintf(
+ buf2,
+ sizeof(buf2),
+ "%.3f, %.3f%%\n" "ox: %.3f, oy: %.3f\n"
+ "x: %.3f, y: %.3f",
+ dist, ((dist / distToDest) * 100.0),
+ ox, oy, sqpos[0], sqpos[1]
+ );
+
+ Gui::Screen::RenderString(
+ buf2,
+ sqpos[0] + sqh + 1.0,
+ sqpos[1] + sqh + 1.0
+ );
+ */
+ }
+ i++;
+ }
+ }
+ }
+}
+
+void NavTunnelWidget::DrawTargetGuideSquare(const float pos[2], const float size, const Color &c)
+{
+ const float x1 = float(pos[0] - size);
+ const float x2 = float(pos[0] + size);
+ const float y1 = float(pos[1] - size);
+ const float y2 = float(pos[1] + size);
+
+ const vector2f vts[] = {
+ vector2f(x1, y1),
+ vector2f(x2, y1),
+ vector2f(x2, y2),
+ vector2f(x1, y2)
+ };
+ m_worldview->m_renderer->DrawLines2D(4, vts, c, Graphics::LINE_LOOP);
+}
+
+void NavTunnelWidget::GetSizeRequested(float size[2]) {
+ size[0] = Gui::Screen::GetWidth();
+ size[1] = Gui::Screen::GetHeight();
+}
+
+NavTunnelWidget::~NavTunnelWidget() {
+
+}
View
20 src/WorldView.h
@@ -3,6 +3,7 @@
#include "libs.h"
#include "gui/Gui.h"
+#include "gui/GuiWidget.h"
#include "View.h"
#include "Serializer.h"
#include "Background.h"
@@ -13,10 +14,12 @@ class Body;
class Frame;
class LabelSet;
class Ship;
+class NavTunnelWidget;
namespace Gui { class TexturedQuad; }
class WorldView: public View {
public:
+ friend class NavTunnelWidget;
WorldView();
WorldView(Serializer::Reader &reader);
virtual ~WorldView();
@@ -99,8 +102,8 @@ class WorldView: public View {
void SelectBody(Body *, bool reselectIsDeselect);
Body* PickBody(const double screenX, const double screenY) const;
void MouseButtonDown(int button, int x, int y);
-
- matrix4x4d m_prevShipOrient;
+
+ NavTunnelWidget *m_navTunnel;
Gui::ImageButton *m_hyperspaceButton;
@@ -120,8 +123,6 @@ class WorldView: public View {
Gui::Label *m_debugInfo;
#endif
- Gui::Label *m_altDebugInfo;
-
Gui::Label *m_hudVelocity, *m_hudTargetDist, *m_hudAltitude, *m_hudPressure, *m_hudHyperspaceInfo, *m_hudTargetInfo;
Gui::MeterBar *m_hudHullTemp, *m_hudWeaponTemp, *m_hudHullIntegrity, *m_hudShieldIntegrity;
Gui::MeterBar *m_hudTargetHullIntegrity, *m_hudTargetShieldIntegrity;
@@ -152,4 +153,15 @@ class WorldView: public View {
vector2f m_indicatorMousedirSize;
};
+class NavTunnelWidget: public Gui::Widget {
+public:
+ NavTunnelWidget(WorldView *worldview);
+ virtual ~NavTunnelWidget();
+ virtual void Draw();
+ virtual void GetSizeRequested(float size[2]);
+ void DrawTargetGuideSquare(const float pos[2], const float size, const Color &c);
+
+ WorldView *m_worldview;
+};
+
#endif /* _WORLDVIEW_H */
Please sign in to comment.
Something went wrong with that request. Please try again.