It'd call System.Array.ToString, which is not overridden and thus uses the default implementation as per Object.Array, which "returns the fully qualified name of the type of the Object" ([url]http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx[/url]).
Hey, I'm using this:
[cpp]
GL.MatrixMode( MatrixMode.Projection );
GL.Rotate( Geom.Pyth( MouseOffsetX, MouseOffsetY ) / 10, new Vector3d( MouseOffsetY, MouseOffsetX, 0 ) );[/cpp]
To rotate the camera first-person shooter style. Since z is always 0 it shouldn't roll but if I move my mouse in a circular motion it does.
Can anyone explain this and how do I fix it?
[QUOTE=Darwin226;22835514]Hey, I'm using this:
GL.MatrixMode( MatrixMode.Projection );
GL.Rotate( Geom.Pyth( MouseOffsetX, MouseOffsetY ) / 10, new Vector3d( MouseOffsetY, MouseOffsetX, 0 ) );
To rotate the camera first-person shooter style. Since z is always 0 it shouldn't roll but if I move my mouse in a circular motion it does.
Can anyone explain this and how do I fix it?[/QUOTE]
glRotate rotates the matrix around a vector by the specified amount. If you think of the vector as the axis of rotation, you should see where your roll is coming from. Instead rotate around each axis individually, for the x and y components, rotate around the x and y axis.
-snip-
wrong thread
[QUOTE=Osherzz;22835885][media]http://www.youtube.com/watch?v=sL0wHSCj4Cs[/media]
gravity![/QUOTE]
You need help with this?
I want this. Now
I got a bit of a problem here. So I wrote a program that finds prime numbers. What it does is you enter a number, and if it's prime, it comes back out and says it's prime. However if it's not prime, it adds one to the original number until it becomes prime.
My problem is this though, for some reason my program is saying 2 and 3 aren't prime. Which they are.
[code]
#include <iostream>
#include <math.h>
using namespace std;
int prime(int n);
int main()
{
int i;
while (1)
{
cout << "Enter a number (0 to exit)";
cout << "and press ENTER: ";
cin >> i;
if (i == 0)
{
break;
}
while (prime(i) == false)
{
cout << i << " is not prime." << endl;
i++;
}
if (prime(i))
{
cout << i << " is prime." << endl;
}
}
return 0;
}
int prime(int n)
{
int i;
int sqrt_of_n;
sqrt_of_n = sqrt((double) n);
for (i = 2; i <= sqrt_of_n; i++)
{
if (n % i == 0)
{
return false;
}
return true;
}
}
[/code]Any idea what it does that?
Edit: Like if you enter the number 1, it'll say:
1 is not prime.
2 is not prime.
3 is not prime.
4 is not prime.
5 is prime.
It says 2 and 3 aren't prime but wikipedia and other places say that 2 and 3 are prime.
You should move the return true out of the for loop, and the problem is in your square root check. The integer square root of 2 and 3 is 1, which is less than 2 so the for loop never runs.
Square roots aren't necessarily integers.
[QUOTE=Agent766;22840455]Square roots aren't necessarily integers.[/QUOTE]
They are when the result is stored into an int variable.
[editline]12:16AM[/editline]
(Or were you pointing out that an int variable shouldn't be used?)
You're also not checking if i == n.
[QUOTE=Wyzard;22841297]They are when the result is stored into an int variable.
[editline]12:16AM[/editline]
(Or were you pointing out that an int variable shouldn't be used?)[/QUOTE]
A square root usually has decimals, hence it's a double, not an integer. You'll lose a lot of precision casting it to an int.
[QUOTE=looped;22836086]You need help with this?[/QUOTE]
damn, wrong thread...
Sometimes, you only need integer precision. Like in this case.
[editline]12:54PM[/editline]
Though you should round up the number before casting here.
[QUOTE=arienh4;22846239]You'll lose a lot of precision casting it to an int.[/QUOTE]
Understatement of the year
So I'm trying to make a vector of pointers to a Star object but it's not working.
Warning: bunch of horrible code ahead
[cpp]
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
class Star {
public:
sf::Sprite Sprite;
Star()
{
sf::Image Image;
Image.LoadFromFile("1px.png");
Sprite.SetImage(Image);
Sprite.SetPosition(rand(),rand());
}
};
int main()
{
std::vector<Star*> lol;
std::vector<Star*>::const_iterator it;
for (int i=0;i<100;i++) {
Star* newStar = new Star();
lol.push_back(newStar);
}
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();
App.Display();
for(it = lol.begin(); it != lol.end(); ++it) {
App.Draw(it->*Sprite);
}
}
return EXIT_SUCCESS;
}
[/cpp]
Everything is fine until the drawing part. I've tried everything to fix it, but nothing seems to work. :eng99:
Any help?
[B]So basically the idea of the program[/B] is to render a bunch (a vector) of Stars at a random position.
But I have [B]NO IDEA[/B] how to do that!
Why aren't you using arrays?
[cpp]
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
class Star {
public:
sf::Sprite Sprite;
Star()
{
sf::Image Image;
Image.LoadFromFile("1px.png");
Sprite.SetImage(Image);
Sprite.SetPosition(rand(),rand());
}
};
int main()
{
Star[] StarList = new Star[100];
for (int i = 0; i < 100; i++)
{
StarList[i] = new Star();
}
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();
App.Display();
for (int i = 0; i < 100; i++)
{
App.Draw(StarList[i].Sprite);
}
}
return EXIT_SUCCESS;
}
[/cpp]
You don't need to call new on each element again. And it's also leaking memory, both versions.
Don't forget to delete (or delete[]) what you new (or new[]).
I'd probably also be good to but a range on that rand()-call.
[QUOTE=Dlaor;22850501]Why aren't you using arrays?[/QUOTE]
Yeah I actually did think about using arrays earlier but thought that it wouldn't work :v:
also your version gives me the following Error:
main.cpp:20: error: expected unqualified-id before '[' token
Star StarList[] = new Star[100];
But since the size is static, you might just use a stack-allocated array; 100 Star objects shouldn't consume too much space.
[QUOTE=ZeekyHBomb;22851246]Star StarList[] = new Star[100];[/QUOTE]
Tried this to fix it.
Result: error: initializer fails to determine size of 'StarList'
Eh. That's the syntax for static-sized arrays. Use a pointer instead.
So I tried using pointers (but most likely did it wrong :downs:)
[code]
Star **StarList = new Star *[100];
for (int i = 0; i < 100; i++)
{
StarList[i] = new Star();
}
[/code]
and I added this to the end of it:
[code]
for (int i = 0; i < 100; i++)
{
App.Draw(StarList[i]->Sprite);
}
[/code]
It compiles fine [B]BUT[/B] the Stars don't show.
I also set a range on the Sprite.SetPosition of the stars, still aren't showing.
[editline]08:32PM[/editline]
Okay update:
It shows ONE star and that's all. Haha... :downs:
[editline]08:39PM[/editline]
[B]OKAY I THINK I GOT IT NOW:[/B]
It DOES draw ALL the 100 stars, but in the same Sprite.SetPosition.
[editline]09:46PM[/editline]
[B]YES GOD YESS!!!![/B]
[URL=http://img149.imageshack.us/i/starsvn.png/][IMG]http://img149.imageshack.us/img149/8890/starsvn.png[/IMG][/URL]
100 stars all in random locations :smug:
Thanks a lot guys!
Hey guys, I've hit another bump.
So, I've managed to draw a cube and light it (still drawing in/with immediate mode, this is only a test). I also managed to get the camera moving first person shooter style. Arrow movement too.
Now I decided to slowly start using shaders for lighting and those vertex buffer objects and whatnot.
So, I copy over 1 vertex and 1 fragment shader from an example and I'm trying to get it working.
This is the code that I have so far, the problem is in the OnLoad function
[URL="http://pastebin.com/FUqNGpXY"]http://pastebin.com/FUqNGpXY[/URL]
Console outputs only "test", no other info.
It only displays a black screen, it's possible that the cube just isn't lighted, it's also possible that the shader has an error so it just isn't displaying anything. Everything works without that code that uses the shaders.
I'm probably getting very annoying, sorry about that.
[editline]09:30PM[/editline]
Oooooh, I'm supposed to give the vertex shader the projection and modelview matrix, right?
Yes, you have to do everything yourself as soon as you use shaders.
No problem, I've woken up with new loads of enthusiasm. I've managed to get something to display, It's a yellow box, I'm guessing it's a side of the cube, the problem is that the movement doesn't work anymore, I'm guessing that I have to translate the modelviewMatrix and the projectionMatrix instead of what I'm currently doing.
[QUOTE=NotMeh;22852108] -snipquote- [/QUOTE]
Why are you using an array of pointers?
How do I translate or rotate a Matrix4? I found that Matrix4 has a Rotation and Translation static methods, so do I multiply and existing matrix with the one that is returned by those methods or what?
Post #500! Wohoo ignorance!
[QUOTE=ZeekyHBomb;22855735]Why are you using an array of pointers?[/QUOTE]
I have no idea, but it's working and I'm happy.
Now to add random planets and moons that orbit them.
[QUOTE=Darwin226;22855830]How do I translate or rotate a Matrix4? I found that Matrix4 has a Rotation and Translation static methods, so do I multiply and existing matrix with the one that is returned by those methods or what?
Post #500! Wohoo ignorance![/QUOTE]
glRotate is deprecated I believe.
Setup your own rotation matrix creation and yeah, through multiplying you can 'stack' several transformations.
[QUOTE=NotMeh;22856041]I have no idea, but it's working and I'm happy.
Now to add random planets and moons that orbit them.[/QUOTE]
It's working doesn't mean it's pretty :(
Sorry, you need to Log In to post a reply to this thread.