[QUOTE=Xion12;37813689]Works fine for me, what is in your a.txt file?[/QUOTE]
This is my a.txt file
[code]
1 2 1
2 2 1
[/code]
I decided to try storing into a linked list
[code]
#include <iostream>
#include <fstream>
using namespace std;
struct node
{
int row;
int col;
float value;
node *link;
}*p;
void main()
{
fstream a("a.txt", ifstream::in);
int i, j;
float k;
while(!a.eof())
{
a>>i;
a>>j;
a>>k;
node *matrix1;
matrix1=new node;
matrix1->row=i;
matrix1->col=j;
matrix1->value=k;
matrix1->link=p;
p=matrix1;
//cout<<i<<j<<k<<endl;
}
node *q;
for(q=p;q!=NULL;q=q->link)
{
cout<<q->row;
cout<<q->col;
cout<<q->value;
cout<<endl;
}
}
[/code]
The output is the same but its printing it out backwards now (which I think it should because thats how linked lists are stored). Its still printing the last line twice for some reason. UPDATE: Got it to work. Apparently you can't have empty spots beneath whats beneath whats in A otherwise it prints it out again.
How would you guys recommend storing this stuff into a linked list so I can multiply it by another matrix later. I'm still confused on how that works.
Someone hit me up with some good C++ and C# online tutorial sites or books, maybe even ones that require you to do some assignments.
Head First C#
[QUOTE=Xion12;37813294]How do I go about using OpenGL in C++? I need the libraries right? Where do I get them, and how would I set up a bare bones OpenGL program?[/QUOTE]
OpenGL should be included in your graphics drivers and to set up OpenGL, take a look at [url]http://open.gl[/url].
I am probably retarded and misunderstood something, but I was reading [URL="http://www.csharp-station.com/Tutorial/CSharp"]this[/URL] set of tutorials and got a question. When would I want to use struct over class in a program? And what it brings that class doesn't?
[QUOTE=kono_kun;37818777]I am probably retarded and misunderstood something, but I was reading [URL="http://www.csharp-station.com/Tutorial/CSharp"]this[/URL] set of tutorials and got a question. When would I want to use struct over class in a program? And what it brings that class doesn't?[/QUOTE]
Struct doesn't bring any feature, it actually prevents you from inheritance. The big difference is the way it's passed around.
If you pass in an object to a function, and it's a class, only the memory adress of the class will be passed in, making it faster in some cases, and enabling the function to modify the object. If it's a struct however, the whole contents of it is copied into the function, disabling the functions to modify the original copy. For some small data structures struct is actually faster. And the immutability of it is a good thing, trust me.
So I'm making Pong and I'm not sure what the best way for the GUI is.
I had it working but then I changed something and its just not working at all now.
I made it as an applet but want to make it in a window and all now
Okay, I really need help again, I've been trying to figure this out by myself for a few days at least, and just want to get back to work on the rest of my game.
Anyway, I'm having trouble creating a map from a text file. I can make the blocks appear, and most of them go to the right spot, but about half of them just appear in a new place.
There's supposed to be 3 lines of 5 blocks each, but it makes this:
[IMG]http://s12.postimage.org/mjator43f/problems.png[/IMG]
The red highlighted part is the blocks it creates, see how a chunk of them are moved?
The map file is just this:
[code]
OOOOO
OOOOO
OOOOO
XXXXX
XXXXX
[/code]
It reads the O's as blocks, and skips over the X's, that part works.
How I'm doing it is scan through the whole text file, add each position into a list. Position being which space it is in the text file.
Then I'm doing oPos[a] % 5 to find the position on the line, and to find the line I divide by 5 and round up.
My current code for doing that is:
[code]
line = Math.DivRem(oPos[a], lineCount, out linePos);
[/code]
I've tried doing both line and linePos separately but this produces the same results.
How do I fix this? D:
[QUOTE=AlienCat;37817641]OpenGL should be included in your graphics drivers and to set up OpenGL, take a look at [url]http://open.gl[/url].[/QUOTE]
Thanks, I didn't know about the graphics drivers thing. That link looks really helpful too.
So I am using java for college project (sadly) and I have this question, I am using SimpleMySQL library to connect to database, but I am struggling a little bit.
I have this piece of code that's required to connect to database.
[code] String user = "sample";
String pass4 = "sample";
String host = "sample";
SimpleMySQL mySQL;
mySQL = new SimpleMySQL();
mySQL.connect(host, user, pass4, "sample");[/code]
I need to make it so when user enters name it has to say if it exists in database or not. I have two problems:
1) When I click on button it freezes for about 5 seconds (guess it's making query) then shows result.
2) If I am having few buttons with different queries, how can I make the above code re-usable, so that I can specify query in brackets or so and it would execute it and how do I make it so when app is launched it connects to database (if that will make query any faster which I assume it will)
I'm stuck trying to correct the circle circle collision correction for my game. Somehow the absorption from one to another cell isn't working correct.
here is a video of the problem:
[vid]http://dl.dropbox.com/u/28034726/circle.webm[/vid]
It shouldn't overlap on collision, but i don't really know how to fix this problem.
Important flow is the following:
1. check if circles collide
[code]
public static boolean entityCollide(Entity e1, Entity e2) {
float dx,dy;
dx = e2.getX() - e1.getX();
dy = e2.getY() - e1.getY();
float radii = e1.getRadius() + e2.getRadius();
if ((dx * dx) + (dy * dy) < radii * radii) {
return true;
}
return false;
}[/code]
2. get intersection area (using [URL="http://mathworld.wolfram.com/Circle-CircleIntersection.html"]http://mathworld.wolfram.com/Circle-CircleIntersection.html[/URL])
[IMG]http://mathworld.wolfram.com/images/equations/Circle-CircleIntersection/Inline41.gif[/IMG]
3. add intersection area to bigger circle, substract intersection area from smaller circle
[code]
Aa = intersectionSurface(o, player);
Ao = Math.pow(o.radius,2) * Math.PI;
Ap = Math.pow(player.radius,2) * Math.PI;
if(o.radius > player.radius){
Ao += Aa;
Ap -= Aa;
}else{
Ao -= Aa;
Ap += Aa;
}[/code]
4. calculate new radii from the updated areas
[code]
o.radius = Math.sqrt(Ao / Math.PI);
player.radius = Math.sqrt(Ap / Math.PI);
[/code]
Anyone got any suggestions? I would really appreciate them :)
[QUOTE=MakeR;37807837][img]https://dl.dropbox.com/u/13368050/exprand.png[/img][/QUOTE]
Mind if I ask what equation you used to make this plot?
I'm EXTREMELY new to this so please bear with me
I got a project for my beginning C# class and I am having a hard time with public/private properties in classes.
could someone explain how I would go about setting the area = to length * width?
[code] private int length;
public int Length
{
get { return length; }
set { length = value; }
}
private int width;
public int Width
{
get { return width; }
set { width = value; }
}
private int area;
public int Area
{
get { return area; }
set { area = value; }
}[/code]
in the set blocks for length and width, add a second line that's just "area = length * width;"
You might have some issues with the Area setter since there's no way of obtaining width and length values to keep all the variables updated. Consider making it read only (by only keeping the get block)
I believe you don't need the set Area part of it, since it's supposed receive values from length and width.
[QUOTE=robmaister12;37828692]You might have some issues with the Area setter since there's no way of obtaining width and length values to keep all the variables updated. Consider making it read only (by only keeping the get block)[/QUOTE]
Simpler to just do the calculation in the get then.
[code]
public int Length { get; private set; }
public int Width { get; private set; }
public int Area
{
get { return Length * Width; }
}[/code]
[QUOTE=gparent;37828754]Simpler to just do the calculation in the get then.
[code]
public int Length { get; private set; }
public int Width { get; private set; }
public int Area
{
get { return Length * Width; }
}[/code][/QUOTE]
Depends on what you're doing (especially if you're using it in time-critical code). If you're retrieving the area value a lot and rarely setting it, it would be better to pre-calculate area in the setters, but if you're mainly working with length/width and occasionally use area then this is better.
Of course, most of the time you won't be working with time-critical code and it's more about style and readability than performance. In that case I would choose your method since it's cleaner and more concise.
[QUOTE=gparent;37828754]Simpler to just do the calculation in the get then.
[code]
public int Length { get; private set; }
public int Width { get; private set; }
public int Area
{
get { return Length * Width; }
}[/code][/QUOTE]
That worked beautifully thanks guys.
[QUOTE=robmaister12;37828854]Depends on what you're doing (especially if you're using it in time-critical code). If you're retrieving the area value a lot and rarely setting it, it would be better to pre-calculate area in the setters, but if you're mainly working with length/width and occasionally use area then this is better.
Of course, most of the time you won't be working with time-critical code and it's more about style and readability than performance. In that case I would choose your method since it's cleaner and more concise.[/QUOTE]
Basically until you profile, go with my way. No reason to optimize uselessly.
Hey guys, first time posting in this thread. First things first: Thanks to everyone that willingly gives their time to help!
So I come here seeking help. I have a project to do over the weekend and it is very difficult. My professor is not very great (not being critical, it is the general census among the students in the same class as me.) I am in a programming II class, learning C. I am really lost of the current project, and am looking for someone to help, tutor, give pointers, etc.. via PMs.
To clarify, I am NOT looking for answers, just help. I am very passionate about my major, and really want to learn vs. someone just giving me answers.
The assignment is quite difficult, and I think it would be a learning experience on both ends. The assignment is to create a 2-D Monte Carlo integration program. Virtual darts are thrown at a circle inside a rectangle, and we are supposed to calculate the area of the circle. If you're interested in helping / tutoring, PLEASE PM me. Any help is greatly appreciated.
[QUOTE=ief014;37827952]Mind if I ask what equation you used to make this plot?[/QUOTE]
I used the equation that ThePuska posted.
To get the graph I ran the equation with 'a' going from 1 to 10 many times each and worked out the percentage that was >= 0.5
So I got this piece of code:
[cpp]new Vector2((float)Math.Round((double)mouseState.X / 50) * 50, (float)Math.Round((double)mouseState.Y / 50))[/cpp]
and, I want my mousepos to round to 50, so for an example, 34 would be 50, 12 would be 0, 63 would be 50, and 80 would be 100.
How do I achieve this? This piece of code doesn't work.
Works for me.
[code]
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print ( math.floor(27.0/50 + 0.5) * 50 )
50
> print ( math.floor(25.0/50 + 0.5) * 50 )
50
> print ( math.floor(24.0/50 + 0.5) * 50 )
0
> print ( math.floor(75.0/50 + 0.5) * 50 )
100
> print ( math.floor(74.0/50 + 0.5) * 50 )
50
[/code]
(Adding 0.5 to the argument in math.floor is pretty much a math.round function)
[editline]28th September 2012[/editline]
You're missing a '* 50' in the Y parameter.
Haha, thank you so much, I only forgot the * 50, indeed.
I've made a screenshot uploader called Superscrot. I use it all the time; I only work on it occasionally. But I'm encountering an (URL) encoding problem that I can't figure out.
When you take a screenshot of a window, it puts the window title in the filename. However, Spotify likes to use the en-dash "–" (U+2013) to separate the artist and track name. This is causing problems.
- Files are uploaded with that filename as-is, without any encoding. I could probably avoid any problems by simply replacing invalid characters with - or _, but I'd like to do this correctly.
- I have a "screenshot overview" page on my server, where I'm using [url=http://php.net/manual/en/function.rawurlencode.php]rawurlencode[/url], which has shown to be the only encode function that properly works. It encodes the en-dash to "%96". I don't know how it got to %96, but that seems to work.
- System.Uri.EscapeUriString, however, encodes the dash as "%E2%80%93". Simply not encoding it at all doesn't work either. In both cases, the server returns a 404 error if I request an image like that.
URL without encoding: [url]http://s.horsedrowner.net/NANO/Window/201209281908041874-Spotify - Justice – Genesis.png[/url] (201209281908041874-Spotify - Justice – Genesis.png)
URL with EscapeUriString: [url]http://s.horsedrowner.net/NANO/Window/201209281908041874-Spotify%20-%20Justice%20%E2%80%93%20Genesis.png[/url] (201209281908041874-Spotify%20-%20Justice%20%E2%80%93%20Genesis.png)
URL with rawurlencode: [url]http://s.horsedrowner.net/NANO/Window/201209281908041874-Spotify%20-%20Justice%20%96%20Genesis.png[/url] (201209281908041874-Spotify%20-%20Justice%20%96%20Genesis.png)
Now, my questions is, how do I encode the URL properly in both C# and PHP?
My server is running nginx 1.2.3 with php 5.4 (yes, PHP, I know), and my server's locale is set to en_US.UTF-8.
[--snip--]
[QUOTE=mkp;37824429]I'm stuck trying to correct the circle circle collision correction for my game. Somehow the absorption from one to another cell isn't working correct.
here is a video of the problem:
[vid]http://dl.dropbox.com/u/28034726/circle.webm[/vid]
It shouldn't overlap on collision, but i don't really know how to fix this problem.
Important flow is the following:
1. check if circles collide
[code]
public static boolean entityCollide(Entity e1, Entity e2) {
float dx,dy;
dx = e2.getX() - e1.getX();
dy = e2.getY() - e1.getY();
float radii = e1.getRadius() + e2.getRadius();
if ((dx * dx) + (dy * dy) < radii * radii) {
return true;
}
return false;
}[/code]
2. get intersection area (using [URL="http://mathworld.wolfram.com/Circle-CircleIntersection.html"]http://mathworld.wolfram.com/Circle-CircleIntersection.html[/URL])
[IMG]http://mathworld.wolfram.com/images/equations/Circle-CircleIntersection/Inline41.gif[/IMG]
3. add intersection area to bigger circle, substract intersection area from smaller circle
[code]
Aa = intersectionSurface(o, player);
Ao = Math.pow(o.radius,2) * Math.PI;
Ap = Math.pow(player.radius,2) * Math.PI;
if(o.radius > player.radius){
Ao += Aa;
Ap -= Aa;
}else{
Ao -= Aa;
Ap += Aa;
}[/code]
4. calculate new radii from the updated areas
[code]
o.radius = Math.sqrt(Ao / Math.PI);
player.radius = Math.sqrt(Ap / Math.PI);
[/code]
Anyone got any suggestions? I would really appreciate them :)[/QUOTE]
I'd take area out of the equation entirely. If you are subtracting a small area from the circle it might not change the radius enough to make them not overlap. Figure out a way to do it by only checking the distance between the circles and the radii to see how much they are overlapping and adjust the radii accordingly. As soon as they are touching start adding the amount of overlap to the radius of the bigger circle and subtracting it from the radius of the smaller circle. I think you're overcomplicating it :P
[QUOTE=horsedrowner;37832713]I've made a screenshot uploader called Superscrot. I use it all the time; I only work on it occasionally. But I'm encountering an (URL) encoding problem that I can't figure out.
When you take a screenshot of a window, it puts the window title in the filename. However, Spotify likes to use the en-dash "–" (U+2013) to separate the artist and track name. This is causing problems.
- Files are uploaded with that filename as-is, without any encoding. I could probably avoid any problems by simply replacing invalid characters with - or _, but I'd like to do this correctly.
- I have a "screenshot overview" page on my server, where I'm using [url=http://php.net/manual/en/function.rawurlencode.php]rawurlencode[/url], which has shown to be the only encode function that properly works. It encodes the en-dash to "%96". I don't know how it got to %96, but that seems to work.
- System.Uri.EscapeUriString, however, encodes the dash as "%E2%80%93". Simply not encoding it at all doesn't work either. In both cases, the server returns a 404 error if I request an image like that.
URL without encoding: [url]http://s.horsedrowner.net/NANO/Window/201209281908041874-Spotify - Justice – Genesis.png[/url] (201209281908041874-Spotify - Justice – Genesis.png)
URL with EscapeUriString: [url]http://s.horsedrowner.net/NANO/Window/201209281908041874-Spotify%20-%20Justice%20%E2%80%93%20Genesis.png[/url] (201209281908041874-Spotify%20-%20Justice%20%E2%80%93%20Genesis.png)
URL with rawurlencode: [url]http://s.horsedrowner.net/NANO/Window/201209281908041874-Spotify%20-%20Justice%20%96%20Genesis.png[/url] (201209281908041874-Spotify%20-%20Justice%20%96%20Genesis.png)
Now, my questions is, how do I encode the URL properly in both C# and PHP?
My server is running nginx 1.2.3 with php 5.4 (yes, PHP, I know), and my server's locale is set to en_US.UTF-8.[/QUOTE]
Both methods are encoding the URI correctly. The difference is that C# is encoding it as UTF-8 and PHP is encoding it as extended ASCII. I find it likely that they both have methods to do it in either encoding. In order to support full UTF-8 I'd suggest you try fixing the PHP implementation, though I can't tell you how
Just a C++ design question.
I have a bunch of game object related data being sent from the server to the client. I want to be able to create a bunch of game objects from that. Currently all I do is know the order of each game object type coming down so I can create them. This works but I'd rather have a more general solution.
I really try to stay away from any kind of "entity" or "entity factory" design but I think something along them lines is needed if I want a more general solution for this.
The problem I have with factories is that in my framework, all subsystems don't have a global pointer like most frameworks do, so any game object that needs to use a subsystem has to have to passed into the constructor. That means some objects may need different arguments, that doesn't play nice with the factory design. I know I could have a number of templated arguments but I really don't want to go down that route.
So the only options I see is to just have a global pointer to all subsystems (which seems to be common in most frameworks) Or to give the base game object class pointers to all subsystems which it may use. Both options don't seem very good to me.
Also, it seems good to have a large monolithic entity list so you can update and draw everything without knowing the type of entity but the problem I have with that is finding specific entity types in that list (Players for example need to be iterated through quickly for spectators and what-not) so it would take a while to find them in the huge entity list.
One idea I had for this is to have the player add itself to a sublist of player objects but then when a player leaves, I have to keep both lists updated. Seems like there's a problem with any solution I come up with. Maybe there is no perfect solution, which is a problem for me because I'm a perfectionist.
Haven't used Java since last year. Didn't think I was that rusty, but apparently I am.
For some reason when I run javac on my .java file, it can't find any symbols.
For example:
[QUOTE]JobSchedule.java:27: cannot find symbol
symbol : class IntegerOverflowException
JobSchedule.java:26: cannot find symbol
symbol : class NullArrayException[/QUOTE]
Anyone know why this is happening? Here is my whole source file:
[QUOTE]import java.util.Scanner;
import java.lang.Math;
public class JobSchedule {
public static void main(String[] args)
{
int [] Array = new int[7];
Array[0] = 5;
Array[1] = 6;
Array[2] = 8;
Array[3] = 8;
Array[4] = 6;
Array[5] = 2;
Array[6] = 4;
system.out.println(recursiveJobSchedule(Array));
}
public static int recursiveJobSchedule(int [] A) throws
NullArrayException, InvalidInputException,
IntegerOverflowException
{
if (A==null) throw NullArrayException;
if (A.length==0) return 0; //Array is empty, so return 0 dollar value
else if (A.length==1) return A[0]; //Array only has one element to return the element value
else //Array is larger than 1 element
{
return max(recursiveJobSchedule(A,A.length-1),A[A.length-1]+recursiveJobSchedule(A,A.length-2));
}
}
public static int recursiveJobSchedule(int[] A, int n)
{
if (A==null) throw NullArrayException;
if (n==0) return 0; //Array is empty, so return 0 dollar value
else if (n==1) return A[0]; //Array only has one element to return the element value
else //Array is larger than 1 element
{
return max(recursiveJobSchedule(A,n-1),A[n-1]+recursiveJobSchedule(A,n-2));
}
}
}[/QUOTE]
Sorry, you need to Log In to post a reply to this thread.