Thread: Vector Operations in 3D Graphics

  1. #16
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by BobMcGee123
    While I do it myself, dotproduct really shouldn't even be a function, rather preferably a macro (it typically takes longer just to call the function than to actually execute it).
    This is not nesscarely true in C++. To avoid using macros I would instead use an inline function if such optimization were needed. I'm actually working on an nth dimensional vector class. Its kinda fun

    A . B = |A| |B| cos
    Being a little picky but thats saying to take the absolute value of A & B. To indicate magnitude it'd be:
    ||A|| ||B||

  2. #17

    Join Date
    May 2005
    Posts
    1,042
    This is not nesscarely true in C++. To avoid using macros I would instead use an inline function if such optimization were needed. I'm actually working on an nth dimensional vector class. Its kinda fun
    Which is why I said typically


    Being a little picky but thats saying to take the absolute value of A & B. To indicate magnitude it'd be:
    ||A|| ||B||
    Yeah, pedantic, but technically right.

    EDIT: Actually, when you take the 'absolute' value of a vector as noted by a single bar it can be interpreted as the magnitude/norm

    http://whatis.techtarget.com/defini...i817829,00.html


    The absolute value of a vector in n dimensions is defined in terms of the coordinates of its termination point, in Cartesian n-space, assuming its origin coincides with the point where all coordinate values are zero. Suppose v is a vector in n dimensions, represented by the following coordinates:

    v = (v1,v2,v3, ..., vn)

    Then the absolute value of v is given by:

    |v| = (v1^2 + v2^2 + v3^2 + ... + vn^2)^1/2

    http://mathworld.wolfram.com/SingleBar.html

    But, double bar is still more socially acceptable (you'll get kicked out of an MIT frat for not using it).

    Also, to bubba, you don't check for division by zero in your normalization function. Typically floats have picked up enough 'noise' and will never quite be zero, but I ran into this problem when writing a 3D camera: if the user just happened to pressed both strafe buttons at the same time, or forward and backwards at the same time, it would set the velocity to the zero vector...when I tried to extract the velocity direction the vector would have coordinates <ISNAN,ISNAN,ISNAN> which had a nice view of nothingness. I also find it funny that you choose to optimize by taking 1 over length and multiplying instead of dividing each time yet you put the normalize function twice in your dotproduct which adds a lot of sqrt surfing.
    Last edited by BobMcGee123; 09-07-2005 at 09:00 PM.
    I'm not immature, I'm refined in the opposite direction.

  3. #18
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Which is why I said typically
    typically would denote more often then not, which really isn't the case.

    About the division by zero, what about the good ol' zero vector?

  4. #19
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    All these definitions of 'vector' are technically incorrect. The 'most general' definition of a vector says nothing about points or distance with direction or arrows. The definition of a vector is that a vector is an element of a vector space. A vector space is a set of elements that is associated with a field, with an addition operation, and with a multiplication operation that multiplies an element of the field with an element of the vector space (a scalar with a vector). These operations have to obey certain axioms. (With x,y,z vectors, a and b scalars, these are: x + y = y + x; (x + y) + z = x + (y + z); there exists an element '0' such that 0 + x = x, for all x; for every x exists a (-x) such that x + (-x) = 0; a(bx) = (ab)x; (a + b)x = ax + bx; a(x + y) = ax + ay; 1x = x)

    For example, a vector space could be a set of real-valued functions on the interval (0,1). (You can add them, multiply them by a scalar, etc.)

    Quote Originally Posted by Perspective
    I recommend any first year university linear algebra book.
    A note to the original poster: Be careful what you buy. Some linear algebra books will introduce vectors as a purely abstract thing -- along the lines of what I wrote above. You will probably want one that focuses on the specific type of vectors that are lists of real numbers. For example, I don't think the linear algebra book I have right now makes any mention of dot products. They are more of a geometric phenomenom.

    Consider the first part of this post a warning of what you'll get if you buy the wrong book. (You'll hopefully run into that somewhere in the book, whatever book you buy, but the abstract stuff probably would not help you solve any game-related issues you have right now.)

  5. #20

    Join Date
    May 2005
    Posts
    1,042
    >>typically would denote more often then not, which really isn't the case.
    Perhaps

    >>About the division by zero, what about the good ol' zero vector?
    I don't see what you mean...division by zero is illegal regardless, which is why you need to check for it in your normalize function.
    I'm not immature, I'm refined in the opposite direction.

  6. #21
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I know, I was giving a defined case in which you would have a zero length vector. I was trying to show another possible case in which one could get division by zero.

  7. #22

    Join Date
    May 2005
    Posts
    1,042
    Oh, blearg yeah nvm I misunderstood you somehow
    I'm not immature, I'm refined in the opposite direction.

  8. #23
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Yeah, I really can't think of a worse way of implementing dotproduct.
    Thanks for your two cents. Which is about what it's worth in this case.


    The poster did NOT ask for every possible use of the dotproduct - I was giving one that is coded for clarity - not for speed. I would never use this function in my code. Lighten up.
    My physics code does not normalize the vectors and lighting in my engine is not even computed with C++ code, rather it's done on the GPU with shaders......for most objects, but not all. Not all objects need dot product lighting. I use a combination of static lighting with dynamic lighting thrown in only when necessary.

    That book also tells you more uses of the dot product and it should be noted there is nothing wrong with the book. It explains the dot product quite precisely. It does NOT tell you every possible application of it. Part of the goal of the book is to help people understand the concepts of 3D w/o throwing tons of code at them - hence they must think for themselves or do some more research to get more information. Notice one word in the title of the book: PRIMER.

    That's it? Vectors are just 3D points that form line segments and view frustrums?
    That is NOT what I said. Read. Vectors are not 3D points in space. Read a book or google for vectors. Or go to www.gamedev.net and look at one of their tutorials on vectors.

    And on a side note:
    Bob I have no idea what your issue is or who you think you are but I do bow before your greatness. You might be good at code, good at math, and a brilliant programmer....but regardless your attitude sucks, and your comments in replies to my posts are not needed.
    Last edited by VirtualAce; 09-08-2005 at 09:00 PM.

  9. #24

    Join Date
    May 2005
    Posts
    1,042
    Your sensitivity is adorable. I didn't attack you personally, just being critical of your code, which is fair because it really is the worst way of doing dotproduct, and I needed to point that out to the newbie. You are being irrational, just calm down, you can stand having your code criticized.

    But bowing to my greatness is pretty cool though

    Just wondering, how old are you?

    EDIT:
    I found another problem with something you've said:
    geometric definition of the dot product states that the dot product is equal to the cosine of the angle between two vectors
    This actually isn't true. The dotproduct is not defined as the cosine between vectors, it's definition is:
    A.B = |A| |B| cos

    not A.B = cos

    As supported by mathworld:
    The dot product can be defined for two vectors X and Y by:

    X.Y = |X||Y|cos(¿)
    http://mathworld.wolfram.com/DotProduct.html

    |A|=|B| = 1 is a special case, not the definition (as I could prove with some physical concepts which originated around the time of the invention of vector math which require length to be unscathed).
    Don't you love learning new things? And yes, I am going to correct you everytime I see something wrong with what you say.

    Cheers!
    Last edited by BobMcGee123; 09-09-2005 at 09:06 PM.
    I'm not immature, I'm refined in the opposite direction.

  10. #25
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Don't you love learning new things?
    I haven't learned anything.

    Do a board search under my name concerning dot product and cosine. I've posted this very thing before. My word definition was not completely accurate.

    http://cboard.cprogramming.com/showt...ht=dot+product

    This thread might be of some interest.
    There are about 50 more concerning dot product.
    Last edited by VirtualAce; 09-10-2005 at 09:05 PM.

  11. #26

    Join Date
    May 2005
    Posts
    1,042
    You saw the message I assume, so I can remove it now (seems inflammatory otherwise).
    Last edited by BobMcGee123; 09-13-2005 at 04:52 PM.
    I'm not immature, I'm refined in the opposite direction.

  12. #27
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Since you cant see my messages I highly recommend you alter your attitude. I could post several example threads where you have pretty much bashed me and acted as Mr. Know It All for no reason - none of which helped the original poster or thread.

  13. #28
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Ok guys lets cool it off. There is no need to get in a fight over this. Bubba go drink a beer and post more screenshots of your graphics engine. BobMcGee123 go do the same if you are of age, otherwise drink some milk and post the screenshots.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3d graphics without API
    By h3ro in forum Game Programming
    Replies: 6
    Last Post: 05-31-2008, 11:51 AM
  2. 3D graphics for a noob?
    By Crazy Glue in forum Game Programming
    Replies: 8
    Last Post: 12-17-2006, 01:38 AM
  3. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 04:15 PM
  4. 3D Graphics -- How?
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-07-2002, 02:49 AM
  5. 3D Modelling + Graphics Cards
    By MethodMan in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-17-2002, 10:29 PM