I was reading up on C++ optimizations and it mentioned two phase constructors giving the following example
[cpp]class OnePhase
{
private:
Bitmap m_bMap; // Bitmap is a "one-phase" constructed object
public:
bool Create(int nWidth, int nHeight)
{
return (m_bMap.Create(nWidth, nHeight));
}
int GetWidth() const
{
return (m_bMap.GetWidth());
}
};
class TwoPhase
{
private:
Bitmap* m_pbMap; // Ptr lends itself to two-phase construction
public:
TwoPhase()
{
m_pbMap = NULL;
}
~TwoPhase()
{
delete m_pbMap;
}
bool Create(int nWidth, int nHeight)
{
if (m_pbMap == NULL)
m_pbMap = new Bitmap;
return (m_pbMap->Create(nWidth, nHeight));
}
int GetWidth() const
{
return (m_pbMap == NULL ? 0 : m_pbMap->GetWidth());
}
};[/cpp]
But would the two phase constructor not enter a loop of recursivelly calling the create method?
I want to get Pitch and Yaw from a Vector3, but I can't get it to work.
From my Camera.cs:
[code]
internal void LookAt(Vector3 target)
{
Vector3 direction = Position - target;
direction.Normalize();
Yaw = ??
Pitch = ??
}
[/code]
Edit: Forgot to mention that all coordinates are in the OpenGL system!
Ok, got it working now :)
[code]
internal void LookAt(Vector3 target)
{
Vector3 direction = target - Position;
float length = direction.Length;
direction.Normalize();
Pitch = (float)Math.Asin(Vector3.Dot(Vector3.UnitY, direction));
Yaw = (float)Math.Atan2(direction.Z, direction.X);
}
[/code]
[QUOTE=Richy19;38495552]I was reading up on C++ optimizations and it mentioned two phase constructors giving the following example
But would the two phase constructor not enter a loop of recursivelly calling the create method?[/QUOTE]
No, maybe you are thinking that m_bMap.Create is the same as one of the OnePhase.Create or TwoPhase.Create methods.
[QUOTE=Meatpuppet;38491143]How would I go about reversing a bool through a keypress? Say I want to increment r when the left key is pressed, but I want to decrement it when it's been pressed a second time. Using C++ and GLFW. Here's what I want to do:
[cpp]
if(keytoggle && GLFW_PRESS == GLFW_KEY_LEFT)
//increment r
// reverse keytoggle (a bool)
if(!keytoggle && GLFW_PRESS == GLFW_KEY_LEFT)
//decrease r
// reverse keytoggle[/cpp]
[/QUOTE]
Still can't figure this out, it seems like it would be really simple.
I'm looking to create a desktop application for my website, [url]http://ezyimg.com[/url] where you can take a screenshot and have it automatically upload the image by sending a request. How would I go about doing this?
@meatpuppet:
Add a global or class variable r somewhere and change it in the keypress event.
To revesre a bool:
keytoggle = !keytoggle;
[QUOTE=kragmars102;38500520]I'm looking to create a desktop application for my website, [url]http://ezyimg.com[/url] where you can take a screenshot and have it automatically upload the image by sending a request. How would I go about doing this?[/QUOTE]
Couldn't you just access the clipboard and paste the image there?
[QUOTE=Meatpuppet;38500530]Couldn't you just access the clipboard and paste the image there?[/QUOTE]
I could do that using HTML5, but I'm looking to have it highlight a certain part of the user's screen and upload directly from their desktop rather then having them visit the website.
[QUOTE=kragmars102;38500520]I'm looking to create a desktop application for my website, [URL]http://ezyimg.com[/URL] where you can take a screenshot and have it automatically upload the image by sending a request. How would I go about doing this?[/QUOTE]
Use sharex and write a plugin for it (or ask the creator to add your website)
[QUOTE=Wealth + Taste;38492681]In Java, how do I reference/use data from an instantiated object in my driver class within one of my support classes? I made a reference in one of my methods in the support class to an instantiated object in my driver class, but it "can't resolve" it.[/QUOTE]
Can someone please help me?
I made a new thread, use this one instead:
[url]http://facepunch.com/showthread.php?t=1226847[/url]
I have been (somewhat successfully) trying to implement RK4 integration with help from the Gaffer on Games tutorial ([url]http://gafferongames.com/game-physics/integration-basics/[/url]), however I seem to be failing in achieving a MKS system.
I am trying to make sure each pixel is equivalent to 1 meter, which I think is the direct result of implementing the above tutorial with no change, however especially when I add momentum and force things start going a bit pear shaped.
In my mind, after implementing proper gravitational force and no drag, a fall of 200 pixels should be equivalent to a fall of 200 meters, which should take about 6.4 seconds, however this doesn't seem to be the case. So either I am fucking something up implementing force/momentum/velocity derivation, or something else is at play (to be clear, with gravity defined as 9.8 m/s2, it takes the particle far far longer than 6 seconds to move anywhere at all).
I can/will post the relevant code if anyone would care to comment/help. But any general tips and tricks regarding physics simulation and RK4 with force/momentum is also appreciated!
[QUOTE=Meatpuppet;38500457]Still can't figure this out, it seems like it would be really simple.[/QUOTE]
[cpp]if(GLFW_PRESS == GLFW_KEY_LEFT)
{
if(keytoggle) r++; else r--;
keytoggle = !keytoggle; // flip the bool
}[/cpp]
Doesn't work, even when I fixed it. (you need to poll glfwGetKey, like this:
[cpp] if(glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
{
if(keytoggle) r += 0.01f * time / 10; r -= 0.01f * time / 100;
keytoggle = !keytoggle; // flip the bool
}[/cpp])
It's not working because keytoggle is being reset all the time, when it's being pressed. I don't know how to avoid that.
[cpp]if(glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
{
r += 0.01f * time / 10;
}
if(glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS)
{
r -= 0.01f * time / 10;
}[/cpp]
?
[QUOTE=Jookia;38504952][cpp]if(glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
{
r += 0.01f * time / 10;
}
if(glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS)
{
r -= 0.01f * time / 10;
}[/cpp]
?[/QUOTE]
Here's what I want to do:
When the left key is pressed the first time, increment r.
When the key is released, flip keytoggle.
When the key is pressed again, decrement r.
When the key is released, flip keytoggle.
Repeat.
[QUOTE=Meatpuppet;38505043]Here's what I want to do:
When the left key is pressed the first time, increment r.
When the key is released, flip keytoggle.
When the key is pressed again, decrement r.
When the key is released, flip keytoggle.
Repeat.[/QUOTE]
[cpp]
//As a class member
bool rInc = true;
if(glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
{
if(rInc)
r++;
else
r--;
rInc = !rInc
}
if(glfwGetKey(GLFW_KEY_RIGHT) == GLFW_RELEASED)
{
keytoggle = !keytoggle;
}[/cpp]
So why are you doing it every frame and not when the events happen?
[QUOTE=Richy19;38505338][cpp]
//As a class member
bool rInc = true;
if(glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
{
if(rInc)
r++;
else
r--;
rInc = !rInc
}
if(glfwGetKey(GLFW_KEY_RIGHT) == GLFW_RELEASED)
{
keytoggle = !keytoggle;
}[/cpp][/QUOTE]
what do you mean as a class member?
[QUOTE=Meatpuppet;38506485]what do you mean as a class member?[/QUOTE]
[URL="http://content.gpwiki.org/index.php/GLFW:Tutorials:Basics"]Register a callback function.[/URL]
Hey, I got a problem,I made a program using java which takes russian named files and renames them into english. But the problem is: When it comes to a loop renaming say 50 (for example) files, it only renames 25 of them. Then if I try again it renames 12 of them. Then 6. then 3 etc..
Any alternatives?
[code] public void Rename(String name, File which){
which.renameTo(new File(desti+"\\"+name));
}
[/code]
This function is called by loop which should rename all files.
I need specifically an alternative for this.
[QUOTE=Meatpuppet;38506485]what do you mean as a class member?[/QUOTE]
He means it has to be declared outside the local scope. So that it's value will stay the same when the function re-runs. Otherwise you'll overwrite it every time the function is run.
Making a bullet class in C++ with SFML. Everything is okay but I've been thinking. This is a snippet of the class code:
[code]
#include <SFML\Graphics.hpp>
class Bullet
{
Bullet();
sf::Texture blt_texture;
sf::Sprite blt_sprite;
};
[/code]
Since there are a lot of bullets loading the image from the HDD for every instance of the bullet should be very inefficient. Should i store the image somewhere else and just use a reference to it or something like that ?
[QUOTE=demoTron;38511935]Making a bullet class in C++ with SFML. Everything is okay but I've been thinking. This is a snippet of the class code:
[code]
#include <SFML\Graphics.hpp>
class Bullet
{
Bullet();
sf::Texture blt_texture;
sf::Sprite blt_sprite;
};
[/code]
Since there are a lot of bullets loading the image from the HDD for every instance of the bullet should be very inefficient. Should i store the image somewhere else and just use a reference to it or something like that ?[/QUOTE]
Always
[editline]19th November 2012[/editline]
[QUOTE=ahdge;38507427][URL="http://content.gpwiki.org/index.php/GLFW:Tutorials:Basics"]Register a callback function.[/URL][/QUOTE]
No idea why I quoted that and responded with that.
[code]
if(glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
{
keytoggle = !keytoggle;
if(keytoggle) { inc = !inc; }
}
r+=keytoggle?inc?r++:r--:0;
[/code]
Or something like that
[QUOTE=demoTron;38511935]Making a bullet class in C++ with SFML. Everything is okay but I've been thinking. This is a snippet of the class code:
[code]
#include <SFML\Graphics.hpp>
class Bullet
{
Bullet();
sf::Texture blt_texture;
sf::Sprite blt_sprite;
};
[/code]
Since there are a lot of bullets loading the image from the HDD for every instance of the bullet should be very inefficient. Should i store the image somewhere else and just use a reference to it or something like that ?[/QUOTE]
If you want to have more than 500 bullets I'd suggest you use a VBO for that instead of single sprites.
It's not that hard to use and will give you an awesome performance boost.
SFMLs class for VBOs is called just "VertexBuffer" I think.
[QUOTE=ahdge;38512051]
[code]
r+=keytoggle?inc?r++:r--:0;
[/code]
Or something like that[/QUOTE]
Wow, that line really looks like you spend some time to make it hard to read.
Keep in mind that the guy who asked this question is new to programming. No need to show him "obfuscated" code :P
Hey WDYNW, I just started working on SFML and C++ together, so I don't really have an idea of what I'm doing but can someone explain why this code doesn't move the shape?
[code]
#include <SFML/Graphics.hpp>
void moveShape(sf::CircleShape shape)
{
shape.move(-2,0);
return;
}
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
shape.setOutlineThickness(4.0f);
shape.setOutlineColor(sf::Color::Blue);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::KeyPressed)
{
moveShape(shape);
std::printf("you pressed a key");
}
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
[/code]
Felheart, you mentioned calling update(), but from what function? Isn't main() the update already?
Oh nevermind, apparently you need to add an ampersand(&) to pass the reference of the variable, otherwise it just sends a copy of their values.
Changing
[code]void moveShape(sf::CircleShape shape)
{
shape.move(-2,0);
return;
}[/code]
to
[code]void moveShape(sf::CircleShape& shape)
{
shape.move(-2,0);
return;
}[/code]
fixed everything
Hey OpenGL pros :v:
Where do these artifacts come from? How do I fix them?
Left side are 2 quads, top side is one quad, right side are 2 quads.
I already converted all of the coordinates from float to int and back to make 100% sure it's not a floating point error.
[IMG]http://i.imgur.com/ZnkPc.png[/IMG]
I can't see anything wrong with it.
edit: looked like an intentional outline to me
There are lines between the faces of cubes.
Strangely there are no lines between the directly adjecant faces. (Where the two sandblocks are touching at the left and right side.
But at all 90° angles there are some artifacts.
Here's a better pic where the effect is really extreme:
[IMG]http://i.imgur.com/gbdnP.png[/IMG]
[IMG]http://i.imgur.com/wQLFE.png[/IMG]
It looks like the faces of the cubes are a little bit "extruded" but thats not the case. I converted all vertex positions to int and back to eliminate potential floatingpoint errors.
I also tried to play around with texture clamp and filter modes. But no luck :(
edit: added even bigger picture with paint annotations
edit2: With anti-aliasing off, it fixes the issue when being near the blocks. But it's still there when viewing them from a distance. Also I want to keep AA.
Need help making this function in Python 2.5
[QUOTE]is_UPC12(number) that accepts an integer representing a 12-digit UPC code,
determines if it is a valid code or not by calculating and comparing the check
digit, and returns True if it is a valid UPC or False otherwise.[/QUOTE]
Sorry, you need to Log In to post a reply to this thread.