3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1] 2

Author Topic: Vector3 & Quaternion  (Read 974 times)

« on: October 12, 2013, 11:30:42 AM »
Hi.

how can work with vector3 & Quaternion in 3drad? I need More Explanation about
vector3 & Quaternion, Because I want Begin Learn more about 3drad scripting.

Thanks

My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
« Reply #1 on: October 12, 2013, 01:05:05 PM »
Good for you that you've decided to learn.

Some ago I posed something about all the existing variables in AngelScript.
http://www.3drad.com/forum/index.php?topic=7719.msg62125#msg62125

I've also discussed Vector3 and Quaternion.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #2 on: October 13, 2013, 12:43:14 AM »
OK, Thanks Roberto.  :D
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
« Reply #3 on: October 13, 2013, 12:29:38 PM »
in this code when A key is hold, SkinMesh can rotate in z axis. But I want when release A key, Fast does not stop and decrease rotation speed slowly then stop. But I don't know how can do it.

Code: [Select]
float rotate;
Quaternion quaternion;
void Main()
{
   if (iKeyDown(iKeyCode("DIK_A"))) {
   iQuaternionFromEulerAngles(quaternion,0,0,rotate,"xyz");
   iObjectOrientationSet(OBJ_0,quaternion);
   rotate += 30; 
}
Please guide me to write this code.

and I need more explanation about this functions :

iQuaternionFromEulerAngles
iQuaternionFromAxisAngle
iQuaternionToEulerAngle

Thanks.
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
« Reply #4 on: October 13, 2013, 02:01:13 PM »
iQuaternionFromEulerAngles

This return a Quaternion made of three components you specified. This function is the one you'll use most when dealing with Quaternions.

iQuaternionFromAxisAngle

This functions returns a Quaternion based on a Vector and an angle rotated around this vector. Kinda complicated, not important right now.

iQuaternionToEulerAngle

This gives you the three x, y and z components of a Quaternion. But.. It's broken, it doesn't work like you would want it to.

in this code when A key is hold, SkinMesh can rotate in z axis. But I want when release A key, Fast does not stop and decrease rotation speed slowly then stop. But I don't know how can do it.

I think I understand. The trick is to change the speed of the rotation.

float z = 0, speed = 0;
void Main()
{
   if (iKeyDown(iKeyCode("DIK_A")))
   {
     speed = 10;
   }
   else
   {
      if (speed > 0) speed -= 0.1;
      else speed = 0;
   }

   Quaternion q;
   iQuaternionFromEulerAngles(q,0,0,z,"xyz");
   iObjectOrientationSet(OBJ_0,q);

   z += speed;
}

Note, I haven't tested the code above. I just wrote it here.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #5 on: October 13, 2013, 02:53:35 PM »
Quote
iQuaternionFromEulerAngles

This return a Quaternion made of three components you specified. This function is the one you'll use most when dealing with Quaternions.

Quote from: behdadsoft on Today at 12:29:38 PM
iQuaternionFromAxisAngle

This functions returns a Quaternion based on a Vector and an angle rotated around this vector. Kinda complicated, not important right now.

Quote from: behdadsoft on Today at 12:29:38 PM
iQuaternionToEulerAngle

This gives you the three x, y and z components of a Quaternion. But.. It's broken, it doesn't work like you would want it to.

Thanks Roberto for your explanation and good script. it work very well.

I learned some C++ programming syntax, but I can't write good scripts.
I'm really disappointed. because really I don't know how can write better scripts. ???




My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
« Reply #6 on: October 14, 2013, 12:13:54 AM »
...how can write better scripts. ???

It's just a matter of practise. You got to learn some kind of logic-thinking.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #7 on: October 14, 2013, 01:44:02 AM »
can you more explanation? I tried to learn more programming logic and some syntax but what should I do not know. I can read most scripts but I can't write good.
Please help me out of this confusion would survive.

Thanks
« Last Edit: October 14, 2013, 01:45:37 AM by behdadsoft »
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
« Reply #8 on: October 14, 2013, 06:00:04 AM »
I'm sorry, there is no magic solution here. Practise is the key..


For now, don't worry about the feeling of not knowing everything. I'd suggest you just start making your game and try to solve all the problems you encounter. If you can't work it out, ask here.
This is the best way of learning programming.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #9 on: October 14, 2013, 06:04:45 AM »
Quote
I'm sorry, there is no magic solution here. Practise is the key..
For now, don't worry about the feeling of not knowing everything. I'd suggest you just start making your game and try to solve all the problems you encounter. If you can't work it out, ask here.
This is the best way of learning programming.

Ok, Thanks Roberto. :)
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
« Reply #10 on: October 18, 2013, 09:52:19 AM »
One thing you can do to improve your code logic ability is to do Sudoku puzzles.  Sudoku puzzles require you to consider many possibilities and think 1 step ahead. 

