• What Do You Need Help With? V6
    7,544 replies, posted
Hey guys, I wanted to create some start a project to create something similar like an ambilight, but right now I'm trying to figure out how I could capture the current average screen brightness and push it out over a serial port. Anybody got a hint for me?
[QUOTE=Goz3rr;40254204]I don't fully understand your question, but it would be something along these lines: [code] public class MyClass { public String String1; public String String2; public int Int1; public MyClass(String String1, String String2, int Int1) { this.String1 = String1; this.String2 = String2; this.Int1 = Int1; } } public class Form1 { .. your other code .. private List<MyClass> _listOfThings = new List<MyClass>(); private void OnButtonClick() { _listOfThings.Add(new MyClass(_textBox1.Text, _textBox2.Text, _numericBox3.Value); } } [/code] [editline]12th April 2013[/editline] Or do you mean list as in form control, not the data type? If that's the case, make a listbox and then call this code on the button click: [code] _listBox1.Items.Add(String.Format("{0} {1} {2}",_textBox1.Text, _textBox2.Text, _numericBox3.Value)); [/code][/QUOTE] Yeah, I want some component on my form that acts like a list *Click button* *Add string with the variables* *Change textbox text* *Add (another) string with the variables to the next line of the list*
[QUOTE=JohanGS;40255917]Yeah, I want some component on my form that acts like a list *Click button* *Add string with the variables* *Change textbox text* *Add (another) string with the variables to the next line of the list*[/QUOTE] Then use a ListBox and the second code snippet i provided.
[QUOTE=pinecleandog;40254490]I'm not going to make a whole new thread for this, but is there anyone here that would be willing to mess around with unity with me, if they have spare time? I'm no programmer myself, I'm more into 3D modeling, "texture art" and level design. Although learning to program for unity would be fun to learn since I have some programming knowledge; just not that much.[/QUOTE] I think Gary was going to make a thread for Unity.
[QUOTE=Two-Bit;40258144]I think Gary was going to make a thread for Unity.[/QUOTE] Already has.
I need realistic armor penetration WW2 style. How would I approach that. And where can I find the formulas and equations I need for AP, APHE, HEAT, HESH,etc? I have one example here that I found: Round: E0, Weight, V0, RHA penetration, Stopping Power 9x19mm NATO has: 538J, 7.26g, 385m/s, 3mm, 17.8 12.7x99mm NATO has: 18214J, 46g, 890m/s, 15mm, 518.6 And one all-round formula of tank kinetic rounds (long rod): T * (1/cos@)^0.75 = (M/D^3) * (D/L)^0.3 *(v^2/U^2) T = plate thickness (cm) @ = angle u = constant L = penetrator length (cm) M = penetrator mass (g) D = penetrator diameter (cm) v = penetrator velocity (m/s) And the simpliest of course (kinetic energy)0,5 m*v^2 (how would that help with penetration or armor? Somelinks that might help you help me: [url]http://www.youtube.com/watch?v=wq5S8CrsUig&feature=player_embedded[/url] [url]http://www.battlefront.com/community/showthread.php?t=24792[/url] [url]http://www.combinedfleet.com/formula.htm[/url] [url]http://hsrlab.gatech.edu/AUTODYN/papers/paper156.pdf[/url] [url]http://wiki.worldoftanks.com/Battle_Mechanics#Penetration_Mechanics[/url] [url]http://www.navweaps.com/index_nathan/Penetration_index.htm[/url] I need more than this. Any other formulas (better or for other ammo or condition) tips, guides, theories, everything I missed etc. Cause I'm stuck after looking for 7-12 days. I can even pay you some if you do a great .PDF (10-30 USD) with much info in it. Also if anyone want's to help with the 2d prototype (Tech demo in SFML to visually do the ballistics) just PM me. I count on you!
I'm sure it's an obvious answer, but I'm having zero luck fixing this Visual Basic program. It's supposed to move a mole from a designated starting point move in one square increments either up, down, left, or right. He will either end up in the water (Which I designated as 2) and drown, or cross the bridges (3) and survive. Supposed to loop it 1000 times and show the results. I'm doing something wrong here, but I can't see what. I'm pretty sure it has something to do with the array though [code] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim space(,) As Integer = {{2, 2, 2, 2, 2, 2}, {2, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 2}, {2, 0, 0, 0, 0, 3}, {2, 0, 0, 0, 0, 2}, {2, 3, 2, 2, 2, 2}} Dim intdirection As Integer Dim rand As New Random Dim intx As Integer = 2 Dim inty As Integer = 3 Dim intmoledrowns As Integer = 0 Dim intmolelives As Integer = 0 Dim intcounter As Integer = 0 For intcounter = 0 To 1000 space(intx, inty) = 1 Do While space(intx, inty) = 1 intdirection = rand.Next(4) + 1 If intdirection = 1 Then 'Moves down one intx += 1 End If If intdirection = 2 Then 'Moves up one intx -= 1 End If If intdirection = 3 Then 'Moves right one inty += 1 End If If intdirection = 4 Then 'Moves left one inty -= 1 End If Loop If space(intx, inty) = 2 Then 'Mole drowns intmoledrowns += 1 End If If space(intx, inty) = 3 Then 'Mole escapes intmolelives += 1 End If intcounter += 1 Next MessageBox.Show("The mole survived " & intmolelives & " times and drowned " & intmoledrowns & " times.") End Sub End Class [/code] EDIT: I'm pretty sure I see how I messed up. There's no way for the statement to declare when the mole should end the loop. EDIT2: Actually I'm pretty sure I was fully retarded when I wrote this, it must have made sense in my head at the time. Any help would be appreciated. [editline]14th April 2013[/editline] Finally I think I got it! I wasn't randomizing the value each time a move was made. Disregard my question.
[QUOTE=177cheese;40269537] Finally I think I got it! I wasn't randomizing the value each time a move was made. Disregard my question.[/QUOTE] Never make a new random each time you need one, this usually ends up in the same numbers being generated. Just declare a random at the top of the class and use that every time.
I have some problems, i made my own StreamReader on C#, it makes map names and allowed peoples to build on it like this: [code] #main: notch;jeb_;somebody; #bridge: someone;jeb_;anotherone; #hell: herobrine;pigmen; [/code] I handly made this text file to test it, StreamReader reads it fine just i can't write someone's name next to list of a map, here are some stuffs i used for maps name: [code] player.Name.ToLower(); world.Name.ToLower(); [/code] And also i used a text file called allow.txt to read all stuffs. I also want to know how to remove someone's name from the list, like when i do /disallow <name> on current map, i don't want to remove someone from all of maps just i want to remove someone from a map.
I have problem when reading a pgm file binary. The problem appears with the comment lines that start with #. i also have to store height, width, max color value and actual picture in to a struct. Can you help me with the scanning and the storing please this is how my struct looks like [code] #define MAX 100 struct PGMstruct{ int width; int height; int maxColorVal; int pgmData[MAX][MAX]; }; [/code] and this is an example of a pgm file [code] P2 #type of pgm 9 #this is width 9 255 # height and max color value # picture 0 0 0 0 0 0 0 0 0 0 255 255 255 0 255 255 255 0 0 255 255 255 0 255 255 255 0 0 255 255 0 255 255 255 255 0 0 0 0 255 255 255 0 0 0 0 255 255 255 255 0 255 255 0 0 255 255 255 0 255 255 255 0 0 255 255 255 0 255 255 255 0 0 0 0 0 0 0 0 0 0 [/code]
Most people say that you should inherit from std::exception for a c++ exception class, so that you can catch them all polymorphically, but in my opinion that doesn't really make much sense because if you're creating an exception class it's because you're throwing more information than a simple string, so you would have to catch that exception by it's actual class anyway. Basically what i'm saying is that surely there is no point in even making a new class if all you're going to do is catch std::exceptions. You might as well just use one of the existing standard exceptions that take a string for what(). Is there something I am missing?
It can be useful to have a new exception class that behaves exactly like std::exception because you can catch it separately. But yeah, if you're only catching std::exception then there's no point.
I am having a problem with some basic opengl. I got some samples to work from open.gl and then tried refractoring it into some classes but I can't get the triangle to show on the screen. I boiled it down to only the necessary files. [url]https://dl.dropboxusercontent.com/u/28926055/Problem.rar[/url] Any tips ?
[QUOTE=Larikang;40280510]It can be useful to have a new exception class that behaves exactly like std::exception because you can catch it separately. But yeah, if you're only catching std::exception then there's no point.[/QUOTE] I've actually come round to inheriting from std::exception after thinking about it. For me it would be more like std::exception -> possibly my own base -> my exception. Even though I would obviously catch my own exceptions and so it's not important for me alone, if it was a library or something, as a last resort it is better to catch std::exception than to catch an unknown exception.
Just need some C++ help, mainly with a certain task. I need to create a file and fill it with data if the file it's creating is not found prior to creation. [cpp] if (!fltFile) { // Generate a file with regular data. cout << filnam.str() << " not found. " << filnam.str() << " has " << schedule[i].numSeats() << " seats.\n"; // 1A 1B 1C 1D // 2A 2B 2C 2D for (int j = 0; j < 5; j++) { for (int k = 0; k < schedule[i].numSeats() / 5; k++) { fltFile << j+1 << int2col(k+1) << " "; } // End FOR (COL) fltFile << endl; } // End FOR (ROW) } // End IF (Flight file existence)[/cpp] fltFile is an fstream object with ios_base::in and ios_base::out. I don't know how else to explain, "Check for file, if file's not there, create it and fill it with dummy data. Then read it afterwards."
What problem with it are you having?
[QUOTE=Agent766;40285810]What problem with it are you having?[/QUOTE] Well, the file isn't being created after testing whether or not it exists.
You should probably look [url=http://www.cplusplus.com/doc/tutorial/files/]here[/url]. If you create an ofstream and write to it, it'll create the file if it doesn't exist.
[QUOTE=Agent766;40285987]You should probably look [url=http://www.cplusplus.com/doc/tutorial/files/]here[/url]. If you create an ofstream and write to it, it'll create the file if it doesn't exist.[/QUOTE] So only an ofstream can make files, not fstream in general? Even when ios_base flags are set to in and out?
You can. It sounds like it'd be something like this: [code]fstream fltFile; fltFile.open("file.txt", ios::in | ios::out); if(!fltFile.is_open()) { fltFile << sampleData() << std::flush; fltFile.seekg(0); // When we continue, we'll need to read from the beginning } // fltFile is either read from disk or created with sample data[/code] Check this thread for more info: [url]http://www.cplusplus.com/forum/beginner/2211/[/url] I don't have a ton of experience with this and it's not tested, but it should be in the right direction.
[QUOTE=Philly c;40280987]I've actually come round to inheriting from std::exception after thinking about it. For me it would be more like std::exception -> possibly my own base -> my exception.[/QUOTE] Better to derive from one of std::exception's descendants: std::logic_error is for problems that the program could've avoided by checking a condition beforehand. These basically represent bugs in the program. (Example: you try to retrieve the next item from a queue, but the queue is empty. The program should've checked whether it was empty first.) std::runtime_error is for problems that [i]can't[/i] be checked beforehand. These aren't bugs, just situations that the program has to cope with. (Example: you try to write to a file but the disk is full.) Below those two general categories, there are some children that represent more specific types of errors, like std::invalid_argument (a type of logic error) and std::overflow_error (a runtime error). Sometimes it's enough to just throw one of these directly, but if you do need to create your own custom exception class, it's a good idea to derive it from the standard one that best represents the kind of problem your exception will be used for.
- Nevermind
[QUOTE=Agent766;40286439]You can. It sounds like it'd be something like this: [code]fstream fltFile; fltFile.open("file.txt", ios::in | ios::out); if(!fltFile.is_open()) { fltFile << sampleData() << std::flush; fltFile.seekg(0); // When we continue, we'll need to read from the beginning } // fltFile is either read from disk or created with sample data[/code] Check this thread for more info: [url]http://www.cplusplus.com/forum/beginner/2211/[/url] I don't have a ton of experience with this and it's not tested, but it should be in the right direction.[/QUOTE] Thanks for that thread, because the problem lied in ios_base::in and out on the same file which didn't work. And now it does.
Garry changed the code tags?
[QUOTE=quincy18;40280582]I am having a problem with some basic opengl. I got some samples to work from open.gl and then tried refractoring it into some classes but I can't get the triangle to show on the screen. I boiled it down to only the necessary files. [url]https://dl.dropboxusercontent.com/u/28926055/Problem.rar[/url] Any tips ?[/QUOTE] Still no luck on this, its driving me crazy anyone ?
Anyone here visualised Audio? I currently have 3 RGB leds and I cycle through the hue from 1 - 360 making a kinda rainbow and then I adjust the brightness of the LEDs based on the bass from the FFT data. I'd like to dynamically adjust the colour more dynamically and not really sure how to do this. What should I base it off? Frequency?
Found it. [code] glBufferData( GL_ARRAY_BUFFER, sizeof( m_Vertices ), m_Vertices, GL_STATIC_DRAW ); [/code] sizeof( m_Vertices ) was evaluated to 4 instead of 60 since it was the size of only the first element in the array instead of the whole array.
[QUOTE=quincy18;40292645]Found it. [code] glBufferData( GL_ARRAY_BUFFER, sizeof( m_Vertices ), m_Vertices, GL_STATIC_DRAW ); [/code] sizeof( m_Vertices ) was evaluated to 4 instead of 60 since it was the size of only the first element in the array instead of the whole array.[/QUOTE] It's actually the size of the pointer that's pointing to the array. sizeof(m_Vertices[0]) would evaluate to the size of a single array element.
[QUOTE=ThePuska;40292751]It's actually the size of the pointer that's pointing to the array. sizeof(m_Vertices[0]) would evaluate to the size of a single array element.[/QUOTE] Ahh oke thanks, wasn't really sure which one it returned.
[cpp]public class binarysearch { public static void printValues(int low, int high, int mid){ System.out.print("Low: " + low + "\n Mid: " + mid + "\n High: " + high + "\n"); } public static void main(String[] args) { int elements[] = {10, 11, 12, 16, 20, 25, 32, 36, 40, 44, 50, 55, 64, 77, 81, 90}; int low = 0; int high = elements.length -1; int mid = 0; int target = 90; //Can be changed. The number we are looking for. int p = 0; int i = 0; System.out.println("Target is: " + target + "\n"); while(i == 0 && low <= high){ if(low > high){ p = -1; }else{ mid = (low + high) / 2; if(target == elements[mid]){ p = mid; System.out.println("Found target at index: " + p); i = 1; }else if(target < elements[mid]){ high = mid; p = mid; printValues(low,high,mid); }else if(target > elements[mid]){ low = mid; p = mid; printValues(low,high,mid); }else{ printValues(low,high,mid); } } } } }[/cpp] I've made this rather messy binary search algorithm. It works but if I want to search for 90, as in the last spot of the array it fails and falls into an endless loop. I've tried to fix it but I've ran out of ideas.
Sorry, you need to Log In to post a reply to this thread.