Jan 28, 2015

After long while I had some time to finally make something for the game. As i was planning before, I've implemented the group moving behaviour to the engine. Although it still needs fixes to be of good use, its still a good start

Here's video that I've recorded to demonstrate:

Jan 8, 2015

Today I've implemented character selecting (same way as in any rts game). Most interesting upgrade was to create raycast from cursor position rather then just directly raycasting from camera. I used the guide located in here: Mouse Picking with Ray Casting

Since I am using glm and glfw, my function looks like this:
glm::vec3 GraphicsMain::GetMouseRay(){
    // Get mouse position
    double xpos, ypos;
    glfwGetCursorPos(window, &xpos, &ypos);

    float x = (2.0f * xpos) / res_x - 1.0f;
    float y = 1.0f - (2.0f * ypos) / res_y;
    glm::vec3 tmp_vec3 = glm::vec3 (x, y, 1.f);

    glm::vec4 tmp_vec4 = glm::vec4 (tmp_vec3.x, tmp_vec3.y, -1.f, 1.f);
    tmp_vec4 = glm::inverse(ProjectionMatrix) * tmp_vec4;
    tmp_vec4 = glm::vec4 (tmp_vec4.x, tmp_vec4.y, -1.0, 0.0);
    tmp_vec4 = (glm::inverse(ViewMatrix) * tmp_vec4);
    tmp_vec4 = glm::normalize(tmp_vec4);

    tmp_vec3 = glm::vec3(tmp_vec4.x, tmp_vec4.y, tmp_vec4.z);

    return tmp_vec3;
}

After failing a ton of time with overlapping query in PhysX, I've decided to just roll simple check to get selection for models. I guess the check could be somehow more simple but this will do for now:

if(x_min <= models_list.at(i)->position.x &&
models_list.at(i)->position.x <= x_max &&
z_min <= models_list.at(i)->position.z &&
models_list.at(i)->position.z <= z_max)

I think next I should try implementing moving the group in formation, or at least in a way where all the models are not trying to move on to each other. But that will be implemented on the next post.

Models trying to move to same position, quite dumb result

Dec 20, 2014

Most of the code refactoring has been done. Next I'm planning on implementing select with sweep query and moving units of blocks in the same way as I've been moving the one block before.
I've also given access to the blog for my artist, who may post her concept art and sketches that we are planning on using in the game.

Nov 26, 2014

Time to fix some mess on code. In other words pack the experimented code to functions and classes. Currently there's way too much reused and reused code which I want to have neatly on functions and classes.

Cleaning it might take a while so new content will appear slower for now. After some cleaning Im planning on implementing some ideas:
  • Raycast check if projectile/object passed other object but didnt collided
  • Homing missile which tracks the target
  • Breakable models (need another physx library)
  • Selecting models with sweep query
  • Some new sample models for scenery
I've also got one person working on some concept art, planning to check the results during the new year's day. I gave pretty free hands for the artist, as the only requirements given were "sci-fi laser pew pew" -type of design.

Nov 16, 2014

I've tried to record video of the current situation of project. Here's the result:


Nov 9, 2014

Finally I got the callbacks working correctly, now the bullets will pop up as sphere when they hit either one of the "players" or the ground.

Bullets blooming to sphere when they hit ground or player
I achieved this by nesting class of PxSimulationEventCallback on my physics engine class. And I implemented all of the event functions in there just for the future:

    class pCallBacks:public PxSimulationEventCallback{
        public:
        pCallBacks(void);
        ~pCallBacks(void);

        PxFilterFlags TestFilterShader(   
        PxFilterObjectAttributes attributes0, PxFilterData filterData0,
        PxFilterObjectAttributes attributes1, PxFilterData filterData1,
        PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize);

         void                        onConstraintBreak(PxConstraintInfo* constraints, PxU32 count);
         void                        onWake(PxActor** actors, PxU32 count);
         void                        onSleep(PxActor** actors, PxU32 count);
         void                        onContact(const PxContactPairHeader& pairHeader, const PxContactPair* pairs, PxU32 nbPairs);
         void                        onTrigger(PxTriggerPair* pairs, PxU32 count);
      };

    pCallBacks gCallbacks;

And then just set the callbacks on the init:

sceneDesc.simulationEventCallback = &gCallbacks;

The problem currently is that I need to make a new list for explosions and then remove these actors from the physics simulation (currentl the spheres bounce around instead of staying in one spot). Ill try to achieve that for the next post on the blog.

Oct 28, 2014

Currently I am trying to test out filtering in Physx engine. The plan was to make simple raycast check if one of the targets could see the white player and shoot back if it did (return false if raycast hits ground or air). I've set groups for terrain (0), "boxes" (1) and the projectiles (2). However only effect I've seen is that the projectiles won't go through ground anymore...
Maybe the filters for models are working correctly but there is something wrong with the raycast filter (since it's different kind of filter compared to settings filters).

PxReal maxDistance = 10000.0f;            // [in] Raycast max distance
PxRaycastBuffer hit;                 // [out] Raycast results

PxQueryFilterData tmp_filter_data = PxQueryFilterData();
tmp_filter_data.data.word0 = 2;        // Projectile group
tmp_filter_data.data.word1 = 1;        // "Player" group
tmp_filter_data.flags |= PxQueryFlag::eANY_HIT;

// Always returns 0 if using filters..but why?
bool status = gScene->raycast(origin, unitDir, maxDistance, hit, PxHitFlags(PxHitFlag::eDEFAULT), tmp_filter_data);

Well, to get some kind of progress I've added some inaccuracy to the shots, now bullets wont travel in straight line against the target.
White player shooting inaccurately at the brown boxes

After getting filters to work, I'll try to make custom oncontact triggers. If I can manage that, then i can convert my bullets to exploding bullets which could be some fun :)

*** EDIT ***

I had one simple mistake when I was setting the filters for my boxes. Instead of setting setQueryFilterData I was using setSimulationFilterData.

So setting the filters simple worked like this:

 PxFilterData filterData;
 filterData.word0 = 1;

const PxU32 numShapes = gBox3->getNbShapes();
PxShape* shapes;
gBox3->getShapes(&shapes, numShapes);
for(PxU32 i = 0; i < numShapes; i++)
{
    PxShape* shape = &shapes[i];
    shape->setQueryFilterData(filterData);
}