API Question Camera rotation pan

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
I have got a question. I have a cockpit camera that the position changes dynamically. But when I switch to it I can not pan using ALt+ arrow keys. It resists the change.

Code:
if ((CAM==4)&&(PADSel==0)){
    SetCameraDefaultDirection (_V(-1,0,0));
        SetCameraOffset ((CAM_pos4));
        //SetCameraShiftRange(_V(0,0,1),_V(-1,0,0),_V(1,0,0));
        SetCameraRotationRange (1,1,1,1);
      oapiCameraSetCockpitDir (0,0);
}

This is in the poststep
 

asbjos

tuanibrO
Addon Developer
Joined
Jun 22, 2011
Messages
696
Reaction score
259
Points
78
Location
This place called "home".
First, I guess that you mean Ctrl and arrow keys, not Alt.

It seems like that the reason is the line "oapiCameraSetCockpitDir". This will in every frame set your camera in the default direction (the direction pointed by SetCameraDefaultDirection) every frame. If you remove it, you can again pan your camera as you want.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks that fixed that. One other issue. Is when the camera is moving in this case only in the Y direction The camera is moving ahead of the location. When I stop the camera is in the correct. I think it is a timing issue?
The cam position is based off of the movement of the cab

Code:
if (CAB_proc > 55.8) CAB_proc = (55.8);
    else if (CAB_proc < 0) CAB_proc = (0);

    if (CAB_check == CAB_DOWN)CAB_proc = (CAB_proc + .05);
    else if (CAB_check == CAB_UP)CAB_proc = (CAB_proc - .05);
    else if (CAB_check == CAB_STOP)CAB_proc = CAB_proc;

	    if (CAB_proc > 55.8) CAB_proc = (55.8);
    else if (CAB_proc < 0) CAB_proc = (0);

Code:
CAM_pos4.x=19.0;
CAM_pos4.z=231.42;
CAM_pos4.y=56.2-(CAB_proc);
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks. I have run into another issue.

I have a cockpit that rotates 310 degrees. So the animation code looks like this:
Code:
	 COCKPIT1 = new MGROUP_ROTATE (2, COCKPITGrp1, 28,_V(.012, .26467119 , 2.2077), _V(0,1,0), (float)(310*RAD));

So straight forward along the z axis is .5 animation state. I want the camera to follw the rotation of the cockpit. So when the cockpit is straight ahead Cockpit_proc =.5 then the camera is 0,0,1.
http://i373.photobucket.com/albums/oo179/gattispilot/camerarotation_zps0a3a0f56.jpg
Code:
(COCKPIT_proc1=(COCKPIT_proc*310)-155 );   
	   
	   
	   //SetAnimation (anim_ENGINENEW, COCKPIT_proc);
CAMZ=cos(COCKPIT_proc1);
CAMX=sin(COCKPIT_proc1);
//if CAMX >1 CAMX=1;
//if CAMX <0 CAMX=1;
	SetCameraDefaultDirection (_V(CAMX,0,CAMZ));

I tried this but the camera shook badly and was off.

I want also to be able to switch to a straight forward shot also.

Code:
case 0:  //PILOT
           SetCameraDefaultDirection (_V(0,0,1));
          SetCameraOffset (_V( -.2,.7,1.943));
		  oapiCameraSetCockpitDir (0,0);
          break;
 case 1:  //PILOT
           SetCameraDefaultDirection (_V(0,0,1));
          SetCameraOffset (_V( -.2,.7,1.943));
		  oapiCameraSetCockpitDir (0,0);
          break;
 
Last edited:

asbjos

tuanibrO
Addon Developer
Joined
Jun 22, 2011
Messages
696
Reaction score
259
Points
78
Location
This place called "home".
I did something similar for my probe where I have a solar array which can be rotated, and I have a camera which follows the rotation of the array.
Here is the code:
In PreStep:
Code:
if (ActiveCamera == 2 && oapiCameraInternal() == true)
	{
		SetCameraDefaultDirection (_V( 0,-cos(ArrayRotateProcess*2*PI), sin(ArrayRotateProcess*2*PI)));
		oapiCameraSetCockpitDir (0, 0);
	}
AcitveCamera = 2 is the solar array camera.

