Jump to content

Multiplying a scalar with a vector?


DorianaCele
 Share

You are about to reply to a thread that has been inactive for 1654 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello everyone, 

I am just wondering how to multiply an scalar with a vector, defined by multiplying the scalar on each elements of that vector. The background of this is quite simple: I wanna shrink some object's size to 10% of its original size. So after I get its size stored in a vector using "current_size = llGetScale();" function, I wanna define a new_size which is 10% of the current size. But simply typing "new_size = 0.1*current_size;" generates an error. And I cannot find the corresponding operator of scalar multiplying vector in knowledge base. I know using the "." operator to quote elements of the vector individually, however I think it is a waste since I do believe there should be some dedicated operator for such very well-defined math calculation. So can anyone tell me what is that operator to multiply a scalar and a vector by multiplying each elements of that vector the scalar? Thank you very much.

Link to comment
Share on other sites

1 hour ago, Rolig Loon said:

You should be able to write

vector new_size = old_size * 0.1;

That's an allowable operation.  You also have the function llScaleByFactor, if you want to rescale an entire linkset.

Thank you, however my following script got compiling error as shown in the image. It happens when defining global variables. 

https://gyazo.com/ca24f4ccb4e8097b00e5e9bef54f0222

Where could possibly go wrong?

Link to comment
Share on other sites

Going on the absence of indentation in those lines, I'd guess that you're trying to do this as part of a global declaration.

You cannot perform a calculation in a global declaration, though you can assign a constant value, as you do with size_original.

Without seeing the rest of the script, I'd suggest you just declare the vector size_shrinked as a global, and assign it a value in the state_entry event.

vector size_original = <blah, blah, blah>;
vector size_shrinked;

default
{
    state_entry ()
    {
        size_shrinked = size_original * 0.1;
        // etc., etc,
    }

    // etc., etc.
}

 

Edited by KT Kingsley
  • Like 3
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1654 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...