Anybody know where I can see an implementation of the adaptive arithmetic algorithm for encoding and decoding in Java?
<-- [IMG]http://www.facepunch.com/fp/ratings/box.png[/IMG]
[code]
public class OpenUp {
public static void main(String[] args) {
Running game = new Running();
game.runWindow();
}
}
[/code]
[code]*imports*
public class Running {
JTextArea output = new JTextArea();
JTextField input = new JTextField();
JPanel Container = new JPanel();
GridLayout layout = new GridLayout(2,1);
JFrame Window = new JFrame("Retail Simulator");
Random generator = new Random();
int gameSpeed = 5000;
int basePay = 10;
int employees = 10;
int mess = 0;
int money = 0;
int customers = generator.nextInt(49)+1;
int theives = generator.nextInt(2)/20;
int amountSpent = generator.nextInt(50)*customers;
public void runWindow() {
Container.add(output);
Container.add(input);
Window.setContentPane(Container);
Window.setLayout(layout);
Window.setSize(500,500);
Window.setVisible(true);
}
public void tickTock() {
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//makes stuff happen here.
game.amountSpent = generator.nextInt(50)*customers;
game.output.append(Integer.toString(amountSpent));
}
};
new Timer(gameSpeed, taskPerformer).start();
}
}
[/code]
Main class gets things kicking but the code in tickTock says "game cannot be resolved"
[QUOTE=ScottyWired;44690207]<-- [IMG]http://www.facepunch.com/fp/ratings/box.png[/IMG]
[code]
public class OpenUp {
public static void main(String[] args) {
Running game = new Running();
game.runWindow();
}
}
[/code]
[code]*imports*
public class Running {
JTextArea output = new JTextArea();
JTextField input = new JTextField();
JPanel Container = new JPanel();
GridLayout layout = new GridLayout(2,1);
JFrame Window = new JFrame("Retail Simulator");
Random generator = new Random();
int gameSpeed = 5000;
int basePay = 10;
int employees = 10;
int mess = 0;
int money = 0;
int customers = generator.nextInt(49)+1;
int theives = generator.nextInt(2)/20;
int amountSpent = generator.nextInt(50)*customers;
public void runWindow() {
Container.add(output);
Container.add(input);
Window.setContentPane(Container);
Window.setLayout(layout);
Window.setSize(500,500);
Window.setVisible(true);
}
public void tickTock() {
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//makes stuff happen here.
game.amountSpent = generator.nextInt(50)*customers;
game.output.append(Integer.toString(amountSpent));
}
};
new Timer(gameSpeed, taskPerformer).start();
}
}
[/code]
Main class gets things kicking but the code in tickTock says "game cannot be resolved"[/QUOTE]
Your [I]game[/I] variable only exists in [I]OpenUp.main[/I], so the instance can't be addressed that way from itself.
Use [I]this[/I] instead.
[editline]1st May 2014[/editline]
Actually, don't. That would address the derived [I]ActionListener[/I].
I assume that the 'game' that you want is the current instance of Running? If that's the case, since the anonymous class (the ActionListener) is inside of Running you can just access amountSpent and output directly (remove the 'game.').
If you are unsure about where the variables are coming from, or if you have local variables that are shadowing the outside instance variables, you can use Running.this to access them: For example, Running.this.amountSpent = ...;
You can just access the fields by name without additional identifier, since the outer class's members are visible in the inner one.
Something to note here is that when you keep a reference to an instance inner class instance [sic], the outer class instance will also always be kept alive.
What is the algorithm for sorting the points of a triangle in CCW? My triangle rendering method doesn't work with my current sorting method.
[QUOTE=Pat.Lithium;44691121]What is the algorithm for sorting the points of a triangle in CCW? My triangle rendering method doesn't work with my current sorting method.[/QUOTE]
[url]https://en.wikipedia.org/wiki/Back-face_culling[/url]
Basically you take the dot product of the normal of the triangle with the position of the triangle relative to the camera, and if it's less than zero then you keep the triangle, otherwise discard it.
CCW matters because the cross product is not commutative.
I'm trying to get this gawsh darn thing to work, but IDK what is going wrong. I feel like the delimiter is skipping 44 because it doesn't have a + or -... Help?
[CODE]
package io;
import java.util.*;
import java.io.*;
public class PhoneNums {
public static ArrayList<String> readPhoneNumbers() {
String filename = "data/phone.txt";
ArrayList<String> output = new ArrayList<String>();
try {
Scanner input = new Scanner ( new FileReader(filename) );
while (input.hasNext()) {
input.useDelimiter("[+-]");
int countryCode = input.nextInt();
String areaCode = input.next();
String phoneNumber = input.next();
System.out.println("Country Code: " + countryCode);
System.out.println("Area Code: " + areaCode);
if(phoneNumber.length() < 5){
System.out.println("Phone Number: " + phoneNumber + input.next());
}else {
System.out.println("Phone Number: " + phoneNumber);
}
//System.out.println(input.nextLine()); // Comment this line out
}
input.close();
} catch ( NoSuchElementException e){
System.out.println(e);
} catch (FileNotFoundException e) {
System.out.println(e);
}
return output;
}
}
[/CODE]
[b]Textfile I'm trying to organized:[/b]
+1-555-555-5555
+1-800-555-1212
+61-3-9527-9527
44-1289-555555
[b]Expected Output:[/b]
Country Code: 1
Area Code: 555
Phone Number: 5555555
Country Code: 1
Area Code: 800
Phone Number: 5551212
Country Code: 61
Area Code: 3
Phone Number: 95279527
Country Code: 44
Area Code: 1289
Phone Number: 555555
[b]Output I Get: [/b]
Country Code: 1
Area Code: 555
Phone Number: 5555555
Country Code: 1
Area Code: 800
Phone Number: 5551212
Country Code: 61
Area Code: 3
Phone Number: 95279527
44
java.util.NoSuchElementException
[QUOTE=ECrownofFire;44691235][url]https://en.wikipedia.org/wiki/Back-face_culling[/url]
Basically you take the dot product of the normal of the triangle with the position of the triangle relative to the camera, and if it's less than zero then you keep the triangle, otherwise discard it.
CCW matters because the cross product is not commutative.[/QUOTE]
I understand how to do back-face culling, but my sorting method doesn't work. I need an algorithm to sort 3 points in CCW order.
You can do it in 2d using something like (xb-xa)(yb+ya)+(xc-xb)(yc+yb) if the result is positive its clockwise, else its counter-clockwise. (You could also just use Atan2, its probably slower tho)
However for 3d sorting points CCW or CW without a point of reference is not easy, It all depends on what angle you look at the face whether their vertices are sorted CW or CCW.
I am not sure what your use-case is, but for convex meshes you could use a point inside of the mesh as reference, then just project the points on a 2d plane and use the method above.
For Concave meshes you could probably find some algorithm to generate multiple convex meshes out of a Concave one and then do the same thing.
thanks for the info, but I've realised at this point everything doesn't matter yet because I'm still completely lost on this whole 3D engine thing. I have 4 days to finish this assignment, I've just finished implementing zbuffering and I understand how to implement back-face culling, but as it stands I have have a program that will draw a 2D polygon that has some matrices set up for nothing.
I don't know where to begin.
matrices will transform your vertices into the space you defined by those matrices, by simply multiplying the vertex with the matrix.
So if you have rotated your matrix and apply it to all your vertices your mesh will be rotated.
Same for translation, scale and perspective...
I understand matrices and their implementation now. I think I'm just stuck on where to begin on this engine. I have the skeleton for it some what done, it's able to draw polygons (with z-buffering), my 2D clipping works (I think). I don't know what to go from here, I just want to have an empty scene with a cube in it that I can transform.
create an "object": 4 vertices for cube and it's triangles
give it a model matrix, a view/camera matrix and a projection(perspective or orthogonal) matrix.
per frame manipulate the matrices like you wish (move/rotate the view and/or the object ) and multiply the 3 matrices in the correct order.
then multiply the vertex with the final model-view-projection matrix and you have your final vertex positions to render.
EDIT: the view and projection matrices should not belong to the object, you usually need only one, not per object.
Man I need help with the LZW algorithm. Anybody mind adding me on Steam to give me a hand with it?
Does anyone know anything about uploading files and session expiration (POST)? I'm uploading files to MediaFire but if the session expires while it's uploading it will fail, large files always fail in this situation.
When it expires I would be denied access and get 403: Forbidden, I added a thread to check and renew the session token while it was uploading but now MediaFire returns the result -99 which means "Missing or invalid session token", as a new token is generated if it's expired. I'm not sure how I could change the session token while it's uploading, I'm writing to the request stream of an HttpWebRequest which is basically done in one method call. This is with C# by the way.
How can try my skills in programming? Is there any basic stuff "to-do" as beginner to check myself?
[QUOTE=Krizzu;44697528]How can try my skills in programming? Is there any basic stuff "to-do" as beginner to check myself?[/QUOTE]
Think of something to create, and try create it, although it depends how much of a beginner you are
[QUOTE=Krizzu;44697528]How can try my skills in programming? Is there any basic stuff "to-do" as beginner to check myself?[/QUOTE]
Start of with "Hello World" :D
Then I would go on with implementing data-structures, testing out all the language Features etc.
And maybe do some code-challenges like on [url]http://www.codewars.com/[/url]
[QUOTE=johnnyaka;44697567]
And maybe do some code-challenges like on [url]http://www.codewars.com/[/url][/QUOTE]
That's what I'm looking for. Any sites for C#?
[QUOTE=Krizzu;44697586]That's what I'm looking for. Any sites for C#?[/QUOTE]
If you want to do some heavy math algorithms, check [url]http://projecteuler.net/[/url]
For relaxing challenges, you could look at [url]http://codegolf.stackexchange.com/[/url] or [url]http://programmingpraxis.com/contents/chron/[/url]
[editline]1st May 2014[/editline]
And maybe [url]http://codekata.com/[/url]
[QUOTE=Josh707;44696371]Does anyone know anything about uploading files and session expiration (POST)? I'm uploading files to MediaFire but if the session expires while it's uploading it will fail, large files always fail in this situation.
When it expires I would be denied access and get 403: Forbidden, I added a thread to check and renew the session token while it was uploading but now MediaFire returns the result -99 which means "Missing or invalid session token", as a new token is generated if it's expired. I'm not sure how I could change the session token while it's uploading, I'm writing to the request stream of an HttpWebRequest which is basically done in one method call. This is with C# by the way.[/QUOTE]
Are you sure you can't keep the current token active by just polling some other data from the server with it?
[QUOTE=Tamschi;44697721]Are you sure you can't keep the current token active by just polling some other data from the server with it?[/QUOTE]
There's an API function called 'renew session token' which [I]should[/I] do exactly that. The description being: "Extends the life of the session token by another 10 minutes. If the session token is <5 minutes old, then it does not get renewed and the same token is returned. If the token is >5 minutes old, then, depending on the application configuration, the token gets extended or a new token is generated and returned."
I'm currently using that but it is returning a new key rather than extending. When adding/modifying an application in MediaFire the only option is to change the name, going through every possible option/API function I haven't found a single other instance of the phrase 'application configuration' or extending the session.
See [url]www.mediafire.com/developers/[/url] if you want to check it out.
[QUOTE=Krizzu;44697528]How can try my skills in programming? Is there any basic stuff "to-do" as beginner to check myself?[/QUOTE]
Just to add to what others have said check out [url]https://github.com/karan/Projects[/url], it has a some simple/complex projects you can do.
The Ciphers in the text section were certainly fun to do.
I'm trying to expand my knowledge of programming languages, so I'm moving from Java to Ruby and learning Ruby on Rails through a coursera course . I'm also taking Java II this summer at my university as it's required and I want to get it out of the way so I can take the next class.
What advantages will I see with Ruby over Java? I've been playing with Ruby using "learn ruby the hard way" and so far, the whole object oriented style is making me really happy. I just want to know that I'm not screwing myself over by learning Ruby.
Well I suppose you merely need to ask yourself: "Why?"
My university also requires me to learn Java. However I am learning C++ on the side for a very dedicated purpose: to further [I]Empiresmod[/I] as it does need dev help. I have a very specific purpose for learning this language and that purpose is going to give me a motive.
What do you want to do with Ruby? Is it something that's going to benefit you later? Do you see yourself using it later? Don't mindlessly "expand your knowledge of languages", because without a purpose or vision, you'll not learn nearly as well as you could.
[QUOTE=Shadow187(FP);44699543]Well I suppose you merely need to ask yourself: "Why?"
My university also requires me to learn Java. However I am learning C++ on the side for a very dedicated purpose: to further [I]Empiresmod[/I] as it does need dev help. I have a very specific purpose for learning this language and that purpose is going to give me a motive.
What do you want to do with Ruby? Is it something that's going to benefit you later? Do you see yourself using it later? Don't mindlessly "expand your knowledge of languages", because without a purpose or vision, you'll not learn nearly as well as you could.[/QUOTE]
Well, I figured I'd see what all the fuss is about, plus the web apps for Rails looks pretty neat!
I understand it's possible to go without any prior Ruby knowledge for Rails.
Really don't know where I'm going with anything in programming, I really just like to learn. Technically, I'm a computer science major, but I don't [I]feel[/I] like one because I feel like I'm not getting enough out of my college education.
In the words of Snoop," If you stop at general math, you're only going to make general math money."
I'm in the exact same boat as you. My final for Software I (aka Java I) covered recursion, instance/static methods, and few other things worth mentioning. You know what I did? I stared doing my friends' C++ homework for fun to learn the language.
Try to find yourself a group of likeminded individuals. A friend and I went to a Github convention because we're going to be making apps for Android over the Summer together. Do something [I]extra[/I] in our field and you'll feel satisfied. As for myself, I'm making my own custom 2048 and a solver for it.
Do whatever makes you happy. But [B]set yourself a goal.[/B] Don't just blindly "learn ruby", you want to set a goal like "[I]I want to learn Ruby so I can do [B]this."[/B][/I], 'this' being some cool design/project.
[QUOTE=Josh707;44699383]There's an API function called 'renew session token' which [I]should[/I] do exactly that. The description being: "Extends the life of the session token by another 10 minutes. If the session token is <5 minutes old, then it does not get renewed and the same token is returned. If the token is >5 minutes old, then, depending on the application configuration, the token gets extended or a new token is generated and returned."
I'm currently using that but it is returning a new key rather than extending. When adding/modifying an application in MediaFire the only option is to change the name, going through every possible option/API function I haven't found a single other instance of the phrase 'application configuration' or extending the session.
See [url]www.mediafire.com/developers/[/url] if you want to check it out.[/QUOTE]
You could try the other token version, maybe it behaves differently.
I tried to compile my c++ program in VS 2013 and got 610 errors about 'x' is not a member of "global namespace" file cmath
'x' being different function names.
looks like this :
[img]http://i.imgur.com/a7zpXl9.png[/img]
[QUOTE=Pat.Lithium;44702124]I tried to compile my c++ program in VS 2013 and got 610 errors about 'x' is not a member of "global namespace" file cmath
'x' being different function names.
looks like this :
[img]http://i.imgur.com/a7zpXl9.png[/img][/QUOTE]
What does your code look like?
Sorry, you need to Log In to post a reply to this thread.