Advanced Question Camera issues?

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
10,550
Reaction score
4,375
Points
203
Location
Dallas, TX
I have run into 2 issues not sure how to fix them if possible.

1. Generally the default for the camera is +Z direction. I have it set this way but it still show the +z direction.

Code:
{
    // physical specs
    SetSize (10);
    SetEmptyMass (1500.0);
    SetCW (0.3, 0.3, 0.6, 0.9);
    SetWingAspect (0.1);
    SetWingEffectiveness (0.1);
    SetCrossSections (_V(1,1,1));
    SetRotDrag (_V(1.5, 1.5, 1.5));
    if (GetFlightModel() >= 1) {
        SetPitchMomentScale (1e-4);
        SetBankMomentScale (1e-4);
    }

    SetTrimScale (0.05);
    SetCameraDefaultDirection (_V(0,0,-1));
    SetCameraOffset (_V(-.1,-8.2,15.9));

2. I can select the cockpit camera to different locations. But when I switch to another vessel and back to this one it goes back to the default direction. When I press a key to change the camera position it goes to the next one. So I have to cycle back to here I was.

Code:
void MYvessel::SelectCockpitView (int CAM)
{
    
          if (CAM==1) {

            SetCameraDefaultDirection (_V(0,-.453990,-.89));
            SetCameraOffset (_V(-.1,-3.5,18));
            oapiCameraSetCockpitDir (0,0);
          }

          if (CAM==2) {
            SetCameraDefaultDirection (_V(-.7,0,-.7));
            SetCameraOffset (_V(11,-8,30));
            oapiCameraSetCockpitDir (0,0);
          }
}

....
if(key==OAPI_KEY_V)
{
                CAM = CAM + 1;
            if(CAM > 2) CAM = 1;
                    SelectCockpitView(CAM);
            return 1;
}
 
I'm answering the question, even after so many years, so any one that stops here with the problem could have a solution.

There's 3 VESSEL2 events you must handle when dealing with non standard views:

Code:
	virtual void clbkFocusChanged (bool getfocus, OBJHANDLE hNewVessel, OBJHANDLE hOldVessel);

	virtual bool clbkLoadVC (int id);

	virtual bool clbkLoadGenericCockpit ();

The LoadVC and the LoadGenericCockpit are obvious - they are called when you switch to a Virtual Cockpit station (selected by ID), or when you select the Glass Cockpit. You redefine your camera here, but this will last only until another vessel gets the focus.

The magic you need happens on clbkFocusChanged . This callback is called when someone lost the focus (you included), and when someone get the focus (you included). What you need is to detect when you get the focus so you can restore your views.

There're lots more things you could do with this call back, but I will deal only with the problem at hand now. The following code snippet would solve this:

Code:
void RANGER1::clbkFocusChanged (bool getfocus, OBJHANDLE hNewVessel, OBJHANDLE hOldVessel) {
	if (!getfocus || hNewVessel != this->GetHandle()) return;
	InitCamera();
}

Where InitCamera is the function that will detect the current viewing mode for your vessel (Internal Camera? If yes, Virtual Cockpit? Panel? Generic?) and then reset the camera position/direction as you wish.
 
Back
Top