Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411613 Posts in 69390 Topics- by 58447 Members - Latest Member: sinsofsven

May 10, 2024, 02:08:11 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Game Math
Pages: [1] 2
Print
Author Topic: Game Math  (Read 3117 times)
Sigma
Level 1
*


View Profile WWW
« on: November 18, 2009, 10:11:22 PM »

i have keen interest in learning math and physx fundas pertaining games but most of my progress were retarded by the lack of visualization. So i have posted this new topic. Everything looks fine when i was watching a tutorial or while going through some tutorial code, i understand what it does. but when it comes to my own implementation i couldnt visualize how to implement stuffs through math.So with trial and error method after making lots and lots of try i used to find the solution. Its eating most of the valuable time.So i just want to make things clear So guys help me out by  ur valuable replies and comments.

Lets start with vectors.
     I know how to normalize a vector and what it will yield but my question is when i should normalize a vector? give me some gud examples?

All the replies are highly appreciated.
« Last Edit: November 18, 2009, 10:16:03 PM by Sigma » Logged

Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #1 on: November 18, 2009, 10:24:01 PM »

It's kind of an ambiguous question, but one example of normalizing a vector would be to describe a direction in space (you could of course describe a direction in space with any kind of vector, but if you assume all your direction vectors are normalized, you can multiply them by the same speed variable for example to translate something along that direction vector at the specified speed). Many 3d math concepts like surface normals for example usually assume normalized vectors.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #2 on: November 19, 2009, 01:30:51 AM »

Normalise it when you want it to be unit length.

e.g.
- when you want to use a vector as a direction indicator
- when you want a normal to a surface
- when you want to resize a vector to be a certain length, normalise it first and then multiply by the new length
Logged

powly
Level 4
****



View Profile WWW
« Reply #3 on: November 19, 2009, 02:11:15 AM »

Well, normalizing is rarely something you have to do, it's just easier to do it.

For example you don't have to normalize a direction vector. Just divide the scalar by the magnitude of your vector. Same goes for surface normals; when doing your lighting calculations you can just divide the dot product by the magnitudes of your light and surface normal vectors.

When you normalize a vector, you mostly do it for ease of use; it sure is a lot smoother to just multiply your direction vector directly and you sure will want to normalize your surface normals and light vectors so your dot product will automagically return something in the [-1, 1] -region. So, as a general rule, you will want to normalize if you're going to get a cross product or a dot product of your vector or it is a direction vector you will want to multiply by something. Also, many libraries like getting normalized vectors.
« Last Edit: November 19, 2009, 02:14:22 AM by msqrt » Logged
st33d
Guest
« Reply #4 on: November 19, 2009, 03:21:31 AM »

This tutorial set me straight back in the day, if you go through it slow enough you should get a pretty good grasp of vector math.

http://www.tonypa.pri.ee/vectors/tut01.html
Logged
brog
Level 7
**



View Profile WWW
« Reply #5 on: November 19, 2009, 03:45:21 AM »

Let's do a case study!  I'll search through Vertex Dispenser source and explain any reason for normalising a vector.

(dealing with vectors)
- Finding the angle between two vectors.
- Rotating a vector around another vector.

(dealing with levels, which are 3d models)
- Finding the normal to a point on the surface.  This is then used for lighting and for particle effects that will be spraying out of the surface.
- Letting the player select a point on the surface - this involves moving the point in the direction they choose, given by the directions tangent to the surface normal.

(dealing with units)
- When a unit takes damage, it's pushed slightly away from the source of the damage.  So we get a vector between the unit and the damage source, project it into the tangent plane and then normalise (because we want the distance it's pushed to depend on the amount of damage, not on the distance between the attacker and defender).
- When turning to aim towards something, again the normalised vector to the target is used.

(rendering)
- Lighting!
- Drawing things a fixed distance above the level surface.
- Camera moves towards where it should be at a constant speed.. use a normalised vector!

I'm bored of this activity now.
Logged
Sigma
Level 1
*


View Profile WWW
« Reply #6 on: November 19, 2009, 11:17:00 AM »

Thanx for the reply guys. How to rotate an object with respect to other in other terms how to rotate a vector w.r.t another vector?
Logged

increpare
Guest
« Reply #7 on: November 19, 2009, 12:20:03 PM »

Thanx for the reply guys. How to rotate an object with respect to other in other terms how to rotate a vector w.r.t another vector?
Rotation matrices, or if you're in 3d you have the option of using quaternions (they're more efficient/fashionable).  That's not really a 'how', I guess, but those are the things you use to do it.  Rotation matrices are a little more transparent when it comes to understanding, I guess.
Logged
Sigma
Level 1
*


View Profile WWW
« Reply #8 on: November 22, 2009, 09:57:39 AM »

can anybody explain what are quaternions? i couldn't find good starter guide on net everything looks scary
Logged

