• What Do You Need Help With? V6
    7,544 replies, posted
So I'm learning C from computerscienceforeveryone.com, but I don't understand why the majority of the lessons so far (I'm at Unit 7, Course 1) have been all about binary. How important is binary in programming?
Trying to convert this to tail recursion: Original [CODE]public Comparable tailRecursion(ArrayList<? extends Comparable> itemArray) { int lastIdx = itemArray.size() - 1; Comparable lastItem = itemArray.remove(lastIdx); if (!itemArray.isEmpty()) lastItem = tailRecursion(itemArray); return lastItem;[/CODE] My version [CODE]public static Comparable tailRecursion(ArrayList<? extends Comparable> itemArray) { int lastIdx = itemArray.size() - 1; Comparable lastItem = itemArray.remove(lastIdx); if (!itemArray.isEmpty()) { lastItem = tailRecursion(itemArray); } return method(itemArray);[/CODE] How do I avoid crashing?
[QUOTE=blacksam;45211247]How do I avoid crashing?[/QUOTE] Stack overflow?
[QUOTE=cartman300;45211392]Stack overflow?[/QUOTE] Arrayindexoutofbounds -1 I'm probably over complicating this.
[QUOTE=blacksam;45211430]Arrayindexoutofbounds -1 I'm probably over complicating this.[/QUOTE] That exception will be thrown when you provide the initial method call with an empty ArrayList. Can't think of other circumstances.
Hey guys, here's a question from a friend of mine who's looking for a Java book. He knows C# and C and design patterns and all that jazz, and he is starting as an intern in a company who programs in Java. He is looking for a good Java book that isn't introductory, but covers most aspects of the language - not the tutorial kind of book, but more of a reference book. Any ideas? Thanks
If someone knows what could be wrong, I'm ready to explain the code. Also I tried rotating the cube by 90 degrees on its Z axis and it completely disappears. Also changing the fov on the projection view matrix doesn't solve the problem either. Any help would be greatly appreciated. I don't know people who know OGL so FP isy only hope.
[QUOTE=blacksam;45211247]Trying to convert this to tail recursion: Original <code> My version <code> How do I avoid crashing?[/QUOTE] I'm confused. What is this function supposed to do? To me it looks like it returns the first element in the arraylist and clears the arraylist. You are removing the last element until the arraylist is empty, at which point you return the last element that you removed (which is the first element in the original arraylist). And what is method in your version?
[QUOTE=KatNotDinner;45212256]If someone knows what could be wrong, I'm ready to explain the code. Also I tried rotating the cube by 90 degrees on its Z axis and it completely disappears. Also changing the fov on the projection view matrix doesn't solve the problem either. Any help would be greatly appreciated. I don't know people who know OGL so FP isy only hope.[/QUOTE] I have looked over the code and so far I can see a few issues, I don't usually program in C++, my experience is OpenGL and Java in this department but... In your render code you set the Model Matrix to Identity and then do the rotations, but you never set the position. [code] MM = IDENTITY_MATRIX; Translate(&MM, x, y, z) ; // Put the position of the model in world space in the matrix RotateY(&MM, Angle); RotateX(&MM, Angle); [/code] Then in your vertex shader you need to multiply vertexPosition_modelspace by the Model, view and projection matrices. [code] "void main(){\n" //"gl_Position.xyz = vertexPosition_modelspace;\n" //"gl_Position.w = 1.0;\n" "outcolor = (PM * VM * MM ) * input;\n" "gl_Position = (PM * VM * MM) * vertexPosition_modelspace;\n" "}\n" [/code] That's what I see at the moment, give that a try.
[QUOTE=blacksam;45211247]Trying to convert this to tail recursion: Original [CODE]public Comparable tailRecursion(ArrayList<? extends Comparable> itemArray) { int lastIdx = itemArray.size() - 1; Comparable lastItem = itemArray.remove(lastIdx); if (!itemArray.isEmpty()) lastItem = tailRecursion(itemArray); return lastItem;[/CODE] My version [CODE]public static Comparable tailRecursion(ArrayList<? extends Comparable> itemArray) { int lastIdx = itemArray.size() - 1; Comparable lastItem = itemArray.remove(lastIdx); if (!itemArray.isEmpty()) { lastItem = tailRecursion(itemArray); } return method(itemArray);[/CODE] How do I avoid crashing?[/QUOTE] Looks like the kind of thing you'll want to try the debugger for.
[QUOTE=Fantym420;45214159]I have looked over the code and so far I can see a few issues, I don't usually program in C++, my experience is OpenGL and Java in this department but... In your render code you set the Model Matrix to Identity and then do the rotations, but you never set the position. [code] MM = IDENTITY_MATRIX; Translate(&MM, x, y, z) ; // Put the position of the model in world space in the matrix RotateY(&MM, Angle); RotateX(&MM, Angle); [/code] Then in your vertex shader you need to multiply vertexPosition_modelspace by the Model, view and projection matrices. [code] "void main(){\n" //"gl_Position.xyz = vertexPosition_modelspace;\n" //"gl_Position.w = 1.0;\n" "outcolor = (PM * VM * MM ) * input;\n" "gl_Position = (PM * VM * MM) * vertexPosition_modelspace;\n" "}\n" [/code] That's what I see at the moment, give that a try.[/QUOTE] Thanks a lot, will do ASAP.
[IMG]http://i.gyazo.com/076858f3b9d87ac1caae7928a2ec7c57.gif[/IMG] the start of my platformer, has jumping and crouching. when you are crouched you move slower and you jump lower :D
I feel extremely stupid for not multiplying the position by the matricies. Anyways, doing that just results in a black screen and I'm not really sure what position should I render the cube in.
[QUOTE=KatNotDinner;45218766]I feel extremely stupid for not multiplying the position by the matricies. Anyways, doing that just results in a black screen and I'm not really sure what position should I render the cube in.[/QUOTE] Hmm, I'm looking over your code and it might be the View Matrix or Projection matrix values, i'm looking at them now. I'll let ya know what I find. EDITED: this You may want to increase your far plane, but this looks ok as far as I can tell. [code] MakePM(&PM, 60, 1.0f, 100.0f, (float)CUR_W/CUR_H); [/code] I found this about building a view matrix the variables in it are the camera and where it's pointing and what is the : At = point camera is looking at Eye = the camera position Up = camera up vector, (i.e. z up is 0,0,1); [code] zaxis = normal(At - Eye) xaxis = normal(cross(Up, zaxis)) yaxis = cross(zaxis, xaxis) xaxis.x yaxis.x zaxis.x 0 xaxis.y yaxis.y zaxis.y 0 xaxis.z yaxis.z zaxis.z 0 -dot(xaxis, eye) -dot(yaxis, eye) -dot(zaxis, eye) l [/code]you need to make a function to do this calculation and replace this line[code]Translate(&VM, 0, 0, -2);[/code]with the answer from the function, this is what you use to place a camera in the world to look at things.Also the source for the above calculation: [URL="http://stackoverflow.com/questions/349050/calculating-a-lookat-matrixHope"]http://stackoverflow.com/questions/349050/calculating-a-lookat-matrix [/URL] Hope this helps
Do you have any idea if there's a built in function to get the cross product? I already implemented normalization.
What's a good place to learn the basics of Java?
[del]hello again, i'm writing a deferred renderer in opengl and i'm having trouble with reconstructing view space fragment position from the hardware depth buffer. i feel that i could figure this out pretty easily if i stored the view space depth value in a gbuffer texture, but it feels wasteful to generate a hardware depth buffer and then create a duplicate just because i'm too lazy to convert it to view space. would anyone be kind enough to explain to me how i can use the raw, hardware depth buffer value for a given fragment and extrapolate from that depth value the view space position of a fragment for lighting purposes? (i'm already capable of READING the data, just not sure what to do with it!). thanks![/del] turns out the reason the usual algorithms werent working is because i wasn't converting my screen-space depth value to NDC before beginning reconstruction
[QUOTE=KatNotDinner;45220183]Do you have any idea if there's a built in function to get the cross product? I already implemented normalization.[/QUOTE] Not sure, but here's a java one(not built in) that I'm using: [code] public point3DF crossProduct(point3DF toCross) { return new point3DF( (y * toCross.z) - (toCross.y * z), (z * toCross.x) - (toCross.z * x), (x * toCross.y) - (toCross.x * y)); } [/code] That is from my 3d point class, the letters by them selves are the first vector(x,y,z), and the passed variable is the second(toCross.x, toCross.y, toCross.z). It then returns the result. I hope this isn't confusing, I'm not always good at explaining things.
-snip- i answered my own question, being as tired as i am i am experiencing memory loss and right now is not a good time to program :v:
[QUOTE=confinedUser;45227402]-snip- i answered my own question, being as tired as i am i am experiencing memory loss and right now is not a good time to program :v:[/QUOTE] Don't snip the question, answer it so we find the answer too :P
[QUOTE=Arxae;45227569]Don't snip the question, answer it so we find the answer too :P[/QUOTE] it was only a question about it being normal to struggle so hard on beginner programs such as asking a user to input a number and it outputting a Fibonacci sequence. i haven't slept in like a day so trying to program something like that is such a strain because i wouldn't know where to start with it. right now i feel like a complete dumbass :v:
[QUOTE=Fantym420;45225707]Not sure, but here's a java one(not built in) that I'm using: [code] public point3DF crossProduct(point3DF toCross) { return new point3DF( (y * toCross.z) - (toCross.y * z), (z * toCross.x) - (toCross.z * x), (x * toCross.y) - (toCross.x * y)); } [/code] That is from my 3d point class, the letters by them selves are the first vector(x,y,z), and the passed variable is the second(toCross.x, toCross.y, toCross.z). It then returns the result. I hope this isn't confusing, I'm not always good at explaining things.[/QUOTE] A lot simpler than I thought. Wikipedia led me to the formula: length(v1)*length(v2)*sin(angle); where angle is the angle between the 2 vectors. So I started venturing in order to find out how to find this angle and I was thrown even more discouraging formulas. Thanks Edit: Alright, updated code: [url]http://pastebin.com/Xvmffzyd[/url] Getting a backscreen now >.< .
[QUOTE=KatNotDinner;45227812]A lot simpler than I thought. Wikipedia led me to the formula: length(v1)*length(v2)*sin(angle); where angle is the angle between the 2 vectors. So I started venturing in order to find out how to find this angle and I was thrown even more discouraging formulas. Thanks Edit: Alright, updated code: [url]http://pastebin.com/Xvmffzyd[/url] Getting a backscreen now >.< .[/QUOTE] ok, so you are setting the place the camera is and the place it's looking to the same, and your MM is identity so the model will be at 0,0,0 with the camera, so you'll be in the model, set your look at more like this [code] // Looking At Camera Pos Top of camera(up) it's a direction so it should be a normal LookAt(&VM, Vector(0, 0, 0), Vector(20, 20, 20), Vector(0, 0, -1)); [/code] That should move your camera out side of the model and point it towards the origin 0,0,0 and set the -Z axis as up. After you get it working you'll need to set your MM to move and rotate the model around the world.
Thanks a lot, I'll report back with results when I can! Edit: I'm doing something horribly wrong. [img]http://i.imgur.com/7I30Uf4.png[/img] Updated Pastebin with new code
How do you quickly split a name in java? I have a sheet of first and last names. SamSmith JaneDoe JoseCuervo and I wonder if there's something like StringBuilder that would do this easily.
[QUOTE=KatNotDinner;45228642]Thanks a lot, I'll report back with results when I can! Edit: I'm doing something horribly wrong. [img]http://i.imgur.com/7I30Uf4.png[/img] Updated Pastebin with new code[/QUOTE] Well it's at least showing something, that's a plus. Have you tried checking your vertex information, I know on Android OpenGL ES 2.0 you pass in a large array of every vertex, which for a cube I think is 36 total vertices that get passed to OpenGL. Unless you are just doing a quad which is 6 total vertices. I'll give an example of how my code builds the vertices from my model info (.obj file) [code] v -0.500000 -0.500000 0.000000 v -0.500000 0.500000 0.000000 v 0.500000 0.500000 0.000000 v 0.500000 -0.500000 0.000000 vt 0.000000 1.000000 vt 0.000000 0.000000 vt 1.000000 0.000000 vt 1.000000 1.000000 f 4/1 3/2 2/3 f 1/4 4/1 2/3 [/code] v is vertex (x,y,z) vt is texture coordinates f is faces (triangles) first number is which vertex / second number is which texture point I read all the data above and build the final array using the face and vertex info, the texture info goes into another array, so face one (f 4/1 3/2 2/4) and face two(f 1/4 4/1 2/3) become (vertex order is the same as it's read in): [code] // NOTE: this is pseudo code just to show the output array[0] = { 0.5, -0.5, 0.0}; array[1] = { 0.5, 0.5, 0.0}; array[2] = {-0.5, 0.5, 0.0}; array[3] = {-0.5, -0.5, 0.0}; array[4] = { 0.5, -0.5, 0.0}; array[5] = {-0.5, 0.5, 0.0}; [/code] I'm running out of ideas without installing c++ and trying your code myself, and I'm not gonna go that far at the moment, I hope this'll help ya out a bit more. [editline]27th June 2014[/editline] [QUOTE=blacksam;45231772]How do you quickly split a name in java? I have a sheet of first and last names. SamSmith JaneDoe JoseCuervo and I wonder if there's something like StringBuilder that would do this easily.[/QUOTE] Do they all have capitals separating them? If they do you can iterate through the string looking for where the current letter is not equal to the current letter lower case. Not sure if there's build in function for it though.
I need some more help with processing. I'm using the external library G4P in conjunction with Processing to have buttons that don't take forever to code again and again. However, I'm trying to have buttons in a class in another file that the original file can access. Whenever I run it, I get this error: [code]You might want to add a method to handle GButton events syntax is public void handleButtonEvents(GButton button, GEvent event) { /* code */ } [/code] I'm not sure what is causing this error. Can someone help me figure out what it is? Main file [code]import g4p_controls.*; // Blicks main program // SDD Major Work // By ---------------- // Last Modified: 27/6/14 class Blicks { void Blicks() { } } void setup() { size(800,550, P2D); smooth(); Menu mainMenu = new Menu("MainMenu", this); } [/code] Menu class: [code] // Menu Class for Blicks // SDD Major Work // By --------- // Last Modified: 27/6/14 import g4p_controls.*; import processing.core.PApplet; public class Menu { PApplet pa; GButton button1, button2, button3, button4; Menu(String menuName, PApplet papp) { pa = papp; if(menuName.equals ("MainMenu")) { //draw mainmenu backgroundFileName = "MainMenuBackground.png"; button1 = new GButton(pa, 362, 166, 86, 48, "Play"); button2 = new GButton(pa, 362, 218, 86, 48, "Help"); button3 = new GButton(pa, 362, 276, 86, 48, "Credits"); button4 = new GButton(pa, 362, 402, 86, 48, "Quit"); } else if (menuName.equals ("GameSelect")) { //draw GameSelect backgroundFileName = "GameSelctBackground.png"; } else if (menuName.equals ("HelpScreen")) { //draw helpScreen backgroundFileName = "HelpScreen.png"; } else if (menuName.equals ("CreditsScreen")) { //draw CreditsScreen backgroundFileName = "HelpScreen.png"; } else if (menuName.equals ("Quit")) { //quit screen backgroundFileName = "Quit.png"; } else { //do nothing } menuBackground = loadImage(backgroundFileName); image(menuBackground, 0, 0); button1.addEventHandler(this, "myHandleButtonEvents"); button2.addEventHandler(this, "myHandleButtonEvents"); button3.addEventHandler(this, "myHandleButtonEvents"); button4.addEventHandler(this, "myHandleButtonEvents"); drawButton(); } void drawButton() { if(button1 != null) button1.draw(); if(button2 != null) button2.draw(); if(button3 != null) button3.draw(); if(button4 != null) button4.draw(); } public void myHandleButtonEvents(GButton button, GEvent event) { println("Hi"); } PImage menuBackground; String backgroundFileName; } [/code]
I'm new to the programming section. I've been programming C++ for a year now because of my study International Game Architecture and Design. I want to create an application that listens on a specific port, in such a way that I can extract the metadata from an audio stream (format won't be my worst problem currently). To be honest, I have no clue where to start. I'd assume that I'd start with some sort of socket-server that listens on a specific port, however, I've never done anything other than creating small games in C++ so far. There are existing applications that do something like this, but I can't get hold of the source code. I am a deejay myself and I know the struggle of people asking you what track you played. The current applications found on the internet are mostly twitter-bots that tweet the track you are currently playing. Since I know that most people don't want to clutter their twitter feed with tracks that 99 out of 100 people won't care about, I wanted to make a small system where people can make the metadata store locally in case there is no internet connection and push them to their own website / a pre-built website (that I'd develop) so they don't have to always have an internet connection to publish the played songs. Anyone here who has experience with extracting metadata from a stream and would be willing to help me get started with sockets etc? I don't mind using any language. I'm familiar with C++, C#, PHP (not really what I should go for), Lua and JavaScript (NodeJS).
Ok so for an assignment I need to take input for the amount of guests for a pizza party. For every 7 guests order 1 large pizza, for every 3 guests left over order 1 medium pizza and for every 1 guest left over order 1 small pizza. This is my attempt: [code]#include <iostream> #include <string> using namespace std; int main() { cout << "How many guests will be attending?: "; int guests; cin >> guests; int largePizzas = guests / 7; int remainder = guests % 7; int mediumPizzas = remainder / 3; cout << "Large pizzas: " << largePizzas << " Medium pizzas: " << mediumPizzas << " Small pizzas: " << remainder << endl; system("pause()"); return 0; }[/code] It works sometimes, but only for certain numbers of guests. I'm sure it has something to do with the remainder but I can't wrap my head around it. The solution is probably obvious but I just can't get it. Actually kinda embarrassed I can't get this basic arithmetic to work. Any help?
[code] int guests = 61; ... int remainder = guests % 7; // 5 int largePizzas = (guests - remainder) / 7; // 8 guests = remainder; int mediumPizzas = (remainder - (remainder % 3)) / 3; // 1 int smallPizzas = remainder % 3; [/code] [editline]28th June 2014[/editline] This makes me hungry. [editline]28th June 2014[/editline] [url]http://ideone.com/87lI1j[/url]
Sorry, you need to Log In to post a reply to this thread.