In ConsumeBufferedKey:
Code:
case OAPI_KEY_C: // switch camera
	// checking that the view is in cockpit mode
	if (oapiCameraInternal() == false)
	{
		// Don't do anything
		return 0;
	}
	else if (ActiveCamera == 0 /* Was in main view*/)
	{
		// location of the camera (under the antenna)
		SetCameraOffset (_V( 0.0124,-0.6,-0.1136));

		// Direction of the camera : -Y axis
		SetCameraDefaultDirection (_V( 0,-1, 0));
        
		// Rotate camera to desired direction
		oapiCameraSetCockpitDir ( 0, 0);

		// Make camera fixed
		SetCameraRotationRange (0,0,0,0);

		// Remeber which camera is in use
		ActiveCamera = 1;
		return 1;
	}
	else if (ActiveCamera == 1) // Was in antenna view
	{
		// location of the camera (under the antenna)
		SetCameraOffset (_V( 0.0124,-0.6,-0.1136));

		// Direction of the camera : follow array rotation (done in clbkPreStep)

		// Rotate camera to desired direction
		oapiCameraSetCockpitDir ( 0, 0);

		// Make camera fixed
		SetCameraRotationRange (0,0,0,0);

		// Remeber which camera is in use
		ActiveCamera = 2;
		return 1;
	}
	else if (ActiveCamera == 2) // Was in solar array view
	{
		// Set camera back to default
		SetCameraOffset (_V(-0.449269, 0.126497, 1.45));

		// Set to default direction
		SetCameraDefaultDirection (_V( 0, 0, 0));

		// SetCameraRotationRange-values are the default ones (page 437 in Orbitersdk\doc\API_Reference.pdf
		SetCameraRotationRange ( 0.8*PI, 0.8*PI, 0.4*PI, 0.4*PI);

		// Rotate camera back to default view
		oapiCameraSetCockpitDir ( 0, 0);

		// Remember which camera is in use
		ActiveCamera = 0;
		return 1;
	}

I hope it helps.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks. I will try it. One issue is that at I need the view to be +z when the animation state is .5

I did this:
Code:
if ( oapiCameraInternal() == true)
	{
		SetCameraDefaultDirection (_V( -sin(COCKPIT_proc*2*PI),0, cos(COCKPIT_proc*2*PI)));
		oapiCameraSetCockpitDir (0, 0);
	}

