• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
MARS_999

Help with the math on this?

24 posts in this topic

I am not sure what this is even called in math terms, but here I go...

 

i have a range from 0 to 1

 

and I want to take the value of 1 and make that 0, and 0 and make that 1. and if I have .1 make it .9 and .9 make it .1

 

So I am not sure how to do this. And/or what it's called.

 

Thanks!

0

Share this post


Link to post
Share on other sites

The 2 points are p0 = 1 and p1 = 0 (values at time t = 0 and t = 1 respectively).

 

He mentioned specific values for t in his post (t = 0.1 and 0.9).

 

Lerp is the general case for this

 

p = (1 - t) * p0 + t * p1 = p0 - t * (p0 - p1)

 

Plugging in p0 = 1 and p1 = 0 we get

 

p = 1 - t(1 - 0) = 1 - t

 

which is what fir said too (with variables named differently, y == p and x == t)

2

Share this post


Link to post
Share on other sites

From reading his post, he wants 0 --> 1, 1 --> 0   and  0.1 --> 0.9 and 0.9 --> 0.1.

Indeed, y = 1.0 - x

 

You can use it to determine diagonals on slopes if you have square tiles, for example.

Edited by Kaptein
0

Share this post


Link to post
Share on other sites

Well yeah, I assumed he wanted linear interpolation not polynomial.

 

Lagrange's Polynomial Interpolation Formulae will do that though. EDIT: Maybe Legendre not Lagrange ;)

Edited by Paradigm Shifter
0

Share this post


Link to post
Share on other sites

(imo) this is not interpolation, this is some specyfic case of linear transformation ( [0,1] -> [0,1] ) whose probably has some naming, though i dont know it

0

Share this post


Link to post
Share on other sites

Stop overly complicating it guys.

 

float getVal(float in)

{

return in==1.0f ? 0.0f : in==0.0f ? 1.0f : in==0.1f ? 0.9f : in==0.9f ? : 0.1f; --assumes infinite precision floating point, otherwise not possible to satisfy requirements

}

0

Share this post


Link to post
Share on other sites
I'm pretty sure that's not what the op wants, I expect they want 0.5 to map to 0.5 and 0.25 to map to 0.75, so f(t) = 1 - t is correct.
0

Share this post


Link to post
Share on other sites

I don't understand why some of you developers are so against 'generalisations', that is what you do all the time anyway.  Instead of bashing the people who mentioned LERP and made it more 'complicated', you should be grateful to learn something new, although more 'complicated'.  It is a good exercise to get better at what you are doing.   If you are ever going to translate between any other values, that is the formula you will need to to get the job done anyway.  It is seriously good to know, although it shouldn't be too hard to come up with that yourself with a bit of thinking.

 

It is not like the easy solution was not posted already.

 

Personally, I have used both LERP and 1-t a lot of times without even seeing the connection, so for me it was kind of useful.  I have actually 'invented' LERP a lot of times in my head already without even knowing the 'label' LERP.  I am sure anyone who has ever needed a fixed number of steps between two arbitrary points have done that.

 

By the way...  Using values between 0 and 1 is used in a lot of fields, one which is probability.  Me, for one, last time I used this kind of value was to multiply with sample data to make a volume control, (0 = 0, 1000000 = 1) so these kind of values crops up everywhere.

0

Share this post


Link to post
Share on other sites

I don't understand why some of you developers are so against 'generalisations', that is what you do all the time anyway.

I don't think anyone's against generalizing, per se. Personally, I feel that over-complicating the situation is adding nothing significant; otherwise, we could provide all sorts of methods to solve simple problems, like trying to tell our children to find the area of a square for their geometry homework by integrating.
 
However, there's something more to it:

I want to take the value

It sure sounds like he's not doing it out of curiosity, by his wording. It also sounds like he wants to program something to do it; otherwise, why ask, if he could do it by hand, and isn't asking simply to be scholarly?
 
The thing is, if he doesn't understand the algorithm for what he wants, and he's trying to implement it, then giving him a complex and inefficient way of solving the problem isn't the best answer, if he may be unable to derive the simpler answer for his use case. Linear interpolation is much slower than subtracting two numbers, so it is no better of an answer than the one already posted.

Of course, if Paradigm Shifter was attempting to build on fir's answer with more information for the sake of knowledge, then that's well and fine. However, providing a one line answer that may sound contradictory to someone who doesn't immediately see the link between the two creates confusion. If Paradigm Shifter's first two posts were combined into one, from the beginning, and underscored that the simplification was what the OP was after, and how we got there, there probably would have been less conflict.
 
All in all, with clarification in place, I agree with the above points.

0

Share this post


Link to post
Share on other sites

I gave a one line answer because the OP asked what it was called, fir had already given the specific answer and I just said what the technique was called in the general case ;)

0

Share this post


Link to post
Share on other sites

