Project InterDimension Drive MFD

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
This is my first MFD also. Thought I would start a new thread for it. It is a MFD to allow a vessel to travel from one location to another location at a high rate of time/speed. Of course it is Science fiction. But it is based off ideas from several TV shows.
I supposed the idea is to use worm holes. There are a couple of MFD's addon's that do Warp or Jump drive. BUT for traveling from one location to another on the same planet. They don't work. I understand why. The curve of the planet gets in the way.

Thanks to Face and meson800 I was able to make a SIMPLE babystep version.

Basically you enters a target vessel and it places your ship at the selected target location.

What I want and I am asking help is to be able to do the same but be able to choose a base rather than a vessel

2 be able to calculate the distance between the selected base and your vessel.

Code:
void IDDRIVE::MOVEVESSEL(void)
{
    OBJHANDLE targetHandle = oapiGetObjectByName(targetName);  // gets the handle of target
    if (targetHandle != NULL) //checks to make sure we have a valid vessel
    {
        VESSEL *v = oapiGetVesselInterface(targetHandle);  //gets interface of target


        VESSELSTATUS2 status;
        status.flag = 0;
        status.version = 2;

        v->GetStatusEx(&status);




        VESSEL *v2 = oapiGetFocusInterface();

        v2->DefSetStateEx(&status);
    }
}


---------- Post added 07-19-14 at 08:44 AM ---------- Previous post was 07-18-14 at 07:54 PM ----------

I have access to RWarp code which allows one to select the base.
Code:
bool cbSelectPlanet(void *id, char *str, void *usrdata)
{
 
     
    instance[gmfdFocus].PlanetRef=oapiGetGbodyByName(str);
    if(instance[gmfdFocus].PlanetRef!=0)
    {
        oapiOpenInputBox("Select Base", cbSelectBase, 0, 20, 0);
    }
    return true;
}
 
bool cbSelectBase(void *id, char *str, void *usrdata)
{
     
 
    instance[gmfdFocus].BaseRef=oapiGetBaseByName(instance[gmfdFocus].PlanetRef, str);
    return true;
}

So here you open and input box and enter the planet and then base. I understand that. But it is the instance[gmfdFocus], don't get.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
oK. Even with code reverse engineering is hard.
in a Global h
Code:
//Global Variables
extern int  MySoundID;
extern C_DATA c_data;
extern INSTANCE instance[INSTANCES];
extern int notePtr[INSTANCES];
extern int gmfdFocus;

#endif

Global.cpp
Code:
INSTANCE instance[INSTANCES];
TIMERS timers[20];
int ship;
int focus;
int notePtr[INSTANCES];



Error 1 error C2065: 'INSTANCES' : undeclared identifier e:\orbiter2010p1a\orbitersdk\samples\iddrivemfd\IDDRIVE_Globals.h 112 1 IDRIVE



Code:
struct INSTANCE
{
	double velocity;
	VESSEL *Spacecraft;
	VECTOR3 GRelPos;
	double distanceToTarget;
	double accelTime;
	double timeToTarget;
	double acc;
	double decelTime;
	double targetRadius;
	double stopDistance;
	double maxWarp;
	double userAperture;
	double gamma;
	double updateHUD;
	BEACONLIGHTSPEC beacon;
	VECTOR3 pos;
	VECTOR3 col;
	double spacecraftSize;
	double fieldSize;
	double totalChargeMass;
	bool warpAttached;
	double fuelRequired;
	NOTEHANDLE noteHandle;
	OBJHANDLE PlanetRef;
	OBJHANDLE BaseRef;
	ENUM_MODES mode;
	OBJHANDLE vesselHandle;
	bool stop;
	double lastDistance;
	VECTOR3 lastPYR;
	VECTOR3 gTargetPos;
	VECTOR3 vectorToTarget;
	VECTOR3 gPos;
	double fval;
	int rmtId;
	ENUM_MFDMODES mfdMode;
	double pctOriented;
	bool rvelSet;
	bool matchSpeed;

} ;
Error 5 error C2011: 'INSTANCE' : 'struct' type redefinition e:\orbiter2010p1a\orbitersdk\samples\iddrivemfd\IDDRIVE_Globals.h 40 1 IDRIVE

Code:
bool cbSelectPlanet(void *id, char *str, void *usrdata)
{


	instance[gmfdFocus].PlanetRef = oapiGetGbodyByName(str);
	if (instance[gmfdFocus].PlanetRef != 0)
	{
		oapiOpenInputBox("Select Base", cbSelectBase, 0, 20, 0);
	}
	return true;
}
Error 8 error C2027: use of undefined type 'INSTANCE' E:\orbiter2010p1A\Orbitersdk\samples\IDDriveMFD\IDRIVE.cpp 107 1 IDRIVE


