Jump to content

  • Log In with Google      Sign In   
  • Create Account

Magusware

Member Since 20 May 2011
Offline Last Active Aug 04 2013 11:44 AM

Topics I've Started

OpenAL AL_FORMAT_51CHN16, any actual how to out there?

16 July 2013 - 04:54 PM

Hi Guys,

 

I have managed to find a bit more info on the subject but still no definitive answer or solution. In light of the new info my question has now changed.

 

Looking into the files that the sample uses with audacity I see that the fiveptone.wav actually has 6 channels in the file whereas the file I am trying to play only has 2 (thus being stereo).

 

What are the steps needed to take to make the audio play through more channels and give bass and rear speakers output to the 2 channel track? Would I need to create a special 5.1 buffer and somehow put the data in all the respective channels, if so how? 

 

Basically, I want the track to sound somewhat similar to what I hear in my music player when previewing it, where I can hear the bass etc. just nicely.

 

Thanks in advance,

Chris

 

 

 

-- Old Question --- 

 

Hi guys, 

 

Got a problem here with audio in my game. I decided to start working on getting 5.1 sound working when I hit a bit of a wall. Up until now I've been using alut so everything has been simple and easy and I have to look up very little in what I needed... again... until now...

 

I have been using alutCreateBufferFromFile(const char* filename); function to create my buffers, but what I have managed to deduce is I need to load the data separately and use alBufferData to set the buffer data as I need it.

 

as such I have the following.

ALenum		format;
void*		data;
ALsizei		size;
ALsizei		freq;
ALboolean	loop;

alutLoadWAVFile(filename, &format, &data, &size, &freq, &loop);

ALuint buffers[1];
alGenBuffers(1, buffers);

ALenum eBufferFormat = alGetEnumValue("AL_FORMAT_51CHN16");

//safeguard if al_format_51chn16 is unsupported
format = eBufferFormat ? eBufferFormat : format;

alBufferData(buffers[0], format, data, size, freq);

This is obviously not how you do it. I know this because it doesn't play the audio. It finds the format enum but I don't think I'm using it correctly.

However, It does play if I let it use the format it pulls from alutLoatWavFile, so the al/alut implementation is working.

 

So my question is, what am I missing? what am I doing wrong? The official documentation is no help whatsoever and searching the problem online is coming up with nothing but dead ends.

 

I know very little about audio programming so a step by step for this would be perfect and much appreciated. Even a nudge in the right direction would be awesome.

 

 

Thanks in advance

MaGuSware™


CPU and Memory Usage, Problem Obtaining it [C++]

05 May 2012 - 03:11 PM

Greetings,

I have been working on my final year project for, the content of which is irrelevant to the problem, but I need to obtain the CPU Usage each frame and the memory usage of the program.

I have implemented a snippet of code I found on Stack Overflow (http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process) but I have a huge problem.

Quite frequently the GetCPUUsage() returns 0 or INF.
This is obviously because the current and last are the same values.

This is moving into programming territory I know extremely little or absolutely nothing about. What are the potential solutions to this problem, I have no problem implementing a different method of obtaining resource usage if anybody has any suggestions.

