Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   vec<x/y>, sin, cos (https://forums.graalonline.com/forums/showthread.php?t=76607)

Switch 09-02-2007 02:04 AM

vec<x/y>, sin, cos
 
What does vecx/vecy, sin, and cos do/mean??

Kyranki 09-02-2007 03:19 AM

Vectors.

Level of Math Education Suggested: 10 - 11th Grade Calculus

Switch 09-02-2007 03:25 AM

darn im only at an 8th grader's math edu :(

so how about cos and sin?

Knightmare1 09-02-2007 03:39 AM

im 11 xD i only know algebra and can swear in 3 differant languages.....

DustyPorViva 09-02-2007 04:02 AM

vecx/y and sin cos are simple to learn with Graal. I learned that stuff way back in 7th grade on my own(I honestly don't know the true mathmatics behind it... though we did start getting into sine/cosine in Geometry).
vec stands for vector, in which you're getting the vectorx/y of a direction.
Basically, vecx and vecy are like the following arrays:
vecx={0,-1,0,1};
vecy={-1,0,1,0};
It's generally used to get the movement of a direction.
x=vecx(player.dir)
y=vecy(player.dir)
if your direction was 3, would return (1,0).
You can also multiply it like so:
player.x+=vecx(player.dir)*.5
player.y+=vecy(player.dir)*.5
Which would move the player .5 tiles in their direction. Sin/cos are kind of the same(in principle in Graal, I'm sure I will have the math guru's all over me for this post), in which it gets the 'movement' of an angle.

Kyranki 09-02-2007 04:02 AM

My suggestion applied to both subjects.

DustyPorViva 09-02-2007 04:06 AM

I honestly wouldn't dwell on the whole "I'm not in a high enough grade," thing. Best thing to do is find scripts that use the functions and pick them apart(this was a lot easier to do way back than it is now, as offline levels had a lot of scripts, and they weren't as overwhelming as they are now adays). You'll soon learn how they work by trial and error and be impressed with yourself. I learned a lot of stuff in Graal before I was ever taught it in a class, such as coordinates(a Graal level is just like a huge graph paper), arrays, problem solving and algorithms' :)
I mean, it might not apply the same in class, but you'll learn how to use them in Graal, and you won't feel completely out of the loop when you start learning them in school, unlike just about everyone else in your class.

Crow 09-02-2007 01:39 PM

We didnt learn cos/sin in school yet, though I already know how it works. You can really learn alot through Graal, but I guess I cannot help you understand it, because my english is not enough for such things ;P

Chompy 09-02-2007 01:44 PM

Ok, some basic things I learned from playing with sin and cos in graal:
They are from the math term 'trigonometry' where radians is used instead of degrees.
Radians goes from 0 to PI*2.

For example, if you want your player to move in the direction that the player is facing, do this:

PHP Code:

temp.angle = (pi/* (player.dir 1));
temp.speed 1.5;

player.+= cos(temp.angle)*temp.speed;
player.-= sin(temp.angle)*temp.speed

However that will only move the player once, so it should probably be in a loop or when it is provoked by a key for example.
Cos belongs to the x-axis
Sin belongs to the y-axis

This is some simple basic stuff I first learned about cos and sin when I played around with it..
so I don't know if all above is fully correct, so if I'm not, someone else can correct me ;o

coreys 09-02-2007 04:34 PM

Quote:

Originally Posted by Chompy (Post 1345280)
Ok, some basic things I learned from playing with sin and cos in graal:
They are from the math term 'trigonometry' where radians is used instead of degrees.
Radians goes from 0 to PI*2.

Actually, trig uses degrees. I guess it varies from place to place, but at least in America it uses degrees.

But really, I forgot all the trig I learned in Geometry and Algebra 2. >.<

Chompy 09-02-2007 04:37 PM

Quote:

Originally Posted by coreys (Post 1345308)
Actually, trig uses degrees. I guess it varies from place to place, but at least in America it uses degrees.

But really, I forgot all the trig I learned in Geometry and Algebra 2. >.<

xD

Switch 09-02-2007 04:57 PM

Quote:

Originally Posted by Kyranki (Post 1345238)
My suggestion applied to both subjects.

I didn't know because you only said "Vectors" then said you should be in 10th grade.

Quote:

Originally Posted by Chompy (Post 1345280)
Ok, some basic things I learned from playing with sin and cos in graal:
They are from the math term 'trigonometry' where radians is used instead of degrees.
Radians goes from 0 to PI*2.

For example, if you want your player to move in the direction that the player is facing, do this:

PHP Code:

temp.angle = (pi/* (player.dir 1));
temp.speed 1.5;

player.+= cos(temp.angle)*temp.speed;
player.-= sin(temp.angle)*temp.speed


so what does cos and sin really do, or should I not eally be worrying about them?

Tolnaftate2004 09-02-2007 06:41 PM

sin and cos are properties of angles. If you have a right triangle such that angle a is opposite of side A, b opposite of B, and c, the right angle, opposite of the hypotenuse, C, sin(a) = A/C, cos(a) = B/C, sin(b)=B/C, cos(b)=A/C, sin(c)=1, and cos(c)=0.

Though I'm sure you haven't learned it, trigonometry is essential to spherical, polar, and cylindrical coordinate systems. Vector calculations rely heavily on trigonometry, as well as 3D graphics.

They're basically only ever used in graal for pretty light effects and movement systems.

coreys 09-02-2007 09:52 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1345324)
They're basically only ever used in graal for pretty light effects and movement systems.

Yeah pretty much. Like that one stupid light in the graal.net snippet library that just goes around in a (sorta) circle.

Codein 09-04-2007 01:09 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1345324)
sin and cos are properties of angles. If you have a right triangle such that angle a is opposite of side A, b opposite of B, and c, the right angle, opposite of the hypotenuse, C, sin(a) = A/C, cos(a) = B/C, sin(b)=B/C, cos(b)=A/C, sin(c)=1, and cos(c)=0.

Though I'm sure you haven't learned it, trigonometry is essential to spherical, polar, and cylindrical coordinate systems. Vector calculations rely heavily on trigonometry, as well as 3D graphics.

They're basically only ever used in graal for pretty light effects and movement systems.

I was thinking I'd need to use cos and sin for the melee system I need to make. Rather than hit right in front of the player, damage is done to everything that's in the sector in which the sword moves.

DustyPorViva 09-04-2007 01:44 AM

Ya, you can do that. Or you can also specify a few check points (I did this once withe sword.gani, I opened the gani up in Graalshop and translated the pixel position of the tip of the sword into tiles for each frame, and did checks there.

Codein 09-04-2007 01:58 AM

That seems like a good alternative. However, I plan to use weapons which vary in length. It'd look silly if I had a large bamboo pole (there's a japanese word I'm trying to think of) that only did damage at the end of the pole. Obviously, I'm looking more towards doing damage if you're in the area of the sector rather than on the circumference.

DustyPorViva 09-04-2007 02:14 AM

You can define the area of a circle you're willing to check by specifying a point A with an angle and radius, then check all along a circle until getting to point B, which would also be an angle with a radius. Something like:
PHP Code:

this.width=pi/2;
this.checkcount=10;
this.checkwidth=this.width/this.checkcount;
this.radius=5;
this.angle=((player.dir-1)%4)*(pi/2);
for (
i=0;i<this.checkcount;i++) {
  
triggeraction(player.x+cos(this.angle+(this.checkwidth*i))*this.radius,player.y-sin(this.angle+(this.checkwidth*i))*this.radius,"attack");


Or something like that.

zokemon 09-04-2007 05:50 PM

Grades of Math are different in every school so you can't really say "10th grade math".

Codein 09-04-2007 06:23 PM

I got taught about basic trig, including cos/sin/tan functions, at around 13 years old and was a recurring subject until I'd finished school, which was about 3 months ago or so.

As soon as it comes up once in your syllabus, it's more than likely to reoccur in the future. For example, I'm taking Maths at Sixth-Form (which is like Year 12 and 13 of school) and trigonometry makes up a good part of it.

Switch 09-04-2007 09:45 PM

Quote:

Originally Posted by Codein (Post 1345755)
I got taught about basic trig, including cos/sin/tan functions, at around 13 years old and was a recurring subject until I'd finished school, which was about 3 months ago or so.

As soon as it comes up once in your syllabus, it's more than likely to reoccur in the future. For example, I'm taking Maths at Sixth-Form (which is like Year 12 and 13 of school) and trigonometry makes up a good part of it.

I'm learning 9th grade general stuff at age 12 so I guess I'll be learning next year. :confused:

Codein 09-04-2007 09:55 PM

Quote:

Originally Posted by Switch (Post 1345778)
I'm learning 9th grade general stuff at age 12 so I guess I'll be learning next year. :confused:

I think Grade 8 is like Year 9 in England.

Switch 09-04-2007 09:59 PM

Quote:

Originally Posted by Codein (Post 1345782)
I think Grade 8 is like Year 9 in England.

I'm in 7th grade o_O

Codein 09-04-2007 10:06 PM

Quote:

Originally Posted by Switch (Post 1345783)
I'm in 7th grade o_O

Yeah, but you'll move on to 8th Grade sooner or later :P

Nothing is stopping you from learning though :P

Switch 09-04-2007 10:18 PM

Quote:

Originally Posted by Codein (Post 1345787)
Yeah, but you'll move on to 8th Grade sooner or later :P

Nothing is stopping you from learning though :P

Next year = 8th grade = I learn sin/cos in school >_<

Codein 09-04-2007 10:25 PM

Quote:

Originally Posted by Switch (Post 1345790)
Next year = 8th grade = I learn sin/cos in school >_<

Why wait if you have a desire to learn?

Switch 09-04-2007 11:17 PM

Quote:

Originally Posted by Codein (Post 1345792)
Why wait if you have a desire to learn?

Cuz I don't understand what the hell they're talkin about xD

Codein 09-05-2007 12:44 AM

Quote:

Originally Posted by Switch (Post 1345813)
Cuz I don't understand what the hell they're talkin about xD

Ever thought about googling it? If this yields no results, PM me :P


All times are GMT +2. The time now is 04:13 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.