So what is INSTANCE?
in my cpp I have
Code:
#define INSTANCES       30
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Is `INSTANCES` macro defined before you declare the "Global Variables"?

Was `INSTANCE` type defined earlier, maybe in another header file?

Are you including the header files with your type definitions in correct order in the code before you use them?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
Thanks
Is `INSTANCES` macro defined before you declare the "Global Variables"?
Not sure what you mean?

Are you including the header files with your type definitions in correct order in the code before you use them?
Not sure what you mean by correct order?

What I can find is the lower case "instance"
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Not sure what you mean by correct order?
INSTANCES macro and INSTANCE type must be defined before you declare the variable:
Code:
extern INSTANCE instance[INSTANCES];
Code:
INSTANCE instance[INSTANCES];


What I can find is the lower case "instance"
It's in Global.cpp, as you already listed.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
Still not sure. Funny I didn't see where
Where this is even mention otherthan the solution

IDDRIVEGLOBALS.cpp
Code:
#include "IDDRIVE_Headers.h"

int  MySoundID;
C_DATA c_data;
INSTANCE instance[INSTANCES];
TIMERS timers[20];
int ship;
int focus;
int notePtr[INSTANCES];
int gmfdFocus;
SIMDATA simData;
int rvelSet;


Code:
// ==============================================================
//                 ORBITER MODULE: DialogTemplate
//                  Part of the ORBITER SDK
//          Copyright (C) 2003-2010 Martin Schweiger
//                   All rights reserved
//
// IDDRIVE.cpp
//
// This module demonstrates how to build an Orbiter plugin which
// inserts a new MFD (multi-functional display) mode. The code
// is not very useful in itself, but it can be used as a starting
// point for your own MFD developments.
// ==============================================================

#define STRICT
#define ORBITER_MODULE
#include "windows.h"
#include "orbitersdk.h"
#include "IDDRIVE.h"
#include "IDDRIVE_Globals.h"

// Plugin defines
#define ENGAGE			0
#define CANCEL			1
#define MODES			10
#define MAXCHARS		255
#define MAXFOV			RAD * 45
#define INSTANCES       30
 

Attachments

  • solutionwindow.jpg
    solutionwindow.jpg
    42.9 KB · Views: 2
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
IN MY IDDRIVE_Globals.h
Code:
#ifndef _IDDRIVE_GLOBALS
#define _IDDRIVE_GLOBALS

//Global Defines
#define STOPDISTANCE	stopDistance
#define STOPTIME		5.0
#define JS				0.0000115740740740741	//Julian second
#define MAXACCEL		18000000
#define WARP			maxWarp
#define INSTANCES		30
#define FOCUSGAMMA		instance[focus].gamma

Error 1 error C2011: 'INSTANCE' : 'struct' type redefinition e:\orbiter2010p1a\orbitersdk\samples\iddrivemfd\IDDRIVE_Globals.h 40 1 IDRIVE


Then in my IDDRIVE.cpp
Code:
	//Configure
	for (int index = 0; index<INSTANCES; index++)
	{
		instance[index].mode = mSTOP;
		instance[index].velocity = 0;
		instance[index].vesselHandle = 0;
		instance[index].stop = false;
		instance[index].stopDistance = 1000000.0;
		instance[index].maxWarp = 0.9999;
		instance[index].PlanetRef = 0;
		instance[index].BaseRef = 0;
		instance[index].gamma = 1.0;
		instance[index].fval = 0;
		instance[index].rmtId = -1;
		instance[index].mfdMode = mRWARP;
		instance[index].rvelSet = false;
		instance[index].matchSpeed = true;
		notePtr[index] = -1;


	}
Error 2 error C2027: use of undefined type 'INSTANCE' E:\orbiter2010p1A\Orbitersdk\samples\IDDriveMFD\IDRIVE.cpp 53 1 IDRIVE


The only other reference to "INSTANCE" are: in IDDRIVE_Globals.h
Code:
//Global Variables
extern int  MySoundID;
extern C_DATA c_data;
extern INSTANCE instance[INSTANCES];

Here is the whole IDDRIVE_Globals.h
Code:
#ifndef _IDDRIVE_GLOBALS
#define _IDDRIVE_GLOBALS