The exact code I am using:
#pragma once
/*
http://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process
*/
#include <Windows.h>
#include <Psapi.h>
#pragma comment(lib, "Psapi.lib")
class ResourceUsage
{
private:
PROCESS_MEMORY_COUNTERS pmc;
int numProcessors;
HANDLE self;
ULARGE_INTEGER lastCPU;
ULARGE_INTEGER lastSysCPU;
ULARGE_INTEGER lastUserCPU;
FILETIME ftime, fsys, fuser;
ULARGE_INTEGER now, sys, user;
ResourceUsage()
{
  SYSTEM_INFO sysInfo;
	    FILETIME ftime, fsys, fuser;
	    GetSystemInfo(&sysInfo);
	    numProcessors = sysInfo.dwNumberOfProcessors;
   
	    GetSystemTimeAsFileTime(&ftime);
	    memcpy(&lastCPU, &ftime, sizeof(FILETIME));
   
	    self = GetCurrentProcess();
	    GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
	    memcpy(&lastSysCPU, &fsys, sizeof(FILETIME));
	    memcpy(&lastUserCPU, &fuser, sizeof(FILETIME));
}
~ResourceUsage(){}
public:
static ResourceUsage& GetSingleton()
{
  static ResourceUsage ru;
  return ru;
}

SIZE_T GetMemoryUsage(void)
{
 
  GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
  return pmc.WorkingSetSize;
}
double GetCPUUsage()
{
  double percent = 0.0f;
  GetSystemTimeAsFileTime(&ftime);
  memcpy(&now, &ftime, sizeof(FILETIME));
  GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
  memcpy(&sys, &fsys, sizeof(FILETIME));
  memcpy(&user, &fuser, sizeof(FILETIME));
  percent = (sys.QuadPart - lastSysCPU.QuadPart) +
	 (user.QuadPart - lastUserCPU.QuadPart);
  percent /= (now.QuadPart - lastCPU.QuadPart);
  percent /= numProcessors;
  lastCPU   = now;
  lastUserCPU  = user;
  lastSysCPU  = sys;
  return percent * 100;
}
};

Thanks in advance.

-MaGuSware

Trouble with Recast/Detour

21 April 2012 - 07:09 AM

[Solved]

I recoded my Build Nav Mesh function with the help of andrew from the recast navigation google code group.
If anyone has the problem of nneis being zero on a search they know will have polys there, or subsequently the polycount in the findNearestPoly() is zero. Hell, even if its just not building your mesh, you might be able to solve your problem by looking at my code now that it works.

