![]() |
|
|||||||
| Orbiter SDK Orbiter software developers post your questions and answers about the SDK, the API interface, LUA, meshing, etc. |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
Like the title says, I need help breaking a monster-sized (vessel) class into more managable sub-classes.
Specifically I want to take my Lunar Lander's autopilot functions/variables and (for the sake of readability) place them in their own class. However the base vessel class still needs acces to some of those variables for situations like. Code:
if (ThrotControlAuto()) SetThrusterGroupLevel(THGROUP_HOVER, AP_CommandedThrust); As per the DG example LEM_AP is defined as a friend class to SpiderLEM (my vessel class) Code:
class SpiderLEM: public VESSEL3 {
friend class LEM_AP; // LEM Autopilot Class
public:
SpiderLEM (OBJHANDLE hVessel, int flightmodel);
~SpiderLEM ();
...
Code:
// ==============================================================
// ORBITER MODULE: 'SPIDER' LUNAR EXCURSION MODULE
// A custom Vessel For Orbiter 2010/2011
//
// LEM_Autopilots.h
// Class interface for Lunar Excursion Module Autopilot
// ==============================================================
#include "Orbitersdk.h"
#include "SpiderLEM.h"
class VESSEL3;
class LEM_AP: public SpiderLEM {
public:
LEM_AP (VESSEL3 *v);
virtual ~LEM_AP ();
// Autopilot Functions
void OrientForBurn(VECTOR3& tgtVector);
void SetPitch(double tgtPitch);
void SetRoll(double tgtRoll);
void SetHdg(double tgtHdg);
void AutoHover(void);
void AutoAscent(double simt);
void AutoLand(double simt);
double rRate;
double AP_CommandedThrust, AP_CommandedYaw, AP_CommandedRoll, AP_CommandedPitch; // Autopilot control inputs
protected:
VESSEL3 *vessel;
private:
int AP_ProgState; // current autopilot program state
};
Code:
#include "LEM_Autopilots.h"
LEM_AP::LEM_AP (SpiderLEM *vessel)
{
}
LEM_AP::~LEM_AP ()
{
}
Assorted Functions beyond this point...
If I comment the constructor out the code compiles but I am unable to call any of LEM_AP's functions. Please help a C++ noob figure this out. |
|
|
|
|
|
#2 |
|
O-F Administrator
![]() ![]() ![]() |
Quote:
Code:
LEM_AP::LEM_AP (VESSEL3 *vessel) : SpiderLEM (vessel) {
}
Code:
SpiderLEM (OBJHANDLE hVessel, int flightmodel); Are you sure you want to extend the SpiderLEM class with LEM_AP or only make it a friend class? |
|
|
|
| Thanked by: |
|
|
#3 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
Quote:
Code:
You need an OBJHANDLE of the vessel and flghtmodel to be passed to the SpiderLEM's constructor. Quote:
My problem is simply that the class definition for SpiderLEM itself is rapidly becoming unmanageably large. I thought that breaking various sub-systems off into thier own sub-classes would help counter this. |
|
|
|
|
|
#4 |
|
O-F Administrator
![]() ![]() ![]() |
When you extend SpiderLEM class, which extends VESSEL3 class, you basically create another vessel class based on SpiderLEM, so another vessel. If LEM_AP is just SpiderLEM's autopilot, it shouldn't extend SpiderLEM. Remove ": public SpiderLEM" from the class declaration.
|
|
|
|
| Thanked by: |
|
|
#5 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
Quote:
Code:
class LEM_AP {
public:
LEM_AP (VESSEL3 *v);
virtual ~LEM_AP ();
// Autopilot Functions
|
|
|
|
|
|
#6 |
|
O-F Administrator
![]() ![]() ![]() |
Quote:
|
|
|
|
|
|
#7 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
Ok,
made the change and added SpiderLEM (the primary vessel class) as a friend of LEM_AP. Now the compiler error I'm geting is lots of undeclared identifiers. Functions with the "SpiderLEM::" prefix are marked "illegal reference to non-static member" Do I tell it to get those values from SpiderLEM? Am I going to have to redeclare them? |
|
|
|
|
|
#8 |
|
O-F Administrator
![]() ![]() ![]() |
Quote:
Code:
SpiderLEM::member Code:
vessel->member |
|
|
|
|
|
#9 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
What if the variable or function in question is unique to SpiderLEM (not a member of the VESSEL3 class)?
Likewise How do I call LEM_AP functions from within Spider? Last edited by Hlynkacg; 08-19-2012 at 10:52 PM. |
|
|
|
|
|
#10 |
|
Orbinaut
|
Quote:
Code:
class Lander
{
...
LEM_AP autopilot;
};
Code:
//somewhere in code ... autopilot.some_autopilot_function() ... Code:
class Lender
{
...
LEM_AP *autopilot;
};
//somewhere in code
...
autopilot->some_autopilot_function()
...
One more thing is if you haven't corrected it already. You've declared such constructor in your autopilot class Code:
LEM_AP (VESSEL3 *v); Code:
LEM_AP::LEM_AP (SpiderLEM *vessel)
{
}
Code:
LEM_AP::LEM_AP (VESSEL3 *vessel)
{
}
Last edited by marooder86; 08-19-2012 at 11:09 PM. |
|
|
|
|
|
#11 |
|
O-F Administrator
![]() ![]() ![]() |
Quote:
|
|
|
|
|
|
#12 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
Quote:
Quote:
Uderstand that aside from having a pretty strong math background I'm coming into this armed with little more than the Orbiter API documentation, and a C++ for beginners turorial. I've gotten as far as I have by copying/modifying the SDK samples and through help from this very forum. ---------- Post added at 01:23 AM ---------- Previous post was at 12:26 AM ---------- Another quick question... if I add a clbkPreStep or clbkPostStep to my LEM_AP class will orbiter call it? it'd be nice from a code readability stand point if I could move AP's "house keeping" along with the AP. |
|
|
|
|
|
#13 |
|
O-F Administrator
![]() ![]() ![]() |
Quote:
Quote:
|
|
|
|
|
|
#14 |
|
Orbinaut
|
Quote:
From my point of view, in your case both ways would be equally good, although personally I would go with the first option(storing the actual object as a member) since both classes are strongly interconnected and depand on each other existance. But you know, that's only my .
|
|
|
|
|
|
#15 |
|
Aspiring rocket scientist
![]() ![]() ![]() |
I'm probably missing something obvious so bear with me...
I added to "class LM_AP Autopilot;" to my SpiderLEM class but the compiler is flagging it as undeclared. do I have to include my LEM_Autopilot.h file in SpiderLEM.h? (or move the class declaration to SpiderLEM.h?) If so wouldn't this cause issues with recursion? (LEM_Autopilot.h includes SpiderLEM.h) |
|
|
|
![]() |
|
| Thread Tools | |
|
|
|||||
| Quick Links | Need Help? |