Programming, Coding, etc

Discussion in 'Science and Technology' started by Mr Silver, Oct 21, 2012.

  1. Mr Silver

    Mr Silver Commodore Newbie

    Joined:
    Jun 1, 2010
    Location:
    UK
    Maybe I'm the most computer illiterate person in the world, despite the computer things I am good at, but I really struggle to grasp the principles of computer programming.

    I've made attempts, every now and then, to try and learn about things such as Java, C++, PHP, etc, but I've always come away feeling that I haven't really learned anything, and not understanding what the fuck is so crucial about learning how to create a button graphic that creates a popup when clicked. This is stuff computers do anyway, it's not anything "new", nor have I learned anything about computer programming from it.

    Perhaps I'm in the wrong media, the stuff that fascinates me is how one would program a 3D model (as an example) to make specific actions, such as movement, palette swaps, those kinds of things. Hell, I actually struggle to understand how a 3D image is programmed into a computer in the first place. Sure, I can reason it with intuition, graphic frames, textures and colour, but how exactly is this translated into code? Surely a computer doesn't just "magic up" things like video games and the Internet, based upon long strands of numbers?

    It's really frustrating stuff, I'm determined to try and learn it (for the sake of having it as a useful skill), but I'm failing to do so on my own.
     
  2. sojourner

    sojourner Admiral In Memoriam

    Joined:
    Sep 4, 2008
    Location:
    Just around the bend.
    You don't write programs to do 3d. You need to get into 3d modelling. Checkout Blender.org (free) or maybe start with something easy like Sketchup (also free) to learn about 3d modelling and animation.
     
  3. Lindley

    Lindley Moderator with a Soul Premium Member

    Joined:
    Nov 30, 2001
    Location:
    Bonney Lake, WA
    It's also not necessary to learn GUI programming (buttons and windows) right off. The core of computer programming has nothing to do with all that; graphics and interfaces are just a layer on top of the real logic.

    In a sense, it does. Everything in a computer program is either instructions or data, and both are represented by strings of 1s and 0s on some level. The key is abstraction: bits are abstracted into integers, strings, and other primitive values; primitives are abstracted into objects; objects are manipulated by functions; and function calls are linked together to do useful work.

    Programmers rarely need to view instructions as 1s and 0s; that's what programming languages are designed to abstract. It's more common to view data that way, but even that can often be simplified into a more intuitive representation by 3rd-party libraries. For instance, libpng handles the details of decoding bits of a .png file into a representation that is easier for the program to work with.
     
  4. Mr Silver

    Mr Silver Commodore Newbie

    Joined:
    Jun 1, 2010
    Location:
    UK
    I do dabble in 3D modelling occasionally. I found Blender to have the most potential, but I am at a loss to understand how it works, beyond making a couple of 3D shapes, here and there.

    How does one program an application to have the abilities for a user to model 3D objects though? That's what I'm trying, unsuccessfully to comprehend.

    It seems to be the norm, in every place I've looked. I'm more curious about systems that are employed in interactive media and how systems, like say the auto-correct function (with it's suggested words) on a word processor works.

    So if I understand this correctly, you take a piece of "complex" data like a movie, for example. With that movie you strip down the elements that make it a movie, frames, audio, etc, and then you compress each part of these elements (I assume bits equals data?) into integers, strings, etc?

    How does that work on the other side though? How does one know what the end product will be from just a load of random strings of numbers?
     
  5. gturner

    gturner Admiral

    Joined:
    Nov 9, 2005
    Location:
    Kentucky
    What you're working with (3D graphics) is both simple and complicated, which is why computers were around for a very, very long time before people had hammered out workable and efficient 3-D graphics routines.

    Even 2-D is complicated, once you dig into developing data structures that can support shapes, and then scale, rotate, and translate those shapes, and convert the result to pixels. Add 2-D textures and fills and you've got a lot on your table. Doing it in 3-D, and then in real-time in 3-D, is not a simple thing to understand (lots and lots of array operations, shortcuts, and opaque but very clever math and programming tricks).

    So don't despair! It takes a lot of time on task and a whole lot of playing around to proficiently use someone else's library of routines. To actually understand them (beyond the level of "this routine does that" is almost as hard as writing and debugging them in the first place, and if you'd done that a couple decades ago, you might be running your own space launch company from the profits by now.

    But since graphics, solid modeling, and other complex applications are so, so useful, great effort has gone into making them user friendly, even at the programming level. I'm sure some here can recommend some of the better packages, development kits, and whatnot, but it will take quite a lot of time to get used to them, simply due to the inherent complexity it takes to describe and manipulate such objects.
     
  6. Lindley

    Lindley Moderator with a Soul Premium Member

    Joined:
    Nov 30, 2001
    Location:
    Bonney Lake, WA
    That is a matter of algorithms, which are more abstract than programming. A given algorithm can be implemented in any programming language. However, you will have an easier time comprehending algorithms if you know the basics of at least one language so you can mentally map the algorithm to specific commands.

    Each movie format is well-defined. The first n bits are a frame, the next n bits are audio, etc. The formats can be quite complex, but as long as they are well-defined, you can encode and decode movie files. Usually there is a library to help you out.
     
  7. sojourner

    sojourner Admiral In Memoriam

    Joined:
    Sep 4, 2008
    Location:
    Just around the bend.
    What are you trying to achieve by this? Are you going to try to write your on 3d software like Blender? You know something that sophisticated takes huge amounts of man hours by very talented programmers?
     
  8. Ayelbourne

    Ayelbourne Fleet Captain Fleet Captain

    Joined:
    Apr 25, 2005
    Pretty much how you would do it yourself. Programming is all about teaching the computer a routine that makes it do what you would do, only extremely faster.
    In your example it's just a matter of getting the computer to compare a string of characters entered by the user with other strings of characters stored in some internal thesaurus. Those that are the most similar (i.e. those that have the largest amount of matching characters and matching positions of said characters) are then returned.
     
  9. Lindley

    Lindley Moderator with a Soul Premium Member

    Joined:
    Nov 30, 2001
    Location:
    Bonney Lake, WA
    Technically, I believe it is called the minimum edit distance algorithm.
     
  10. Psion

    Psion Rear Admiral Rear Admiral

    Joined:
    Oct 19, 2001
    Location:
    Lat: 40.1630936 Lon: -75.1183777
    I think that you're coming at this from the wrong direction if you're picking a language first and then trying to figure out how to use it to make models of objects. Assuming you're not looking to use Blender or Sketchup or Wings3D, but rather to figure out how to write a similar program, you should first attempt to study the math and the algorithms -- as Lindley mentions -- behind such a subject.

    For example, consider a simple, two-dimensional box. It has four sides, but more importantly, it has four corners, and most algorithms concern themselves with tracking the motion of those corners through space using something like the Cartesian coordinate system.

    Get out a piece of graph paper and try to follow along using pencil and paper. In high school, you were probably taught that most graphs put their origin -- the starting point where the x and y values are zero -- at the lower left corner, and increasing positive values of x go to the right and increasing positive values of y go up. This is good enough for our purposes, but you should remember that on a computer screen, one usually maps the origin to the upper left corner and increasing positive values of y go down.

    So the box is defined as having four corners at the following locations (for example): (0,0), (0,5), (5,5), and (5,0). This is your data defining a square box having a length of five units on each side. Your algorithm assumes that you draw a line from the first coordinate to the second, second to third, third to fourth, and fourth to first. Try this with pencil and graph paper and you've just essentially emulated the way a computer would draw a box on the screen.

    An offset can then be applied to the box (transforming or moving it in space) by adding the offset to each corner's coordinates. Give your box an offset of (6,8) ... that is, add six to each x value of the box's corners and eight to each y value; like this (x+6,y+8). If you've used the same sheet of graph paper, you should now have a second box, identical in shape to the first, above and to the right of the first.

    Now one thing a computer is good at is doing the same thing over and over, very quickly. Put aside the pencil for a moment and just imagine the computer counting from one to one hundred very quickly. Each time it increments, lets imagine it uses the current count as the x value of the offset. That is, let's assume the box's corners are offset by (count,0) every time the counter goes up by one. So the coordinates for each corner will look something like (x+count,y+0). If you also assume the computer erases the previous box before it draws a new one, you can probably imagine the result you'll get ... a box sliding quickly across the screen to the right until it gets to the end of the count. And then it stops.

    Yet another transformation you can apply to each coordinate is a rotation. The math here gets a little more thick, and it's been over thirty years since I've done this stuff, so forgive me if there are some trig errors. Let's assume you want to rotate your box through a complete, 360 degree circle. This time, you'll want to count from 0 to 359 and you'll want to transform each corner's x and y values by x*sine(count*0.01745329) and y*cosine(count*0.01745329). For fun, don't forget to keep an offset to relocate your box, so the actual value for each corner would be (x*sin(count*0.01745329)+offsetx,y*cos(count*0.01745329)+offsety). Animate the offsetx and offsety values by having them change by some value each time the box is redrawn and you'll have a spinning box sliding across the screen.

    Now implementing the above on a computer and disposing of the graph paper is what you'll use a computer language for. I used BASIC and Z80 assembly language the first few times I tried to tackle these subjects. The results were impressive only for the time. But they are fundamental to understanding what is going on whenever your see a box on your screen ... like a "Submit Reply" button on an HTML page. Somewhere deep down, buried in a library no programmer has probably touched in years, is a call that adds an offset to that box so that it's positioned correctly on your screen.

    I highly recommend getting hold of old, old issues of Byte Magazine or Creative Computing just to see how this stuff used to be done. Here's a PDF version of the February, 1982 issue of Byte (careful, it's a long download) that goes into a simple introduction of computer graphics. Specifically, I draw your attention to "A Graphics Primer" on page 448 and "Interactive 3-D Graphics for the Apple II". The computer systems described and languages used may be long dead, but the principles described are still an active part of graphics today.
     
  11. Lindley

    Lindley Moderator with a Soul Premium Member

    Joined:
    Nov 30, 2001
    Location:
    Bonney Lake, WA
    To put this in the simplest terms: if you want to learn programming, you need to be familiar with variables, loops, conditionals, functions, and some basic IO. You can choose one of many directions to proceed from there, but those are the basic building blocks that you must understand fluently.
     
  12. Psion

    Psion Rear Admiral Rear Admiral

    Joined:
    Oct 19, 2001
    Location:
    Lat: 40.1630936 Lon: -75.1183777
    No, Lindley. If you want to learn programming, you do not need to be familiar with variables, loops, etc. You will learn those concepts as you learn to program. And having a specific, simple task is a great incentive to stick with the learning process as you encounter concepts like those you list.

    At the end of that process, assuming he's stuck it out, Mr. Silver will have a fluent understanding of the basics of programming.
     
  13. Mr Silver

    Mr Silver Commodore Newbie

    Joined:
    Jun 1, 2010
    Location:
    UK
    Thanks to everybody who has posted in this thread. I think my problem is more a frustration of wanting to do more with computers, rather than just using the Internet, Word Processors, and occasionally mucking around on photoshop.

    I think programming, is something that I may just have to accept defeat on, for now. I've got myself Blender though, and I'm really intruiged at the possibilities it offers. It's not particularly intuitive, but I've managed to grasp things such as moving shapes, adjusting viewpoints and switching modes fairly quickly.

    This may be a "trying to run before you can walk" thing, but I'm interested in using Blender to create 3D character models. The sculpting tool is all a bit puzzling though, I've seen some videos where people manage to sculpt out a head shape, from the UV sphere mesh, quite quickly. Is there a particular method of doing this?
     
  14. Robert Maxwell

    Robert Maxwell memelord Premium Member

    Joined:
    Jun 12, 2001
    Location:
    space
    Yeah. Everybody learns in their own way, but having a specific problem you want to solve will help you figure out what you need to learn in order to solve it.

    I would recommend the OP break down what he wants to do into little pieces that can be achieved individually.

    Mr Silver, not to discourage you too much, but learning how to do the simple things is how you learn to program. You first learn simple things like taking input and creating output, building user interfaces, etc. and then you can move on to more complex things like graphics. But you can't start at 3D graphics and work your way back. 3D modeling, as the others have noted, is a completely separate skill that doesn't directly involve programming.

    So, you have to decide what it is you really want to do. If it's 3D modeling and animation, look into learning something like Blender. Just download and install it, start looking at some tutorials.

    If it's programming, decide what kind of programming problem(s) you need to solve, and then we can help you settle on a language that will let you solve those problems most efficiently. Different languages have different strengths so you can save yourself some trouble by picking the right language for the job.

    It sounds like you want to write your own 3D modeling program, and while that's admirable, it is not at all realistic as your first programming project. It may be a good goal to have for a final product, but you have to learn a lot to get there--it will probably take years.

    So, what is it you are actually trying to accomplish?
     
  15. Mr Silver

    Mr Silver Commodore Newbie

    Joined:
    Jun 1, 2010
    Location:
    UK
    I'm interested in both 3D modelling and programming. From my perception, those go hand in hand when it comes to adding 3D modelling into an interactive setting, such as animation or interactive media.

    I think it's prudent to focus on one, for now. In that regard, I've decided to learn something out of my comfort zone - Blender.

    From what I gather, people who have become competent with Blender, go onto to edit the script and tailor it to their specifications.
     
  16. sojourner

    sojourner Admiral In Memoriam

    Joined:
    Sep 4, 2008
    Location:
    Just around the bend.
    Better to ask this on the Blender forums.
     
  17. Robert Maxwell

    Robert Maxwell memelord Premium Member

    Joined:
    Jun 12, 2001
    Location:
    space
    Yeah, that's about right. I suggest you look around at the myriad Blender tutorials out there and see what happens. Like any skill, it is not something you should expect to become proficient with overnight. It will probably take you months to really get good at using it, with daily practice.
     
  18. Lindley

    Lindley Moderator with a Soul Premium Member

    Joined:
    Nov 30, 2001
    Location:
    Bonney Lake, WA
    While there is a relationship between scripting and coding, they are not really the same thing. Just FYI.

    One aspect of 3D modeling which requires significant coding and mathematical background (not just scripting) is the insertion of 3D models into real video, such as might be done for augmented reality apps or movie CGI.
     
  19. Lindley

    Lindley Moderator with a Soul Premium Member

    Joined:
    Nov 30, 2001
    Location:
    Bonney Lake, WA
    I don't disagree that having a goal helps. However, I've seen too many newbies who see a loop and stare at it helplessly, or can't figure out how to output a pyramid of *s. In my opinion, trying to do something complex before you wrap your head around such basic things is asking for frustration.
     
  20. gturner

    gturner Admiral

    Joined:
    Nov 9, 2005
    Location:
    Kentucky
    I really miss the old Byte magazine. Pretty much an entire generation of programmers learned their skills from its pages. In the mid 1980's I bought perhaps a hundred pounds worth of back issues at the Dayton hamfest, going back to the mid 1970's. :)