Henri Korpela

Member
  • Content count

    5
  • Joined

  • Last visited

Community Reputation

104 Neutral

About Henri Korpela

  • Rank
    Newbie
  1. Utilizing vectors to move entities in 3D space

    Thanks, [b]Kyall[/b], for such a useful post! Now I see what are the benefits of using plain coordinates instead of angles to represent direction of where to go to. There's no need to recalculate direction when you can just sum it up to already existing coordinates in order to move requested entity. Simple yet satisfying. Anyway, could somebody still prove why this is true to deepen my understanding (and possibly the other's following this topic): [source lang="c++"]result.x = cos( direction.x ) * magnitude - sin( direction.y ) * magnitude result.y = sin( direction.x ) * magnitude + cos( direction.y ) * magnitude[/source]
  2. Hi, folks and welcome to the topic! First of all, I'd like to point out that I'm no math genius, but I really got hooked on vectors seeing their benefits in programming entity movement in virtual 2D and 3D environments. There are several vector classes written in C/C++ to be found on the Internet. However, as I'm willing to learn more about vectors all the time, I dediced to create my own class template in C++ called [b]Vector3[/b]. As far as I know, vector consists of a direction and a magnitude. Direction can be represents with the help of other vectors or by an angle. Magnitude on the hand, is simply the line segment from one point to another. Sounds reasonably simple. Now, I'm also willing to create a class called [b]Entity[/b]. In this class I'd like to have a [b]Vector3[/b]-class instance as a member. Via member function called "move" I'd like to use the vector to move some entity, like this: [CODE] Entity bob("Bob"); bob.move(30, 0, 1); // '30' and '0' are both angles, '1' represents velocity, which is in meters per second. [/CODE] Now, if I know both the direction given in angles and the magnitude, not to mention the vector start point in 3D space, how is it possible to calculate the vector end point or do I need to calculate the vector end point in order to move the entity? For me, it makes sense that the movement of an entity happens from one point to another, but how is this movement usually implemented by vectors?
  3. OpenAL + stb_vorbis - playing .ogg files?

    I'm just wondering why my static member function [b]_load_ogg[/b] does not work correctly... Could somebody explain me why?
  4. Hello, [i]game developers[/i]! I have been wandering around the Internet & managed to find a nifty little [i].c source file[/i] called [b]stb_vorbis[/b]. I ended up using it due to it's easy integration to my game engine & because [b]libvorbis[/b]' libraries didn't link themselves properly using [b]MinGW[/b]. After I had set up the[b] stb_vorbis[/b] by turning it into a header file & fixing some warnings in that file the compiler helpfully informed me about, I started to look for tutorials. Well, eventually, I found some, sort of: http://code.google.com/p/irrlamb/source/browse/trunk/source/engine/audio.cpp?r=726 https://gist.github.com/965399 Especially the last link turned out to be great, because it offered me a way to [i]stream [/i]an .ogg file. I wanted to have an object-oriented approach to handle .ogg files, both by buffers and streams, but couldn't get it to work. Now, I still have the same problem. By browsing the forums, I concluded that [b]stb_vorbis[/b] is a good solution. However, there are no actual tutorials to help you to set it up. That's sad. So, the question is, has anybody ever managed to get [b]stb_vorbis[/b] to load and play [i].ogg files[/i] via [b]OpenAL[/b]? It'd be very good thing to have a good solution for all other people to solve this similiar problem. Here's my buffer class: audio_buffer.hpp [CODE]/// ----------- /// @author God /// ----------- #ifndef __TIM_AUDIO_BUFFER_HPP__ #define __TIM_AUDIO_BUFFER_HPP__ namespace Tim{ namespace Audio{ /// ------------------------------------------------------------------------- /// @class Buffer /// @brief Represents an audio buffer, where audio files can be loaded into. /// ------------------------------------------------------------------------- class Buffer{ /// Friends: friend class Source; public: /// Enumerations: enum Formats{FORMAT_AUTODETECT, FORMAT_MP3, FORMAT_OGG, FORMAT_VOC, FORMAT_WAV}; /// Constructors & destructors: explicit Buffer(char const* file, Audio::Buffer::Formats const file_format = Audio::Buffer::FORMAT_AUTODETECT); ~Buffer(void); private: /// Static member functions: static void _check_file(Audio::Buffer& buffer); static void _load_ogg(Audio::Buffer& buffer); static void _load_wav(Audio::Buffer& buffer); /// Member data: Audio::Buffer::Formats const _m_iFormat; char const* _m_cpFile; int mutable _m_iChannels; unsigned int _m_uiBuffer; }; } } #endif // __TIM_AUDIO_BUFFER_HPP__[/CODE] audio_buffer.cpp [CODE]#include <cstdio> #include <cstring> #include <vector> #include <tim/al/al.h> #include <tim/al/alc.h> #include <tim/stb_vorbis/stb_vorbis.h> #include <tim/audio_buffer.hpp> using namespace Tim; /// ------------------------------------------------------------------------- /// @class Buffer /// @brief Represents an audio buffer, where audio files can be loaded into. /// ------------------------------------------------------------------------- /// Constructors & destructors: Audio::Buffer::Buffer(char const* file, Audio::Buffer::Formats const file_format) : _m_iFormat(file_format), _m_cpFile(file){ ::alGenBuffers(1, &_m_uiBuffer); _check_file(*this); } Audio::Buffer::~Buffer(void){ ::alDeleteBuffers(1, &_m_uiBuffer); } /// Static member functions: void Audio::Buffer::_check_file(Audio::Buffer& buffer){ switch(buffer._m_iFormat){ case FORMAT_MP3: break; case FORMAT_OGG: _load_ogg(buffer); break; case FORMAT_VOC: break; case FORMAT_WAV: _load_wav(buffer); break; default: switch(buffer._m_cpFile[::strlen(buffer._m_cpFile) - 3]){ case 79: // case 'O': case 111: // case 'o': _load_ogg(buffer); break; case 87: // case 'W': case 119: // case 'w': _load_wav(buffer); break; } break; } } void Audio::Buffer::_load_ogg(Audio::Buffer& buffer){ ::stb_vorbis* __file = ::stb_vorbis_open_filename(const_cast<char*>(buffer._m_cpFile), NULL, NULL); ::stb_vorbis_info __info = ::stb_vorbis_get_info(__file); int const __length_samples = (::stb_vorbis_stream_length_in_samples(__file) * __info.channels); ::ALshort* __buffer = new ::ALshort[__length_samples]; ::alGenBuffers(1, &buffer._m_uiBuffer); ::stb_vorbis_get_samples_short_interleaved(__file, __info.channels, __buffer, __length_samples); ::alBufferData(buffer._m_uiBuffer, ((__info.channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16), __buffer, (__length_samples * sizeof(::ALshort)), __info.sample_rate); delete[] __buffer; ::stb_vorbis_close(__file); } void Audio::Buffer::_load_wav(Audio::Buffer& buffer){ ::FILE* __file = ::fopen(buffer._m_cpFile, "rb"); short __bits_psample, __bytes_psample, __channels, __type_format; long __bytes_psec_avg, __rate_sample, __size, __size_chunk, __size_data; for(__size_data = 0; __size_data < 4; ++__size_data) // __size_data-variable represents a temporary iterator. ::getc(__file); ::fread(&__size, sizeof(long), 1, __file); for(__size_data = 0; __size_data < 8; ++__size_data) // __size_data-variable represents a temporary iterator. ::getc(__file); ::fread(&__size_chunk, sizeof(long), 1, __file); ::fread(&__type_format, sizeof(short), 1, __file); ::fread(&__channels, sizeof(short), 1, __file); ::fread(&__rate_sample, sizeof(long), 1, __file); ::fread(&__bytes_psec_avg, sizeof(long), 1, __file); ::fread(&__bytes_psample, sizeof(short), 1, __file); ::fread(&__bits_psample, sizeof(short), 1, __file); for(__size_data = 0; __size_data < 4; ++__size_data) // __size_data-variable represents a temporary iterator. ::getc(__file); ::fread(&__size_data, sizeof(long), 1, __file); unsigned char* __buffer = new unsigned char[__size_data]; ::fread(__buffer, sizeof(unsigned char), __size_data, __file); ::fclose(__file); // Opened file no longer needed, so it will be closed. ::alGenBuffers(1, &buffer._m_uiBuffer); ::alBufferData(buffer._m_uiBuffer, (__bits_psample == 8) ? ((__channels == 1) ? AL_FORMAT_MONO8 : AL_FORMAT_STEREO8) : ((__channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16), __buffer, __size_data, __rate_sample); delete[] __buffer; // A TEMPORARY BUFFER MUST DIE! } #undef __TIM_TEMPORARY_SIZE_BUFFER[/CODE]
  5. Hello, I created a very primitive application which is both [b]DirectX[/b] & [b]OpenGL[/b] compatible. As I already mentioned, it's primitive, but it works... almost. There is a slight problem and it's about the callback, which handles the window closure in [b]GLFW API[/b]. So, the question is: what kind of function definition will handle the callback properly? I know that the callback in [b]GLFW [/b]is this: int glfwSetWindowCloseCallback(void); I'm looking for proper implementation of the callback function. [b][u]PLEASE NOTE[/u]: WinAPI[/b] is out of the question, because the goal of my [b]OpenGL [/b]implementation of my application is to be compatible with [i]non-Microsoft[/i] systems. This is why I have two different APIS: [b]DirectX [/b]& [b]OpenGL[/b].