bool NavMeshBuilder::CreateNavMesh(int vertex_count, float* verts, int index_count, int* indices)
{
rcContext* ctx = new rcContext();
rcHeightfield*  hf  = rcAllocHeightfield();
rcCompactHeightfield* chf  = rcAllocCompactHeightfield();
rcContourSet*  cset  = rcAllocContourSet();
rcPolyMesh*  polyMesh = rcAllocPolyMesh();
rcPolyMeshDetail* detailPolyMesh = rcAllocPolyMeshDetail();
do
{
  //2
  rcConfig config;
  config.tileSize = 1;
  config.ch = 0.1;
  config.cs = 0.1;
  config.walkableClimb = 0.9;
  config.walkableRadius = 0.2;
  config.walkableHeight = 1.8;
  config.walkableSlopeAngle = 45;
  config.minRegionArea = 8;
  config.mergeRegionArea = 20;
  config.borderSize = 1;
  config.maxEdgeLen = 12;
  config.maxSimplificationError = 1.3;
  config.maxVertsPerPoly = 6;
  config.detailSampleDist = 6;
  config.detailSampleMaxError = 1;
  config.bmax[0] = verts[0];
  config.bmax[1] = verts[1];
  config.bmax[2] = verts[2];
  config.bmin[0] = verts[0];
  config.bmin[1] = verts[1];
  config.bmin[2] = verts[2];
  //3 determine tile boundingbox;
  for(int i = 0; i < vertex_count / 3; i++)
  {
   if (verts[i*3] > config.bmax[0])
    config.bmax[0] = verts[i*3];
   if (verts[i*3+1] > config.bmax[1])
    config.bmax[1] = verts[i*3+1];
   if (verts[i*3+2] > config.bmax[2])
    config.bmax[2] = verts[i*3+2];
   if (verts[i*3] < config.bmin[0])
    config.bmin[0] = verts[i*3];
   if (verts[i*3+1] < config.bmin[1])
    config.bmin[1] = verts[i*3+1];
   if (verts[i*3+2] < config.bmin[2])
    config.bmin[2] = verts[i*3+2];
  }
  //config.width = 370;
  //config.height = 250;
  rcCalcGridSize(config.bmin, config.bmax, config.cs, &config.width, &config.height);
  //4
  if (!rcCreateHeightfield(ctx, *hf, config.width, config.height, config.bmin, config.bmax, config.cs, config.ch))
   break;
  //5
  unsigned char* areas = new unsigned char[index_count/3];
  rcMarkWalkableTriangles(ctx, config.walkableSlopeAngle, verts, vertex_count, indices, index_count / 3, areas);
  //6
  hf->freelist = 0;
  rcRasterizeTriangles(ctx, verts, areas, index_count / 3, *hf);
  //7
  rcFilterLowHangingWalkableObstacles(ctx, config.walkableClimb, *hf);
  //8
  rcFilterLedgeSpans(ctx, config.walkableHeight, config.walkableClimb, *hf);
  //9
  rcFilterWalkableLowHeightSpans(ctx, config.walkableHeight, *hf);
  //10
  if(!rcBuildCompactHeightfield(ctx, config.walkableHeight, config.walkableClimb, *hf, *chf))
   break;
  //11
  if(!rcErodeWalkableArea(ctx, config.walkableRadius, *chf))
   break;
  //12
  chf->dist = 0;
  if(!rcBuildDistanceField(ctx, *chf))
   break;
  //13
  if(!rcBuildRegions(ctx, *chf, config.borderSize, config.minRegionArea, config.mergeRegionArea))
   break;
  //14
  if(!rcBuildContours(ctx, *chf, config.maxSimplificationError, config.maxEdgeLen, *cset))
   break;
  //15
  if(!rcBuildPolyMesh(ctx, *cset, config.maxVertsPerPoly, *polyMesh))
   break;
  this->BuildDebugRender(*polyMesh);
  //16
  if(!rcBuildPolyMeshDetail(ctx, *polyMesh, *chf, config.detailSampleDist, config.detailSampleMaxError, *detailPolyMesh))
   break;
  for (int i = 0; i < polyMesh->npolys; ++i)
  {
   if (polyMesh->areas[i] == RC_WALKABLE_AREA)
    polyMesh->areas[i] = SAMPLE_POLYAREA_GROUND;
   if (polyMesh->areas[i] == SAMPLE_POLYAREA_GROUND ||
    polyMesh->areas[i] == SAMPLE_POLYAREA_GRASS ||
    polyMesh->areas[i] == SAMPLE_POLYAREA_ROAD)
   {
    polyMesh->flags[i] = SAMPLE_POLYFLAGS_WALK;
   }
   else if (polyMesh->areas[i] == SAMPLE_POLYAREA_WATER)
   {
    polyMesh->flags[i] = SAMPLE_POLYFLAGS_SWIM;
   }
   else if (polyMesh->areas[i] == SAMPLE_POLYAREA_DOOR)
   {
    polyMesh->flags[i] = SAMPLE_POLYFLAGS_WALK | SAMPLE_POLYFLAGS_DOOR;
   }
  }
  //17
  dtNavMeshCreateParams params;
  memset(&params, 0, sizeof(params));
  params.verts  = polyMesh->verts;
  params.vertCount = polyMesh->nverts;
  params.polys  = polyMesh->polys;
  params.polyFlags = polyMesh->flags;
  params.polyAreas = polyMesh->areas;
  params.polyCount = polyMesh->npolys;
  params.nvp  = polyMesh->nvp;
  rcVcopy(params.bmin, polyMesh->bmin);
  rcVcopy(params.bmax, polyMesh->bmax);
  params.detailMeshes = detailPolyMesh->meshes;
  params.detailVerts = detailPolyMesh->verts;
  params.detailVertsCount = detailPolyMesh->nverts;
  params.detailTris = detailPolyMesh->tris;
  params.detailTriCount = detailPolyMesh->ntris;
  params.walkableClimb = config.walkableClimb;
  params.walkableHeight = config.walkableHeight;
  params.walkableRadius = config.walkableRadius;
  params.tileLayer = 0;
  params.tileX  = 0;
  params.tileY  = 0;
  params.offMeshConAreas = 0;
  params.offMeshConCount = 0;
  params.offMeshConDir = 0;
  params.offMeshConFlags = 0;
  params.offMeshConRad = 0;
  params.offMeshConUserID = 0;
  params.offMeshConVerts = 0;
  params.ch = config.ch;
  params.cs = config.cs;
  params.buildBvTree = true;
  if(!dtCreateNavMeshData(&params, &m_navMeshData, &m_navMeshDataSize))
   break;
}
while ( 0 != 0 );
delete ctx;
rcFreeHeightField(hf);
rcFreeCompactHeightfield(chf);
rcFreeContourSet(cset);
rcFreePolyMesh(polyMesh);
rcFreePolyMeshDetail(detailPolyMesh);

if (m_navMeshData != NULL && m_navMeshDataSize != 0)
{
  return LoadNavMesh();
}
return false;
}





[Original topic]

Greetings once again GameDev.

I'm having trouble getting recast and detour to work properly. I can get it to generate a navmesh from my world mesh but when I call my pathfinding function it fails to get the nearest poly to the start position and end position. I have clearly overlooked something, what a certain setting does or even missed out a step entirely during the generation.

My NavMesh generation is based on a post by a guy on a forum who gave the correct call order to build the navmesh.

1 - Get geometry for the area you want to mesh from your parser
2 - Create rcConfig structure with your config values
3 - Determine bounding box for the tile you want to create
4 - Call rcCreateHeightField, passing in the geometry from the parser
5 - Call rcMarkWalkableTriangles
6 - Call rcRasterizeTriangles
7 - Call rcFilterLowHangingWalkableObstacles
8 - Call rcFilterLedgeSpans
9 - Call rcFilterWalkableLowHeightSpans
10 - Call rcBuildCompactHeightField
11 - Call rcErodeArea
12 - Call rcBuildDistanceField
13 - Call rcBuildRegions
14 - Call rcBuildContours
15 - Call rcBuildPolyMesh
16 - Call rcBuildPolyMeshDetail
17 - Call dtCreateNavMeshData. This will give you the structure to save to the disk. This will be the mesh for the tile you've just created. Later you can load these files and use dtAddTile (or something similarly named) to load the tiles for use in pathfinding.


From that I have coded up:
bool CreateNavMesh(Ogre::Entity* ent)
{
  /*
  1 - Get geometry for the area you want to mesh from your parser
  2 - Create rcConfig structure with your config values
  3 - Determine bounding box for the tile you want to create
  4 - Call rcCreateHeightField, passing in the geometry from the parser
  5 - Call rcMarkWalkableTriangles
  6 - Call rcRasterizeTriangles
  7 - Call rcFilterLowHangingWalkableObstacles
  8 - Call rcFilterLedgeSpans
  9 - Call rcFilterWalkableLowHeightSpans
  10 - Call rcBuildCompactHeightField
  11 - Call rcErodeArea
  12 - Call rcBuildDistanceField
  13 - Call rcBuildRegions
  14 - Call rcBuildContours
  15 - Call rcBuildPolyMesh
  16 - Call rcBuildPolyMeshDetail
  17 - Call dtCreateNavMeshData. This will give you the structure to save to the disk. This will be the mesh for the tile you've just created. Later you can load these files and use dtAddTile (or something similarly named) to load the tiles for use in pathfinding.
  */
  //1.
  size_t vertex_count;
  float* verts;
  size_t index_count;
  int* indices;
  ::_getMeshInformation(ent, vertex_count, verts, index_count, indices);

  return CreateNavMesh(vertex_count, verts, index_count, indices);
}
bool CreateNavMesh(int vertex_count, float* verts, int index_count, int* indices)
{
  rcContext* ctx = new rcContext();
  //2
  rcConfig config;
  config.width = 370;
  config.height = 250;
  config.tileSize = 1;
  config.ch = 0.1;
  config.cs = 0.1;
  config.walkableClimb = 0.9;
  config.walkableRadius = 0.2;
  config.walkableHeight = 1.8;
  config.walkableSlopeAngle = 45;
  config.minRegionArea = 8;
  config.mergeRegionArea = 20;
  config.borderSize = 1;
  config.maxEdgeLen = 12;
  config.maxSimplificationError = 1.3;
  config.maxVertsPerPoly = 6;
  config.detailSampleDist = 6;
  config.detailSampleMaxError = 1;
  config.bmax[0] = verts[0];
  config.bmax[1] = verts[1];
  config.bmax[2] = verts[2];
  config.bmin[0] = verts[0];
  config.bmin[1] = verts[1];
  config.bmin[2] = verts[2];
  //3 determine tile boundingbox;
  for(int i = 0; i < vertex_count / 3; i++)
  {
   if (verts[i*3] > config.bmax[0])
	config.bmax[0] = verts[i*3];
   if (verts[i*3+1] > config.bmax[1])
	config.bmax[1] = verts[i*3+1];
   if (verts[i*3+2] > config.bmax[2])
	config.bmax[2] = verts[i*3+2];
   if (verts[i*3] < config.bmin[0])
	config.bmin[0] = verts[i*3];
   if (verts[i*3+1] < config.bmin[1])
	config.bmin[1] = verts[i*3+1];
   if (verts[i*3+2] < config.bmin[2])
	config.bmin[2] = verts[i*3+2];
  }
  /*
  Not sure if this is needed, got from looking at Recast Demo source
  */
  {
   config.bmax[0] += config.borderSize * config.cs;
   config.bmax[1] += config.borderSize * config.cs;
   config.bmax[2] += config.borderSize * config.cs;
   config.bmin[0] -= config.borderSize * config.cs;
   config.bmin[1] -= config.borderSize * config.cs;
   config.bmin[2] -= config.borderSize * config.cs;
  }
  //
  //4 create heightfield
  rcHeightfield hf;
  if (!rcCreateHeightfield(ctx, hf, config.width, config.height, config.bmin, config.bmax, config.cs, config.ch))
   return false;
  //5 mark walkable triangles
  unsigned char* areas = new unsigned char[index_count/3];
  rcMarkWalkableTriangles(ctx, config.walkableSlopeAngle, verts, vertex_count, indices, index_count / 3, areas);
  //6 rastarize tris
  hf.freelist = 0;
  rcRasterizeTriangles(ctx, verts, areas, index_count / 3, hf);
  //7 filter low hanging walkable objs
  rcFilterLowHangingWalkableObstacles(ctx, config.walkableClimb, hf);
  //8 filter ledge spans
  rcFilterLedgeSpans(ctx, config.walkableHeight, config.walkableClimb, hf);
  //9
  rcFilterWalkableLowHeightSpans(ctx, config.walkableHeight, hf);
  //10
  rcCompactHeightfield chf;
  rcBuildCompactHeightfield(ctx, config.walkableHeight, config.walkableClimb, hf, chf);
  //11
  rcErodeWalkableArea(ctx, config.walkableRadius, chf);
  //12
  chf.dist = 0;
  rcBuildDistanceField(ctx, chf);
  //13
  rcBuildRegions(ctx, chf, config.borderSize, config.minRegionArea, config.mergeRegionArea);
  //14
  rcContourSet cset;
  rcBuildContours(ctx, chf, config.maxSimplificationError, config.maxEdgeLen, cset);
  //15
  rcPolyMesh* polyMesh = rcAllocPolyMesh();
  rcBuildPolyMesh(ctx, cset, config.maxVertsPerPoly, *polyMesh);
  //16
  rcPolyMeshDetail* detailPolyMesh = rcAllocPolyMeshDetail();
  rcBuildPolyMeshDetail(ctx, *polyMesh, chf, config.detailSampleDist, config.detailSampleMaxError, *detailPolyMesh);
  //17
  dtNavMeshCreateParams params;
  params.verts  = polyMesh->verts;
  params.vertCount = polyMesh->nverts;
  params.polys  = polyMesh->polys;
  params.polyFlags = polyMesh->flags;
  params.polyAreas = polyMesh->areas;
  params.polyCount = polyMesh->npolys;
  params.nvp   = polyMesh->nvp;
  params.detailMeshes  = detailPolyMesh->meshes;
  params.detailVerts  = detailPolyMesh->verts;
  params.detailVertsCount = detailPolyMesh->nverts;
  params.detailTris  = detailPolyMesh->tris;
  params.detailTriCount = detailPolyMesh->ntris;
  if(!dtCreateNavMeshData(&params, &m_navMeshData, &m_navMeshDataSize))
   return false;
  delete ctx;
  if (m_navMeshData != NULL && m_navMeshDataSize != 0)
  {
   return LoadNavMesh();
  }
  return false;
}
bool LoadNavMesh()
{
  m_pNavMesh = new dtNavMesh();
  if(m_pNavMesh->init(m_navMeshData, m_navMeshDataSize, 0) != DT_SUCCESS)
  {
   delete m_pNavMesh;
   return false;
  }
  return true;
}

