1
Audio / Listener Orientation
« on: October 12, 2011, 03:45:51 pm »
Thank you for considering it and also for your patience
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
is not normal and could be solved without hacking in SFML.
I could, of course, put the listener at (0, 0, 10), but it's just that +Y being down makes more sense when using a physics engine.
QuoteTo me it's ok to have the up vector hard-coded, this is like a physical constant (just like gravity for example).
In 3D, gives you the hability to roll your head (e.g. Peeking from a corner of a wall).
In 2D gives you freedom to define which sound-coordinate axis is associated with a screen-coordinate counterpart. I like using x for x and y for y, it's more confortable to work this way.
Also to let you "reverse" the speakers (Up = -Up), for configuration and also could be used for a weird powerup effect.
////////////////////////////////////////////////////////////
void Listener::SetDirection(float x, float y, float z)
{
priv::EnsureALInit();
float orientation[] = {x, y, z, 0.f, 1.f, 0.f};
ALCheck(alListenerfv(AL_ORIENTATION, orientation));
}
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML\Graphics.hpp>
#include <SFML\OpenGL.hpp>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
// Load the sprite image from a file
sf::Texture Tex;
if (!Tex.LoadFromFile("platform.png"))
return EXIT_FAILURE;
// Create the sprite
sf::Sprite Sprite(Tex);
// Change its properties
Sprite.SetPosition(64.f, 64.f);
Sprite.SetSubRect(sf::IntRect(0, 16, 16, 16));
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.PollEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Get elapsed time
float ElapsedTime = App.GetFrameTime() / 1000.f;
// Move the sprite
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Left)) Sprite.Move(-100 * ElapsedTime, 0);
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Right)) Sprite.Move(100 * ElapsedTime, 0);
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Up)) Sprite.Move(0, -100 * ElapsedTime);
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Down)) Sprite.Move(0, 100 * ElapsedTime);
// Rotate the sprite
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Add)) Sprite.Rotate(- 100 * ElapsedTime);
if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Subtract)) Sprite.Rotate(+ 100 * ElapsedTime);
// Clear screen
App.Clear();
// Display sprite in our window
App.Draw(Sprite);
// Now that SFML set-up the viewport, bound the texture and everything, just draw directly
sf::Vector2f v = Sprite.GetPosition() + sf::Vector2f(64.f, 0.f);
float Epsilon = 0.0078125;
glBegin(GL_QUADS);
{
glTexCoord2f(0.f, 0.25f); glVertex2f(v.x, v.y);
glTexCoord2f(0.f, 0.5f - Epsilon); glVertex2f(v.x, v.y + 16);
glTexCoord2f(0.25f - Epsilon, 0.5f - Epsilon); glVertex2f(v.x + 16, v.y + 16);
glTexCoord2f(0.25f - Epsilon, 0.25f); glVertex2f(v.x + 16, v.y);
}
glEnd();
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
The "right" value should be 0.0078125, which is 0.5 / size (from your screenshot your texture looks like it is 64x64), that's why it's called the half-pixel trick
So it's not a ugly hack, but rather a well-known technique to align pixels and texels -- which are initially aligned differently (one is aligned at the center of a pixel, the other is aligned on the top-left corner of a pixel).
But I'm surprised it works because that's the first thing I tried in order to solve this problem.
But something is not clear: do you subtract this offset from pixel coordinates (0 .. size), or normalized coordinates (0 .. 1)?
Don't worry, I'll do the tests
Doesn't the problem reappear if you offset your sprite by this value?
I'm not 100% sure if it got to do with this but I remember one of my class mates talking about something similar or maybe the exact thing(It's about a year ago now) and he said he fixed his problem by offsetting the sprite with 1 pixel. So instead of having origo at 0,0 it was at 1,1
Anyhow, going with the padding solution didn't help you?
I think this is the same problem I already had here.
Do the issues persist exactly as they were in the new graphics API? Would the possibility for customization be too low-level?
Yes, and that was even done before. If you look at the Git log for Renderer.cpp you can find a revision which contains this code (it's two additional lines in ProcessVertex).