Forum

Use the math, Luke

Discuss anything not covered by any of the other categories.

Moderator: InsideQC Admins

Use the math, Luke

Postby mankrip » Tue Aug 31, 2010 9:42 pm

Recently I was trying to figure out how to resize particles down horizontally, and found out that I couldn't use r_refdef.aspect directly for this because when the video width is too small the aspect value becomes bigger than 1, which means it would only be useful for making things taller, instead of more thin.

It was obvious that I needed to "invert" the aspect value in some way to use it in the necessary way, but the funny thing is that it simply occurred to me that the way to do this would be by dividing 1 by the aspect value. In the end this has proven to be correct, but I simply don't know why.

I could have tried subtracting 1 from the aspect value, but for me it simply didn't feel like it would be the right thing to do. And now that the previous algorithm has proven to be correct, it's clear that I was right about this one being incorrect. However, I don't have a clear answer as to why it is incorrect.

I'm sure that any googling for an explanation would take hours and would be futile, just like when I googled for a circle-drawing algorithm that would work in the way I needed (producing horizontal coordinates using vertical coordinates as a base, instead of being based on angles). In the end, I solved both cases myself.

Situations like this makes me feel a bit insecure, because it's as if I'm finding solutions by just banging my head on the keyboard instead of understanding how those things work.

Does anyone else here go through something similar?
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 915
Joined: Fri Jul 04, 2008 3:02 am

Postby Urre » Wed Sep 01, 2010 6:46 am

Every time I code :)
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby andrewj » Wed Sep 01, 2010 11:56 am

aspect is a ratio, width / height.

So it's something to multiply or divide by, and hence subtracting from 1 would not make any sense.
andrewj
 
Posts: 133
Joined: Mon Aug 30, 2010 3:29 pm
Location: Australia

Postby jim » Wed Sep 01, 2010 12:19 pm

It is faster to know without words. Imagine playing Quake and needing to explain every action with words in your mind before you do the actions.
zbang!
User avatar
jim
 
Posts: 599
Joined: Fri Aug 05, 2005 2:35 pm
Location: In The Sun

Re: Use the math, Luke

Postby frag.machine » Wed Sep 01, 2010 1:38 pm

mk wrote:Recently I was trying to figure out how to resize particles down horizontally, and found out that I couldn't use r_refdef.aspect directly for this because when the video width is too small the aspect value becomes bigger than 1, which means it would only be useful for making things taller, instead of more thin.

It was obvious that I needed to "invert" the aspect value in some way to use it in the necessary way, but the funny thing is that it simply occurred to me that the way to do this would be by dividing 1 by the aspect value. In the end this has proven to be correct, but I simply don't know why.

I could have tried subtracting 1 from the aspect value, but for me it simply didn't feel like it would be the right thing to do. And now that the previous algorithm has proven to be correct, it's clear that I was right about this one being incorrect. However, I don't have a clear answer as to why it is incorrect.

I'm sure that any googling for an explanation would take hours and would be futile, just like when I googled for a circle-drawing algorithm that would work in the way I needed (producing horizontal coordinates using vertical coordinates as a base, instead of being based on angles). In the end, I solved both cases myself.

Situations like this makes me feel a bit insecure, because it's as if I'm finding solutions by just banging my head on the keyboard instead of understanding how those things work.

Does anyone else here go through something similar?


As already pointed by andrewj, aspect is a ratio. Looks like your problem is not exactly related only to small width values, but with aspect ratios where width < height, hence you solved it by inverting the ratio formula:
Code: Select all
1/(width/height) = height/width

So, maybe a more generic aspect ratio formula should take in account this condition ?
Code: Select all
float aspect = ((float)(vid.width/vid.height) > 1.0 ? (float)(vid.width/vid.height) : (float)(vid.height/vid.width));
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest