Use the math, Luke
Moderator: InsideQC Admins
5 posts
• Page 1 of 1
Use the math, Luke
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?
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?
-

mankrip - Posts: 915
- Joined: Fri Jul 04, 2008 3:02 am
Re: Use the math, Luke
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)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