//Global Defines
#define STOPDISTANCE	stopDistance
#define STOPTIME		5.0
#define JS				0.0000115740740740741	//Julian second
#define MAXACCEL		18000000
#define WARP			maxWarp
#define INSTANCES		30
#define FOCUSGAMMA		instance[focus].gamma

#define BTN0	LINE*4
#define BTN1	LINE*8
#define BTN2	LINE*12
#define BTN3	LINE*16
#define BTN4	LINE*20
#define BTN5	LINE*24

//Global Constants
const double C=299792458.0;
const VECTOR3 NULL_VECTOR = { 0.0, 0.0, 0.0 };


//Global ENUMS
enum ENUM_TIMERS {tSound=0, tFlashTime=10, tCallOut,tGP1, tUPDATEHUD};
enum ENUM_MODES {mIDLE, mSETUP, mINIT,mSTOP, mORIENT, mACCEL, mDECCEL, mCRUISE, mORIENTONLY, mCHARGE, mDISCHARGE, mRMT, mLOCAL}  ;
enum ENUM_MFDMODES {mRWARP, mIID};
enum ENUM_AXIS{PITCH, YAW, ROLL};
enum COLOR_MODE {COLOR_OFF, COLOR_WHITE, COLOR_RED};

//Global Structs
struct TIMERS
{
	double timer;
	bool flag;
};

struct INSTANCE
{
	double velocity;
	VESSEL *Spacecraft;
	VECTOR3 GRelPos;
	double distanceToTarget;
	double accelTime;
	double timeToTarget;
	double acc;
	double decelTime;
	double targetRadius;
	double stopDistance;
	double maxWarp;
	double userAperture;
	double gamma;
	double updateHUD;
	BEACONLIGHTSPEC beacon;
	VECTOR3 pos;
	VECTOR3 col;
	double spacecraftSize;
	double fieldSize;
	double totalChargeMass;
	bool warpAttached;
	double fuelRequired;
	NOTEHANDLE noteHandle;
	OBJHANDLE PlanetRef;
	OBJHANDLE BaseRef;
	ENUM_MODES mode;
	OBJHANDLE vesselHandle;
	bool stop;
	double lastDistance;
	VECTOR3 lastPYR;
	VECTOR3 gTargetPos;
	VECTOR3 vectorToTarget;
	VECTOR3 gPos;
	double fval;
	int rmtId;
	ENUM_MFDMODES mfdMode;
	double pctOriented;
	bool rvelSet;
	bool matchSpeed;

} ;

struct C_DATA
{
	bool timeDilate;
	bool lengthContract;
	bool callouts;
	bool showField;
	bool visualAb;
	bool freeTravel;
	double emptyMass;
	double fuelEfficiency;
	bool requireDrive;
	double minCharge;
	double maxFov;
	double mainFuelEfficiency;
	bool useFuel;
	double matchSpeedCost;
};

 struct SIMDATA
{
	double simt;
	double simdt;
	double mjd;
	
};

//Global Variables
extern int  MySoundID;
extern C_DATA c_data;
extern INSTANCE instance[INSTANCES];
extern TIMERS timers[20];
extern int ship;
extern int focus;
extern int notePtr[INSTANCES];
extern int gmfdFocus;
extern SIMDATA simData;
extern int rvelSet;
#endif
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
Progress, yes!!!

If I understand this this set all then instance{index} to your assigned values.
Code:
    //Configure
    for(int index=0; index<INSTANCES; index++)
    {
        instance[index].mode=mSTOP;
        instance[index].velocity=0;
        instance[index].vesselHandle=0;
        instance[index].stop=false;
        instance[index].stopDistance=1000000.0;
        instance[index].maxWarp=0.9999;
        instance[index].PlanetRef=0;
        instance[index].BaseRef=0;
        instance[index].gamma=1.0;
        instance[index].fval=0;
        instance[index].rmtId=-1;
        instance[index].mfdMode=mRWARP;
        instance[index].rvelSet=false;
        instance[index].matchSpeed=true;
        notePtr[index]=-1;
 
 
    }
So instance[index].PlanetRef=0;, right?

I am not able to get the input box to open.
I think it is because of the first if statement if if(instance[mfdFocus].PlanetRef!=0)
So if if(instance[mfdFocus].PlanetRef is not equal to zero then proceed., right.

But it is set to zero.


Code:
if(instance[mfdFocus].PlanetRef!=0)
                {
                    if(oapiGetObjectType(instance[mfdFocus].PlanetRef)==OBJTP_PLANET)
                    {
                        oapiOpenInputBox("Select Base", cbSelectBase, 0, 20, (void *)this);
                    }
                }
                break;
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
Ok. trying to get it to display my input

I can get it to display but I want it to display even with the horizon and not at an angle

Code:
bool IDDRIVE::Update(oapi::Sketchpad *skp)
{
	Title(skp, "IDDRIVE");
	// Draws the MFD title
	char Buffer[255];
	char Buffer2[255];
	skp->SetFont(font);
	skp->SetTextAlign(oapi::Sketchpad::CENTER, oapi::Sketchpad::BASELINE);
	skp->SetTextColor(0x00FFFF);
	skp->Text(W / 2, H / 2, "Display area", 12);
	skp->Rectangle(W / 4, H / 4, (3 * W) / 4, (3 * H) / 4);
	skp->SetFont(font);
	CurrentLine = BTN0 - LINE * 2;
	sprintf(Buffer, "ID:%d", mfdFocus);
	//SetTextColor(skp, RGB(0, 255, 0));
	//sprintf(buffer, g_JumpDriveName);
	//l = strlen(buffer);
	skp->Text(10, 2, Buffer, (int)strlen(Buffer));



	//skp->Text(10, CurrentLine, Buffer, (int)strlen(Buffer));
	CurrentLine = 0;
	//hDC = hdc;



	//sprintf(oapiDebugString(), "UP:%0.2f DOWN:%0.2f BL:%0.2f BR:%0.2f YL:%0.2f YR:%0.2f", Spacecraft->GetThrusterGroupLevel(THGROUP_ATT_PITCHUP), Spacecraft->GetThrusterGroupLevel(THGROUP_ATT_PITCHDOWN), Spacecraft->GetThrusterGroupLevel(THGROUP_ATT_BANKLEFT), Spacecraft->GetThrusterGroupLevel(THGROUP_ATT_BANKRIGHT), Spacecraft->GetThrusterGroupLevel(THGROUP_ATT_YAWLEFT), Spacecraft->GetThrusterGroupLevel(THGROUP_ATT_YAWRIGHT));

	CurrentLine = BTN0 - LINE;
	//SetTextColor(skp, RGB(0, 255, 0));
	sprintf(Buffer, "%s", "TARGET                         BASE");
	skp->Text(10, CurrentLine, Buffer, (int)strlen(Buffer));
	CurrentLine = BTN0;
	//SetTextColor(skp, RGB(255, 255, 255));
	if (instance[mfdFocus].PlanetRef != 0) oapiGetObjectName(instance[mfdFocus].PlanetRef, Buffer2, 25); else sprintf(Buffer2, "%s", "Select Target");
	sprintf(Buffer, "%s", Buffer2);
	skp->Text(10, CurrentLine, Buffer, (int)strlen(Buffer));


Code:
#define BTN0	LINE*4
#define BTN1	LINE*8
#define BTN2	LINE*12
#define BTN3	LINE*16
#define BTN4	LINE*20
#define BTN5	LINE*24
 

Attachments

  • iddrivedisplay.jpg
    iddrivedisplay.jpg
    301.3 KB · Views: 13
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
Ok I can get the data to display. But it is at an angle. Even the Display Area from the template is off.

Also why yellow? I looked at the SDK Shouldn't 00FFFF be aqua?

Code:
bool IDDRIVE::Update(oapi::Sketchpad *skp)
{

	char Buffer[255];
	char Buffer2[255];
	Title(skp, "IDDRIVE");
	// Draws the MFD title
	
	
	skp->SetFont(font);
	skp->SetTextAlign(oapi::Sketchpad::CENTER, oapi::Sketchpad::BASELINE);
	skp->SetTextColor(0x00FFFF);
	skp->Text(W / 2, H / 2, "Display area", 12);
	skp->Rectangle(W / 4, H / 4, (3 * W) / 4, (3 * H) / 4);

	sprintf(Buffer, "ID:%d", mfdFocus);
	skp->Text(20, 50, Buffer, (int)strlen(Buffer));

        CurrentLine = 0;
	

sprintf(Buffer, "%s", "TARGET    BASE");
skp->Text(60, 100, Buffer, (int)strlen(Buffer));
 

Attachments

  • MFDALIGNMENT.jpg
    MFDALIGNMENT.jpg
    286.7 KB · Views: 10

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
Seems like I am on my own for this:

So how can one just move their ship to a selected BASE location. I can do that with a vessel.

---------- Post added at 09:37 PM ---------- Previous post was at 07:18 AM ----------

Trying something different
Code:
	char cbuf[256];
	if (targetName != NULL) //checks to make sure we have a valid vessel
	{

		OBJHANDLE hBase = oapiGetBaseByName(targetName, cbuf);
		oapiGetBaseEquPos(hBase, &lng, &lat);
	}
How can I read oapiGetBaseEquPos(hBase, &lng, &lat);s?

Is it possible to move a vessel to those coordinates.

But I can't go past it.
 

BrianJ

Addon Developer
Addon Developer
Joined
Apr 19, 2008
Messages
1,679
Reaction score
902
Points
128
Location
Code 347
Hello,
Also why yellow? I looked at the SDK Shouldn't 00FFFF be aqua?
IIRC these values are not RGB (red, Green, Blue) - they are BBGGRR.
Try FFFF00.


As to why the text is at an angle, my first guess is it might be something to do with this line:
Code:
oapi::Sketchpad::BASELINE
What happens if you remove it?


Code:
    char cbuf[256];
    if (targetName != NULL) //checks to make sure we have a valid vessel
    {

        OBJHANDLE hBase = oapiGetBaseByName(targetName, cbuf);
        oapiGetBaseEquPos(hBase, &lng, &lat);
    }
How can I read oapiGetBaseEquPos(hBase, &lng, &lat);s?

Like this:
Code:
    char cbuf[256];
[COLOR=Red]double base_long = 0;
double base_lat = 0;[/COLOR]
    if (targetName != NULL) //checks to make sure we have a valid vessel
    {

        OBJHANDLE hBase = oapiGetBaseByName(targetName, cbuf);
        oapiGetBaseEquPos(hBase, [COLOR=Red]&base_long, &base_lat[/COLOR]);
    }
Good luck!
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
on the angled display No change when I comment this line out:
Code:
skp->SetTextAlign(oapi::Sketchpad::CENTER oapi::Sketchpad::BASELINE);

Success on the color change.

I am going to try to add this function into a vessel and then convert to a mfd.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,654
Reaction score
2,376
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
on the angled display No change when I comment this line out:
Code:
skp->SetTextAlign(oapi::Sketchpad::CENTER oapi::Sketchpad::BASELINE);
Success on the color change.

I am going to try to add this function into a vessel and then convert to a mfd.

How did you define and create the oapi::Font* font? orientation is the final parameter in "oapi::eek:apiCreateFont()". (See: 7.51.1.2 in the API_Reference.pdf, page 134)
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
I believe just like the MFD template has it:
Code:
// Constructor
MFDTemplate::MFDTemplate (DWORD w, DWORD h, VESSEL *vessel)
: MFD2 (w, h, vessel)
{
    font = oapiCreateFont (w/20, true, "Arial", FONT_NORMAL, 450);
    // Add MFD initialisation here
}
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,654
Reaction score
2,376
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I believe just like the MFD template has it:
Code:
// Constructor
MFDTemplate::MFDTemplate (DWORD w, DWORD h, VESSEL *vessel)
: MFD2 (w, h, vessel)
{
    font = oapiCreateFont (w/20, true, "Arial", FONT_NORMAL, 450);
    // Add MFD initialisation here
}


The number 450 in that function call means 450 * 1/10° = 45° angle of orientation of the text.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
Ok back to this. Going to try something. Place a beacon vessel where you want to go. And select the vessel you want to go to.

So how to get distance of my vessel to the selected vessel?

Code:
void IDDRIVE4::MOVEVESSEL(void)
{

	VECTOR3 aphpos, aphdir, aphrot, gaph;
	VECTOR3 shippos, shipdir, shiprot, gpship;


	OBJHANDLE targetHandle = oapiGetObjectByName(targetName);  // gets the handle of target
	if (targetHandle != NULL) //checks to make sure we have a valid vessel
	{
		VESSEL *v = oapiGetVesselInterface(targetHandle);  //gets interface of target

		//v->GetStatusEx(&targethandle);  //get status of target

		VESSELSTATUS2 status;
		status.flag = 0;
		status.version = 2;

		v->GetStatusEx(&status);
		//
		
		oapiGetGlobalPos(targetHandle, &gpship); // get global postion of ship and put into gpship
			//

		//VESSEL *v = oapiGetVesselInterface(targetHandle);



			VESSEL *v2 = oapiGetFocusInterface();

			v2->DefSetStateEx(&status);
		}
	
}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,745
Reaction score
2,726
Points
203
Location
Dallas, TX
I can select a vessel. We are going to have a beacon vessel that one places via scenario editor at the location they want to be. Open the mfd and select the target and then jump.

But We want a 2 things. this is where I need the help. 1. to calculate the distance between my vessel and the vessel selected. An input of a speed. and then based off the distance and the speed the vessel arrives.
 
Top