Jump to content
james23222000

Script - Math

Recommended Posts

I was just wondering, what do the following lines of script do:

Math::EulerToMatrix(0.f, 0.f, 0.f, ident);

Math::MultiplyMatrices();

Also, on thing I am gonfused about is when to use a '.' or an '->' in a script.

e.g

v->PushActionWait(ACTION_APPEND, 6.0f);

v.PushActionWait(ACTION_APPEND, 6.0f);

Regards

James

Link to comment
Share on other sites

I was just wondering, what do the following lines of script do:

Math::EulerToMatrix(0.f, 0.f, 0.f, ident);

Math::MultiplyMatrices();

Kinda hard to explain as I don't know what each line exactly does.

But I can explain how to use it and what the whole code together does.

You have x, y and z axes, right? z-axis is always up/down and not really important for now.

Look at my awesome sketch:

axesvo1.jpg

You have these axes on the maps (=red), but vehicles have them too (in green)!

When you use the following code to get the position which should be based on the axes your vehicle (the caller) the game will use the MAP-axes to place it.

Vehicle v(Caller);
Vector NEWPOS = v.GetPosition() + Vector(400.f, 0.f, 0.f);

A vector is an x,y,z position. In this case the NEWPOS is the position of the Caller + 400 on the x-axis of the MAP.

This means you can never put on object directly in front of a vehicle with a code like this, because the NEWPOS is not on the x-axis of the vehicle.

This code however, makes it possible to get a new vector based on the axes of the vehicle and not the map:

Vehicle v(Caller);
Vector NEWPOS = v.GetPosition();
float r[9];
float childr[9];
v.GetRotation(r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]);
float dx = 400.f, dy = 0.f, dz = 0.f;
Math::RotateVector(dx, dy, dz, r);
Math::EulerToMatrix(0.0f, 0.f, 0.f, childr);
Math::MultiplyMatrices(childr, r);
NEWPOS = NEWPOS + Vector(dx, dy, 0);

-------------------------------------------------------------------

Also, on thing I am gonfused about is when to use a '.' or an '->' in a script.

e.g

v->PushActionWait(ACTION_APPEND, 6.0f);

v.PushActionWait(ACTION_APPEND, 6.0f);

Regards

James

In simple words a '->' means the object is a variable. It's not defined (yet). Example:

Caller->PushActionWait(ACTION_NEWLIST, 1.0f);

The Caller in this example might be everything. From a vehicle to a person or even a particle.

PushAction codes usually work well with variables.

A '->' doesn't really work with codes that are bound to a specific object type. For example

Caller->GetHealth();

The above won't work, because that code can only be used with objects defined as persons (vehicles don't have health lol). So this would be necessary for example:

Person p(Caller);
p.GetHealth();

I hope this makes it more clear for you,

Hoppah

Link to comment
Share on other sites

Thanks Hoppah :),

Just one last simple question, what is the difference between a single timer and an interval timer in mission scripts?

Regards

James

Single timer ends, interval is a 'looped' timer.

For example:

Mission::StartSingleTimer("Timer1", 60.f);
Mission::StartIntervalTimer("Timer1", 60.f);

60.f is the time in seconds. After 60 seconds the SingleTimer stops, but the IntervalTimer starts again.

This way you can make a code that checks something each minute. Timers only work in missionscripts ofcourse.

Use the following OnTimer code for the timer results, like this:

void OnTimer(const char* timer_, float time_)
{
switch(timer_)
{
case "Timer1":
{
Mission::PlayHint("Timer test");
}
break;
}
}

Using the SingleTimer will play this hint after 60 seconds.

IntervalTimer will play it every 60 seconds until you stop the timer. :)

Hoppah

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...