At .5 proc = I get 0,0,-1. But I need 0,0,1
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
I this in the prestep
Code:
void myship::clbkPreStep (double simt, double simdt, double mjd)
{
if (CAM=2 && oapiCameraInternal() == true)
	{
		COCKPIT_proc1=((COCKPIT_proc*-1)*2*PI);
		//cos(COCKPIT_proc1*2*PI*2). 
		double sinb = sin(COCKPIT_proc1);
		double cosb = cos(COCKPIT_proc1);
		SetCameraDefaultDirection (_V( sinb,0, cosb));
		//oapiCameraSetCockpitDir (0, 0);
			   //sprintf(oapiDebugString(),"cam %f cam %f cam %f cam %f",COCKPIT_proc,COCKPIT_proc1,sinb,cosb);

	}

So I what the camera when COCKPIT_proc=.5 to be 0,0,1

so if COCKPIT_proc=.5 then COCKPIT_proc1=-3.1459 which makes sin =0 and cos 1., right?

But when i turn left or right it does wrong

---------- Post added 11-28-13 at 09:51 AM ---------- Previous post was 11-27-13 at 09:07 PM ----------

This gives the correct values. But it shakes badly.

Code:
if (CAM=2 && oapiCameraInternal() == true)
    {
        COCKPIT_proc1=(((COCKPIT_proc)*320)-160);
        //cos(COCKPIT_proc1*2*PI*2). 
        double sinb = (sin(COCKPIT_proc1));
        double cosb = (cos(COCKPIT_proc1));
        SetCameraDefaultDirection (_V( sinb,0, cosb));
        //oapiCameraSetCockpitDir (0, 0);
               sprintf(oapiDebugString(),"cam %f cam %f cam %f cam %f",COCKPIT_proc,COCKPIT_proc1,sinb,cosb);

    }

So if the cockpit_proc is .5 then .5x320-160 gives us 0. Sin 0 =0 cos 0 =1. At 0 x320-160 = -160
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Any clue on how to rotate the cockpit camera to follow the animation.

---------- Post added at 04:43 PM ---------- Previous post was at 03:12 PM ----------

This works but is reverse. So when the angle is 90 degrees sitting in the cockpit would be to the left. This put the camera to the right. (-1,0,0)

Code:
    COCKPIT_proc1=(((COCKPIT_proc)*320)-160);
        //cos(COCKPIT_proc1*2*PI*2). 
        double sinb = (sin(COCKPIT_proc1));
        double cosb = (cos(COCKPIT_proc1));
        SetCameraDefaultDirection (_V( sinb,0, cosb));
        //oapiCameraSetCockpitDir (0, 0);
//               sprintf(oapiDebugString(),"cam %f cam %f cam %f cam %f",COCKPIT_proc,COCKPIT_proc1,sinb,cosb);

    
               sprintf(oapiDebugString(),"cam %f cam %f cam %f cam %f",COCKPIT_proc,COCKPIT_proc1,sinb,cosb);
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
oK. i am going to ry something else. Make an attachment point like an robot arm and then have the camera follow the rotation. But I can't get the tip right.

Code:
	static UINT COCKPITGrp2[1] = {0};
	rms0_anim[0] = new MGROUP_ROTATE (10, COCKPITGrp1, 1,_V(0,2.7,-4.88), _V(0, 1, 0), (float)(320*RAD)); // -180 .. +180
	anim_arm_cockpit = CreateAnimation (0.5);
parentcockpit = AddAnimationComponent (anim_arm_cockpit, 0, 1, rms0_anim[0]);
	
		

	rms0_anim[1] = new MGROUP_ROTATE (LOCALVERTEXLIST, MAKEGROUPARRAY(arm0_tip), 3,
		_V(0,0,0), _V(0,1,0), (float)(894*RAD)); // -447 .. +447
	anim_arm_wr = CreateAnimation (0.0);
	hAC_arm0 = AddAnimationComponent (anim_arm_wr, 0, 1, rms0_anim[1], parentcockpit);


Code:
//COCKPIT
double dd = simdt * .2;

  if (COCKPIT_proc > 1) COCKPIT_proc = (1);
    else if (COCKPIT_proc < 0) COCKPIT_proc = (0);

    if (COCKPIT_check == COCKPIT_LEFT)COCKPIT_proc = (COCKPIT_proc + dd);
    else if (COCKPIT_check == COCKPIT_RIGHT)COCKPIT_proc = (COCKPIT_proc - dd);
    else if (COCKPIT_check == COCKPIT_STOP)COCKPIT_proc = COCKPIT_proc;

	    if (COCKPIT_proc > 1) COCKPIT_proc = (1);
    else if (COCKPIT_proc < 0) COCKPIT_proc = (0);
	if (COCKPIT_proc!=.5){
	if (COCKPIT_check == COCKPIT_CENTER){
	if (COCKPIT_proc < COCKPIT_proc_request) {
                COCKPIT_proc = COCKPIT_proc + (dd);
                if (COCKPIT_proc > COCKPIT_proc_request)
                    COCKPIT_proc = COCKPIT_proc_request;
            } else {
                COCKPIT_proc = COCKPIT_proc - (dd);
                if (COCKPIT_proc < COCKPIT_proc_request)
                    COCKPIT_proc = COCKPIT_proc_request;
	}}}

	
SetAnimation (anim_COCKPIT, COCKPIT_proc);	
SetAnimation (anim_arm_cockpit, COCKPIT_proc);

	xp0=arm0_tip[1]-arm0_tip[0];normalise(xp0);
 xr0=arm0_tip[2]-arm0_tip[0];normalise(xr0);


Code:
SetCameraDefaultDirection (( xp0,0,xr0));
		//oapiCameraSetCockpitDir (0, 0);
//			   sprintf(oapiDebugString(),"cam %f cam %f cam %f cam %f",COCKPIT_proc,COCKPIT_proc1,sinb,cosb);

	
			   sprintf(oapiDebugString(),"cockpit %f cockpit1 %f sin %f cos %f",COCKPIT_proc,COCKPIT_proc1,xp0,xr0);

Code:
arm0_tip[0] = _V(0,1.57,4.6);
arm0_tip[1] = _V(1,1.57,4.6);
arm0_tip[2] = _V(0,1.57,3.6);

The xp changes not the xr
 
Top