How are the axes separated in this rotator?

For system help, all hardware / software topics NOTE: use Coders Corner for all coders topics.

Moderators: Krom, Grendel

Post Reply
User avatar
Dakatsu
DBB Admiral
DBB Admiral
Posts: 1575
Joined: Mon Feb 20, 2006 12:22 am
Location: St. Petersburg, Florida

How are the axes separated in this rotator?

Post by Dakatsu »

So, I've been having fun with the Unreal Development Kit, and am diving into it head first. I want to edit this code in a subclass, but for the return rotator I am incredibly confused.

Here's the code:

Code: Select all

simulated function rotator AddSpread(rotator BaseAim)
{
	local vector X, Y, Z;
	local float CurrentSpread, RandY, RandZ;

	CurrentSpread = Spread[CurrentFireMode];
	if (CurrentSpread == 0)
	{
		return BaseAim;
	}
	else
	{
		// Add in any spread.
		GetAxes(BaseAim, X, Y, Z);
		RandY = FRand() - 0.5;
		RandZ = Sqrt(0.5 - Square(RandY)) * (FRand() - 0.5);
		return rotator(X + RandY * CurrentSpread * Y + RandZ * CurrentSpread * Z);
	}
}
This bold part is the confusing part:
return rotator(X + RandY * CurrentSpread * Y + RandZ * CurrentSpread * Z);

I can't tell where the X, Y, and Z values separate, or specifically, what separates them? By my logic it is simply multiplying it all into one big number. I thought the values were separated by a comma, something like this:
return rotator(X + RandY * CurrentSpread, Y + RandZ * CurrentSpread, Z);

Can someone tell me how it separates those values?
User avatar
Foil
DBB Material Defender
DBB Material Defender
Posts: 4900
Joined: Tue Nov 23, 2004 3:31 pm
Location: Denver, Colorado, USA
Contact:

Post by Foil »

[Edited for clarity]

The (float)*(vector) operations aren't \"just multiplying\". It's defined as an operator which multiplies each value in the vector by the float, and returns a vector.

Similarly, the (vector)+(vector) operations just add each value in the vectors, and return a vector.

So the that whole X + RandY * CurrentSpread * Y + RandZ * CurrentSpread * Z statement returns a vector, not just a number.
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6459
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Post by fliptw »

I wonder if they use quaternions too.
User avatar
Foil
DBB Material Defender
DBB Material Defender
Posts: 4900
Joined: Tue Nov 23, 2004 3:31 pm
Location: Denver, Colorado, USA
Contact:

Post by Foil »

Certainly possible, especially 'under the hood', as using quaternions can have a performance benefit.

But given that this is a \"Development Kit\", I imagine it's just the simpler 3-vectors for the sake of users.
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6459
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Post by fliptw »

I don't think they'd pull their punches that much.

if they did, they have a specific three component vector type.
User avatar
Sniper
DBB Ace
DBB Ace
Posts: 375
Joined: Thu Nov 05, 1998 12:01 pm
Location: MKE. WI
Contact:

Re: How are the axes separated in this rotator?

Post by Sniper »

Dakatsu wrote:This bold part is the confusing part:
return rotator(X + RandY * CurrentSpread * Y + RandZ * CurrentSpread * Z);

I can't tell where the X, Y, and Z values separate, or specifically, what separates them? By my logic it is simply multiplying it all into one big number.
It depends on what type the rotator() function accepts, and what it returns. Without seeing the API, I am assuming that the rotator() function accepts a float. Within the function, it may do some logic, and then spit back out an array with what you need. Only guessing here.

But yes, by the looks of the function, you're just passing in one number.
User avatar
Foil
DBB Material Defender
DBB Material Defender
Posts: 4900
Joined: Tue Nov 23, 2004 3:31 pm
Location: Denver, Colorado, USA
Contact:

Re: How are the axes separated in this rotator?

Post by Foil »

Sniper wrote:But yes, by the looks of the function, you're just passing in one number.
No.

X,Y,Z are vectors.

The + and * operators are vector operators.

The "X + RandY * CurrentSpread * Y + RandZ * CurrentSpread * Z" statement returns a vector.

So, no, it's not a single number being passed to rotator().
User avatar
Sniper
DBB Ace
DBB Ace
Posts: 375
Joined: Thu Nov 05, 1998 12:01 pm
Location: MKE. WI
Contact:

Post by Sniper »

...which is why I asked what the function accepts and what it returns. That would be most helpful. Otherwise, I'm guessing.
Post Reply