But when I run the search on it with 2 points I know exist, it fails to find the nearest poly's, the code for this search is based on the CapekNav pathfinder by Michael Cutler

bool GetPath(Vector3 start, Vector3 end, std::list<Vector3>& path)
{
  float spos[3] = { start.x, start.y, start.z };
  float epos[3] = { end.x, end.y, end.z };
  dtQueryFilter filter;
  filter.setIncludeFlags(0xffffff);
  filter.setExcludeFlags(0);
  float extents[3] = { 0, 0, 0 };
  dtPolyRef startRef;
  dtPolyRef endRef;
  float nfs[3] = { 0, 0, 0 };
  float nfe[3] = { 0, 0, 0 };
  m_pQuery->findNearestPoly(spos, extents, &filter, &startRef, nfs);
  m_pQuery->findNearestPoly(epos, extents, &filter, &endRef, nfe);
  if (!startRef || !endRef)
   return false;
  dtPolyRef  polys[MAX_POLYS];
  int	nbPolys = 0;
  float   strPath[MAX_POLYS*3];
  int	nbStrPath = 0;
  unsigned char strPathFlags[MAX_POLYS];
  dtPolyRef  strPathPolys[MAX_POLYS];

  m_pQuery->findPath(startRef, endRef, spos, epos, &filter, polys, &nbPolys, MAX_PATH);
  if(nbPolys)
  {
   m_pQuery->findStraightPath(spos, epos, polys, nbPolys, strPath, strPathFlags, strPathPolys, &nbStrPath, MAX_PATH);
   for( int i = 0; i < nbStrPath/3; i++)
   {
	Vector3 point(strPath[i*3+0], strPath[i*3+1], strPath[i*3+2]);
	path.push_back(point);
   }
   path.back().x = end.x;
   path.back().y = end.y;
   path.back().z = end.z;
  }
  return true;
}

Can anyone see what I've missed?

Thanks in advance,
-MaGuSware

Having trouble with Ogre and Bullet

26 October 2011 - 06:42 AM

Greetings again GameDev community.

I'm working on a project for university in which the aim is to make a fully featured game using any middleware we wish to use.
I have chosen to use OGRE for my rending and I am currently looking into different engines for my physics.

Currently I'm testing the Bullet physics engine which was fairly easy to setup but not so easy to configure, if that makes sense.

my testing environment is composed of a few cubes and q3dm1.bsp (from Quake 3).

I can pass the bsp into bullet which generates the physics world just fine. The collisions work just fine and the cubes bounce off the walls and floors.
The problem is that it is too "floaty".

One of my class mates pointed out that it could be to do with the scaling of the physics world, which makes sense considering that 1 unit = 1 meter in bullet. Wheras in Ogre it is whatever the programmer decides.
For this, I would say that my unit:meter ratio is currently governed by the Quake3 level which is loaded in.

To be perfectly honest I'm not sure how to go about scaling this. I have bullet physics "scaling the world" wiki page but that did not help.

A few of the things I have tried, such as scaling the gravity, met with undesired results.
Such as the cubes not settling on the floor, instead they are "wibbing" partly inside the floor trying to push themselves out.

I tried scaling the bsp to the physics engine units, but that made some of the brushes dissapear (as expected (too small)) and it still caused the "wibbing" of the cube.

To be perferctly honest, I am stumped and I don't know where to go from here short of scrapping testing Bullet.

Any ideas?

Recommended Library for Midi playback

18 September 2011 - 07:27 PM

Greetings,


Currently, I am using DirectMusic from Direct X 9.0c Summer 2004, it is depracted and has been for some time now. (installed DX9 '04 Summer SDK to get at it).
Naturally I wish to have something which is not outdated and is still supported.

Can anyone think of anything off the top of their heads that is free and would make a good replacement for this? I've tried searching around and have had no luck thus far. In fact the best I got for midi playback was DirectMusic, which in turn lead me to initially installing the SDK.


Thanks in adv.

Chris.

PARTNERS