I am not sure how to go about setting up a method to determine a color value for each object that is unique. Obviously they need to be unique to determine which one you clicked on, but with only RGB 256 each channel just doing red++ for 256 values and moving to green++ is one way but how can I code it so it a rolling increment. 

 

e.g.

start with red = 0, red++ when red hits 255 move to green, when green hits 255, blue is incremented to 255 then after that start with red = 1, green = 1, blue = 1 or other combos green = 1, blue = 1 red = 0? 

 

Not sure I am making myself clear, but starting to think ray casting and AABB would just be easier in the long run?

 

THanks!

0

Share this post


Link to post
Share on other sites

I am not sure how to go about setting up a method to determine a color value for each object that is unique. Obviously they need to be unique to determine which one you clicked on, but with only RGB 256 each channel just doing red++ for 256 values and moving to green++ is one way but how can I code it so it a rolling increment. 

 

e.g.

start with red = 0, red++ when red hits 255 move to green, when green hits 255, blue is incremented to 255 then after that start with red = 1, green = 1, blue = 1 or other combos green = 1, blue = 1 red = 0? 

 

Not sure I am making myself clear, but starting to think ray casting and AABB would just be easier in the long run?

 

THanks!

For unique colors, you can simply have the color be a 32bit number, and add one when you need a new one. To extract the color, take the bottom eight bits as red, the next lowest eight bits as green, then the eight bits above that as blue. If you want the exact scheme as you've posted, that will require some more logic, but this is the fastest way.

0

Share this post


Link to post
Share on other sites

 

I don't understand why some of you developers are so against 'generalisations', that is what you do all the time anyway.

I don't think anyone's against generalizing, per se. Personally, I feel that over-complicating the situation is adding nothing significant; otherwise, we could provide all sorts of methods to solve simple problems, like trying to tell our children to find the area of a square for their geometry homework by integrating.
 
However, there's something more to it:

I want to take the value

It sure sounds like he's not doing it out of curiosity, by his wording. It also sounds like he wants to program something to do it; otherwise, why ask, if he could do it by hand, and isn't asking simply to be scholarly?
 
The thing is, if he doesn't understand the algorithm for what he wants, and he's trying to implement it, then giving him a complex and inefficient way of solving the problem isn't the best answer, if he may be unable to derive the simpler answer for his use case. Linear interpolation is much slower than subtracting two numbers, so it is no better of an answer than the one already posted.

Of course, if Paradigm Shifter was attempting to build on fir's answer with more information for the sake of knowledge, then that's well and fine. However, providing a one line answer that may sound contradictory to someone who doesn't immediately see the link between the two creates confusion. If Paradigm Shifter's first two posts were combined into one, from the beginning, and underscored that the simplification was what the OP was after, and how we got there, there probably would have been less conflict.
 
All in all, with clarification in place, I agree with the above points.

 

 

That is not what I meant with my post.  The one line answer is good and correct and sane.  The LERP answer is overly complicated, but...  My point is that even if he got his answer, which I am sure is how everybody would solve this problem, it is NOT useless to fill in more information about a topic.  If you don't want to learn from it, that is fine, but my point was to tell naysayers here to not dismiss on behalf of everybody else who want to learn something new, and be better at what they are doing.  This thread is available for anyone to learn from for the future.  To add information that people can learn from if they want, is in my opinion not a bad thing, it is actually good.  That is the reason I defended the person who wrote the little note about LERP.  If you are not interested?  That is fine.  I found it interesting, and someone else might find it interesting too. This forum is full of people giving more information about things than is initially asked for.  Lots of people are learning from that.

0

Share this post


Link to post
Share on other sites

I don't know enough to make it work, but in pseudocode

 

static int _x = 0;

int[red, green, blue, alpha] GetNextColor()

{

  //note, after 2^32 colors, this will fail. if you remove alpha, you only get 2^24 colors

  _x++;

  int alpha (_x >> 24) % 256 //Only take the last 8 bits

  int red = (_x >> 16) % 256 //I think this means that you will ignore the first 16 bits of _x, and only look at the next 8 bits

  int green = (_x >> 8) % 256 //Ignore the first 8 bits, and only look at the next 8 bits

  int blue = _x % 256 //Only look at the first 8 bits

  return [red, green, blue, alpha]

}

I am not sure what you are looking to do here? Is this allowing me to add one to the color palette and cycle all the way through rgb? so get all 16.7 million color variations?

 

If so thanks!

 

Update!

BedderDanu  thanks that worked great!!! Edited by MARS_999
0

Share this post


Link to post
Share on other sites


If you are not interested?

No one said I wasn't interested. To be honest, I never thought of it that way.

 


it is NOT useless to fill in more information about a topic.

Never said that.

 


Of course, if Paradigm Shifter was attempting to build on fir's answer with more information for the sake of knowledge, then that's well and fine.

I have no idea where you are getting the idea that I am against his insight.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0