Game logic is driven by 'if' statements and comparison operators (and, or, not, equals).   

Another way to achieve better logic is to explain it in the simplest terms possible.  The easiest code is often the most useful. 
Imagine a level system in a game.  You have experience points, levels, level requirements, and have to tell the game that if the points reach the amount of points you need to gain a level, reset the points and add one to the level, but you also need to preserve the points gained above that level requirement. 

So if you are level 1 and you need 10 exp to reach level 2, then add 1 to your level and reset the required exp.

int level = 1, exp = 0;

void Main()
{
   if (level == 1 && exp > 10)
   {
      level = 2;
      exp = 0;
   }
}

That's really all there is to thinking how code logic will affect your game.  The above code will do what it it says, but it does need refining because we need the game to be able to know how much exp and levels the player could possibly have at any given time without having to be there to change it for them manually while they play the game.

My code for this system is so simple and clean I impressed myself when I figured it out.  I thought it would be more complicated.  Its not totally finished, but it achieves what we want for a progressive all-knowing level system:

//exp is active exp points, totalExp is your total exp, and
//tnl (meaning to next level) is the amount of exp you need to level up
// we set the tnl the first time and let the game do the rest
int exp, totalExp = 0, tnl = 10, level = 1, scaleFactor = 2;

if ([something happens]) { exp += 5; totalExp += exp; }
if (totalExp >= tnl) { level++; tnl += totalExp / scaleFactor; }

The first line checks if something has happened.  If it has, you get 5 exp and that exp is then added to your total
The second line is checking if the total exp you have equals the required exp to level up.  If it has, add 1 to your current level.

THe next part is something of my own design.  There are MANY ways this could go at this point, but this way is just about as simple as it gets, and it works surprisingly well.  Lets say I have 50 levels in my game.  I would have to define each level's required exp individually if I wanted them to be static (always the same).
So level 1, tnl = 10, level 2, tnl = 20, level 3, tnl = 35, and so on.  This creates a problem later on if you want to change the level up amount or you have to balance the exp you are getting with how much you need per level (a difficulty scale factor).  This is why I made this simple equation.
The game takes how much exp you have and divides it by the scale factor.  In this case, after you [did something] 2 times, your exp would equal your tnl and you would level up.  Since your total exp is 10 at this point, the new tnl would be 10 + 10 / 2, or 15.  Now you have to [do something] 3 times to level up, creating a slight increase in how much effort needs to be put into the game to continue leveling.  When you hit level 3 the equation would read, tnl = 15 + 15 / 2.  since 15 / 2 is 7.5, but the variable is an integer data type, it would be rounded to 8, making your new tnl 15 + 8 = 23.  You now have to [do something] 5 times in order to reach level 4.  This also works if you are playing through the game and collect more exp from harder enemies or challenges.

The point I'm making is that I had to think about this and go through all these mental steps and checklists to arrive at the results I wanted for my game, and that would work every time.

Hope this helped somehow!

-Sorv
« Reply #11 on: October 28, 2013, 08:48:10 AM »
Vector3 & Quaternion variables how much space is occupied in memory?
I should define 45 Vector3 variables and I need know this amount don't decrease frame rate?

Thanks
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
« Reply #12 on: October 28, 2013, 02:23:18 PM »
45 Vector3 variables?! ...I hope that's a typo.  Besides, in an advanced scripting situation, everything would get loaded from a file so you can change the values in the file to test and change the game without even needing Rad to be open.  Try that one for size ;)
« Reply #13 on: October 29, 2013, 07:57:21 AM »
Quote
I should define 45 Vector3 variables and I need know this amount don't decrease frame rate?

why are you asking this question... JUST DO IT and see...

just add a simple declaration for  45 vector3 vars  to any project...

Code: [Select]
Vector3[]        loc(45);
and see... 

if you want you could add a simple loop and populate the array with some data...

iFrameRate() will give you and idea of the frame rate...

--Mike

« Reply #14 on: November 05, 2013, 03:29:55 AM »
I Optimize my Project and decrease the Vector3 from 45 to 8. But I want Know Vector3 and Quaternion data type how much space is occupied in memory?

and I Need Know this issue:
every int or float occupied 4 byte space in memory. if I define int var = 2 , my var is occupied 8 byte in memory right?

Thanks
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0

possible way, if we found will make a way.
Pages: [1] 2