Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 189 190 [191] 192 193 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887611 times)

zombie urist

  • Bay Watcher
  • [NOT_LIVING]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2850 on: August 30, 2012, 11:29:42 pm »

Ok thanks.  :)
Logged
The worst part of all of this is that Shakerag won.

Mini

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2851 on: August 31, 2012, 02:54:46 am »

If you're wanting to work on the same code simultaneously you probably want to use something more like PiratePad, so you can actually see what the other person is doing since Pastebin doesn't (afaik) have anything like that.
Logged

ScriptWolf

  • Bay Watcher
  • You can't spell slaughter without laughter!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2852 on: September 02, 2012, 05:27:28 pm »

I'm going to start the process of learning C++ for Uni next year, tomorrow any tips ?

  I'm not sure on compilers ? I have a copy of visual studio 2010 ultimate will that be ok ?
« Last Edit: September 02, 2012, 07:03:53 pm by ScriptWolf »
Logged
He must be running 3.5 abacuses of RAM

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2853 on: September 02, 2012, 06:58:17 pm »

I'm going to start the process of learning C++ for Uni next year tomorrow, any tips ? Also I'm not sure on compilers ? I have a copy of visual studio 2010 ultimate will that be ok ?

It will work, although I am very anti-VS. IMO, you're best off with Code::Blocks or Eclipse, using MinGW.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2854 on: September 02, 2012, 09:06:09 pm »

I use and like Code::Blocks,
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2855 on: September 03, 2012, 01:49:57 am »

I'm going to start the process of learning C++ for Uni next year tomorrow, any tips ? Also I'm not sure on compilers ? I have a copy of visual studio 2010 ultimate will that be ok ?

It will work, although I am very anti-VS. IMO, you're best off with Code::Blocks or Eclipse, using MinGW.
Why the anti-VS-ness? xD

I don't remember why, but I moved from CodeBlocks to VC 2010, probably because I didn't know how to install libraries...

Code Blocks was nice, though.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2856 on: September 04, 2012, 05:32:42 am »

*double post to bump*

I have a problem in C++. I want to make a point on a grid go from (a,b) to (c,d) in a straight line. I know that I don't need to worry about the target changing. I want it to go a certain distance in a single frame.

D:

The way I thought of was getting the line's function by using the two coords to get the slope and the fixed point. It would look like this: y = (b-d)/(a-c) * (x - a) + b;
Then I was planning on incrementing x from a to d. The problem, I realized, is that this doesn't help with the last condition, that it goes a certain distance per frame.

...So, how would I do this, o great and genius programming masterminds of this thread?
The other way I thought of involved just brute-forcing and finding how much x do I need to add for the point to move the certain distance, but I suspect this isn't optimal.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2857 on: September 04, 2012, 05:40:10 am »

Make a vector of the correct angle with length dist-per-frame, then add that to (a,b) multiplied by the time.

So your current location is (a,b)+time*(dx,dy).
Time is a scalar (int, float, whatever), and time*(dx,dy) == (time*dx,time*dy)

To get (dx,dy), first make the entire vector (tx,ty):
tx = c-a
ty = d-b
Then normalise it (make it length 1, but keep the angle) by dividing it by its own length using pythagoras:
dx = tx / sqrt(tx^2+ty^2)
dy = ty / sqrt(tx^2+ty^2)

edit: optional: multiply dx and dy both with distance-per-frame to get a correct speed vector.
« Last Edit: September 04, 2012, 05:43:26 am by Siquo »
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2858 on: September 04, 2012, 06:17:00 am »

...These vector thingies, I must learn them. :s

I haven't quite gotten to the Geometry and Vectors part of my school's curriculum, which is probably 2 years from now.

I... think I understand. These vectors are nifty! :-0
Incidentally, is there an easy way to compute addition of vectors in a programming language? The first method, completing the triangle, seems to be a bit complicated to do. Maybe the second one could be done by just adding the vectors.. hrm.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2859 on: September 04, 2012, 07:35:09 am »

They can become tricky (there are two pages of disambiguation (sp?) on wikipedia for it, with about 50 entries each), but the basic rules are pretty easy, once you know them. Do not confuse them with the c++ std::vector, though.

A vector (x,y) is an arrow, defined as starting at (0,0) and ending at (x,y). Adding two vectors together is just putting the start of one arrow at the end of the other (http://hyperphysics.phy-astr.gsu.edu/hbase/vect.html, second image), and you get a "result" vector. Calculate like this: (3,4) + (1,2) = (3+1, 4+2) = (4,6).

Vectors, they are Super-effective!!1!
« Last Edit: September 04, 2012, 07:36:40 am by Siquo »
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2860 on: September 04, 2012, 08:22:54 am »

Read up on all the special things that can be done with dot products; those have all sorts of really handy uses when it comes to any sort of geometric manipulation involving vectors and angles. Dot products are really easy to find. If you have vectors A and B, A dot B = sum of Ai*Bi for all elements within the vector. So for 5, 8 and 9,3, the dot product = 45 + 24 = 69.

Then there is the really useful equation of:
cos(theta) = (A dot B) / (length of A * length of B), allowing you to find the angle between two vectors existing in any number of dimensions if you know their elements. theta = cosinverse([A dot B] / [length A / length B]); where length can be found by distance formulae (d = sqrt[vector element 0 squared + ... vector element last squared])
For the 5,8 and 9,3, that angle is the cos inverse of (69 / [sqrt 89 * sqrt 90]); or just under 40 degrees.
Thus if I were to give you a few positions in 10 dimensional space, you can then quickly and easily find the angle between them, despite having not the foggiest as to how to visually represent that. And that's just the tip of the iceberg as far as dot product uses go.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2861 on: September 04, 2012, 08:34:21 am »

Nooo...what's a dot product... @_@

I'm suddenly scared of programming D: I think I need to reconsider ...

Either that, or learn more math.
I really do want to work as one, but I ain't the slightest idea of what to do where. :/
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Blargityblarg

  • Bay Watcher
  • rolypolyrolypolyrolypoly
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2862 on: September 04, 2012, 08:36:57 am »

The dot product is one of the ways of multiplying vectors; it gives you a scalar as output (i.e. a regular number). If your two vectors are (a,b) and (c,d) then (a,b).(c,d) = a*c+b*d.

One important thing is that if the dot product of two vectors is zero, those vectors are orthogonal (i.e. perpendicular)
Logged
Blossom of orange
Shit, nothing rhymes with orange
Wait, haikus don't rhyme

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2863 on: September 04, 2012, 08:40:50 am »

Nooo...what's a dot product... @_@
A dot product is a math thing, not a programming thing. And if you read alway's post, you've already learned everything a dot product can do for you.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2864 on: September 04, 2012, 08:46:48 am »

Nooo...what's a dot product... @_@
Yeah, I refrained from even going there for fear of scaring you off ;)
You won't need dot products or 10-dimensional spaces for now. Adding, scalar-multiplying and normalising (reducing the length of the arrow until it has length 1, but keeping the angle intact) is all you need for what you want now.

However, in the future you'll encounter more of these puzzles, and knowing your vectors will help. But, you often only need to know generally how it works. I'm working with these 4D-tensors now and I'm all like Copy-Paste-Fuckdatshit and it works and I don't really need to know how it works internally, as long as it does the job.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))
Pages: 1 ... 189 190 [191] 192 193 ... 796