Programming Question please help with payload rotation

Mr Martian

Orbinaut/Addon dev/Donator
Addon Developer
Donator
Joined
Jun 6, 2012
Messages
317
Reaction score
122
Points
43
Location
Sydney, Australia, Earth, Sol
Website
www.orbithangar.com
hey guys, i am making a vessel that has a payload, but i want the payload to be rotated 180 degrees when it is jettisoned. this is what i have so far for the payload jettisoning:

Code:
void Pegasus::OrpheusSep (void)
{
	if (OrpheusState == ATTACHED1) // Sanity check, is there a descent stage to jettison?
	{
		VESSELSTATUS vs;
		char name[256];
		VECTOR3 sofs = ORPHEUS_POS;	// Seperation offset			
		VECTOR3	sdir = { 0, 1, 0};		// Seperation direction
		double	svel = 2;				// Separation velocity
		VECTOR3 srot = {0,180,0};

				// Get vessel status structure
		VECTOR3 rofs;
		GetStatus (vs);
		Local2Rel (sofs, vs.rpos);	
		GlobalRot (sdir, rofs);
		vs.rvel += rofs*svel;
		vs.arot = srot;

				// Create descent stage as seperate vessel
		strcpy (name, GetName()); 
		strcat (name, "-Orpheus");
		oapiCreateVessel (name, "ISV_PEGASUS/LANDERS/Orpheus", vs);	// create descent stage vessel
		DelMesh (Mesh_Orpheus);

		OrpheusState = DETACHED1;							// Set vessel status to ascent
	}
}


i am using vs.arot to define the spawned vessel's rotation, but it is not rotated by 180 degrees, it's more just a random rotation that is close to about 50 degrees :idk: i have tried changing the srot value to {0, 1, 0} and {0, 180, 0} but neither works. any help would be much appreciated.

thanks in advance :cheers:
 

Cosmic Penguin

Geek Penguin in GTO
News Reporter
Donator
Joined
Jan 27, 2011
Messages
3,672
Reaction score
2
Points
63
Location
Hong Kong
hey guys, i am making a vessel that has a payload, but i want the payload to be rotated 180 degrees when it is jettisoned. this is what i have so far for the payload jettisoning:

Code:
void Pegasus::OrpheusSep (void)
{
	if (OrpheusState == ATTACHED1) // Sanity check, is there a descent stage to jettison?
	{
		VESSELSTATUS vs;
		char name[256];
		VECTOR3 sofs = ORPHEUS_POS;	// Seperation offset			
		VECTOR3	sdir = { 0, 1, 0};		// Seperation direction
		double	svel = 2;				// Separation velocity
		VECTOR3 srot = {0,180,0};

				// Get vessel status structure
		VECTOR3 rofs;
		GetStatus (vs);
		Local2Rel (sofs, vs.rpos);	
		GlobalRot (sdir, rofs);
		vs.rvel += rofs*svel;
		vs.arot = srot;

				// Create descent stage as seperate vessel
		strcpy (name, GetName()); 
		strcat (name, "-Orpheus");
		oapiCreateVessel (name, "ISV_PEGASUS/LANDERS/Orpheus", vs);	// create descent stage vessel
		DelMesh (Mesh_Orpheus);

		OrpheusState = DETACHED1;							// Set vessel status to ascent
	}
}


i am using vs.arot to define the spawned vessel's rotation, but it is not rotated by 180 degrees, it's more just a random rotation that is close to about 50 degrees :idk: i have tried changing the srot value to {0, 1, 0} and {0, 180, 0} but neither works. any help would be much appreciated.

thanks in advance :cheers:

Try [ame="http://en.wikipedia.org/wiki/Radian"]{0, 3.141592653589, 0}[/ame]. ;)
 

ADSWNJ

Scientist
Addon Developer
Joined
Aug 5, 2011
Messages
1,667
Reaction score
3
Points
38
A couple of ideas from looking at your code...


1. You are mixing relative coords and global coords (Local2Rel and GlobalRot). Was that intentional? You may need to bring everything to a global frame to be consistent.

2. I've generally seen all angles in radians, not degrees, as all the trig functions take radians. Have a play with {0,PI(),0} or equivalent?

Let me know how you get on. I'm in my own coordinate exploration zone on rendezvous coords and orientations in the other thread.
 

Mr Martian

Orbinaut/Addon dev/Donator
Addon Developer
Donator
Joined
Jun 6, 2012
Messages
317
Reaction score
122
Points
43
Location
Sydney, Australia, Earth, Sol
Website
www.orbithangar.com
A couple of ideas from looking at your code...


1. You are mixing relative coords and global coords (Local2Rel and GlobalRot). Was that intentional? You may need to bring everything to a global frame to be consistent.

2. I've generally seen all angles in radians, not degrees, as all the trig functions take radians. Have a play with {0,PI(),0} or equivalent?

Let me know how you get on. I'm in my own coordinate exploration zone on rendezvous coords and orientations in the other thread.

thanks ADSWNJ, i actually tried experimenting with {0*RAD, 0*RAD, 0*RAD};

this is what i have, it rotates the spawned vessel a near-perfect 180 degrees:

Code:
void Pegasus::OrpheusSep (void)
{
	if (OrpheusState == ATTACHED1) // Sanity check, is there a descent stage to jettison?
	{
		VESSELSTATUS vs;
		char name[256];
		VECTOR3 sofs = ORPHEUS_POS;	// Seperation offset			
		VECTOR3	sdir = { 0, 1, 0};		// Seperation direction
		double	svel = 2;				// Separation velocity
		VECTOR3 srot = {0*RAD, 110*RAD, 0*RAD};

				// Get vessel status structure
		VECTOR3 rofs;
		GetStatus (vs);
		Local2Rel (sofs, vs.rpos);	
		GlobalRot (sdir, rofs);
		vs.rvel += rofs*svel;
		vs.arot = srot;

				// Create descent stage as seperate vessel
		strcpy (name, GetName()); 
		strcat (name, "-Orpheus");
		oapiCreateVessel (name, "ISV_PEGASUS/LANDERS/Orpheus", vs);	// create descent stage vessel
		DelMesh (Mesh_Orpheus);

		OrpheusState = DETACHED1;							// Set vessel status to ascent
	}
}

i think that i had to define that the unit was radians, not Pi... im not sure, im kind of new to coding :lol:
 

ADSWNJ

Scientist
Addon Developer
Joined
Aug 5, 2011
Messages
1,667
Reaction score
3
Points
38
i think that i had to define that the unit was radians, not Pi... im not sure, im kind of new to coding :lol:

It's all good. There's 2 PI radians in a circle's circumference, so your * RAD is a constant for * 2 * PI() / 360. 180 degrees would be PI, so {0, 180, 0} becomes {0, PI(),0} or (0,180*RAD,0}.

After pushing back on radians instead of degrees for a long time as a programmer, I have come to like the simplicity they bring to equations. Now of course, had Tau risen to popularity instead of Pi, then the life of a radian would have been even prettier, nut that's for another story.
 
Top