Dacke
Level 10
*****



View Profile
« Reply #9 on: November 22, 2009, 10:02:53 AM »

can anybody explain what are quaternions? i couldn't find good starter guide on net everything looks scary

Do you know how complex numbers work?
Logged

programming • free software
animal liberation • veganism
anarcho-communism • intersectionality • feminism
JLJac
Level 10
*****



View Profile
« Reply #10 on: November 22, 2009, 10:07:28 AM »

Sigma, I think you have the wrong approach. Very few people work like that, going through different interesting math solutions and trying to find out what they are used for. The easier and more common way is to start on a project, might be a little one just for practise, and when you encounter a problem you try to find a good solution for it. Like this: Don't ask when you should normalize a vector, instead, when you encounter trouble, ask yourself 'could this be solved by normalizing a vector?'.

Code and programming is much easier to grasp when you know what goal you're programming towards. Set up a goal and use your solutions and tricks to achieve it, then you will learn what the tricks are good for as you go.
Logged
Oddball
Level 10
*****


David Williamson


View Profile WWW
« Reply #11 on: November 22, 2009, 05:43:32 PM »

can anybody explain what are quaternions? i couldn't find good starter guide on net everything looks scary

Do you know how complex numbers work?
I used to love working with imaginary numbers at college. Not because you can do cool stuff with them but because they have a cool name.
Logged

BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« Reply #12 on: November 22, 2009, 06:00:21 PM »

can anybody explain what are quaternions? i couldn't find good starter guide on net everything looks scary

Do you know how complex numbers work?
I used to love working with imaginary numbers at college. Not because you can do cool stuff with them but because they have a cool name.

I think the best part about it is the slackers and 'haters' asking the priceless and timeless question:
"When are we ever going to use this in life?"
Logged

JLJac
Level 10
*****



View Profile
« Reply #13 on: November 22, 2009, 09:50:57 PM »

Haha they told us that electricians actually use it for something, but they didn't get more specifik than that. Still great fun to learn, though.
Logged
Sigma
Level 1
*


View Profile WWW
« Reply #14 on: November 23, 2009, 09:59:47 AM »

Hey JLJac i'm not throwing questions randomly; these are the stuffs i'm keep on encountering whenever i'm working on a small project for practice. First i did a small project in directx i have encountered lot of problems, without understanding the actual math
behind i just copy paste the code from different websites; now i just starts working on unity, again the same problems are annoying. So i thought it would be better to understand the important math stuffs related to games, so that i can approach any problems. Don't mistaken me...
Logged

Dacke
Level 10
*****



View Profile
« Reply #15 on: November 23, 2009, 10:12:19 AM »

Sigma, could you perhaps give us details about your current knowledge about these things? If you tell us some things about yourself, we can probably answer your questions in ways you can better understand. Smiley

What level of math have you studied in school?

How much programming do you know?

Have you made any games before?

What kind of games are you trying to make now?
Logged

programming • free software
animal liberation • veganism
anarcho-communism • intersectionality • feminism
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #16 on: November 23, 2009, 02:19:16 PM »

I wouldn't recommend learning the maths which make a quaterion work, it won't help you too much with programming. Instead, you should learn what they are used for, and what operations you can do with them, as this is less work. The first part is simple - they represent a rotation in 3d space, more efficiently than other techniques. You can get a good idea of the operations by reading a decent API (unity's?), but in general it's all the things you can imagine doing with a rotation. You can compose to rotations, apply that rotation to a point or object, animate a rotation, etc.
Logged
Kunal
Level 1
*


is feeling Bit.Core.Trippy


View Profile WWW
« Reply #17 on: November 23, 2009, 08:56:40 PM »

Haha they told us that electricians actually use it for something, but they didn't get more specifik than that. Still great fun to learn, though.

Well, they are incredibly useful for visualizing the solution to differential equations. And in engineering students would typically spend a _lot_ of time solving differential equations

TOTALLY OFFTOPIC
My math teacher in high school once wrote out this equation

e^(i*pi) + 1 = 0

and called it the most beautiful equation in the world since it involves all the important mathematical constants (e,i,pi,1 and zero).
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #18 on: November 24, 2009, 02:19:37 AM »

My math teacher in high school once wrote out this equation

e^(i*pi) + 1 = 0

and called it the most beautiful equation in the world since it involves all the important mathematical constants (e,i,pi,1 and zero).
It's not even that difficult to produce a high-school level proof, which makes it even nicer imho.
Logged
Dacke
Level 10
*****



View Profile
« Reply #19 on: November 24, 2009, 02:26:54 AM »

e^(i*pi) + 1 = 0

I just figured out that it's called Euler's identity:
http://en.wikipedia.org/wiki/Euler%27s_identity
Logged

programming • free software
animal liberation • veganism
anarcho-communism • intersectionality • feminism
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic