Page 1 of 1

How are the axes separated in this rotator?

Posted: Wed Nov 11, 2009 3:17 pm
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?

Posted: Wed Nov 11, 2009 3:36 pm
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.

Posted: Wed Nov 11, 2009 4:15 pm
by fliptw
I wonder if they use quaternions too.

Posted: Wed Nov 11, 2009 4:33 pm
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.

Posted: Thu Nov 12, 2009 1:25 am
by fliptw
I don't think they'd pull their punches that much.

if they did, they have a specific three component vector type.

Re: How are the axes separated in this rotator?

Posted: Thu Nov 12, 2009 10:43 am
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.

Re: How are the axes separated in this rotator?

Posted: Thu Nov 12, 2009 11:17 am
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().

Posted: Thu Nov 12, 2009 12:10 pm
by Sniper
...which is why I asked what the function accepts and what it returns. That would be most helpful. Otherwise, I'm guessing.