Jump to content

  • Log In with Google      Sign In   
  • Create Account


TheComet

Member Since 02 Oct 2013
Offline Last Active Today, 05:56 PM

#5172273 Funniest line of code ever ?

Posted by TheComet on 08 August 2014 - 08:15 AM

At work I came across lots of peculiar if-statements that always followed this pattern:

if(statement)
{
    foo();
}else if(!statement)
{
    bar();
}else
{
    fatal_error();
}

They all seemed to originate from a single developer, and apparently he has trust issues with the compiler/hardware.




#5166419 Amusing glitch gallery

Posted by TheComet on 12 July 2014 - 09:22 AM

 

tumblr_n8l3gicoIs1qdlh1io1_400.gif


This isn't normal?

 

This is actual footage of Brazil playing against Germany




#5166364 Amusing glitch gallery

Posted by TheComet on 12 July 2014 - 03:23 AM

tumblr_n8l3gicoIs1qdlh1io1_400.gif




#5165819 c++ function pointers

Posted by TheComet on 09 July 2014 - 09:07 AM

You think this is weird, get into pointer to class methods smile.png

Member function pointers aren't any more weird, they follow the same structure as function pointers after all:

typedef int (*function_type)(int); // function pointer
typedef int (SomeClass::*member_function_type)(int); // member function pointer

The only difference being you need an object or object pointer to call them on:

SomeClass object;
member_function_type member_func = &SomeClass::someMethod;
object.*member_func(25);



#5163826 Boost.Python - Ignoring return types of member functions?

Posted by TheComet on 30 June 2014 - 07:47 AM

I have two unrelated questions.

 

1) Consider the following C++ class and its wrapping code using Boost.Python:

struct Foo
{
    InternalThing* bar(std::string name);
};

BOOST_PYTHON_MODULE(test)
{
    using namespace boost::python;
    class_<Foo>("Foo")
        .def("bar", &Foo::bar)
    ;
}

InternalThing is a class that is not wrapped and has no reason to be exposed, consequently generating a compile error because Boost.Python can't find it.

 

How can I tell Boost.Python to ignore the return type and just assume it to be void?

 

 

2) When I tested the compiled shared object in Python (using PyCharm), I noticed that PyCharm's autocomplete doesn't know about any of the available classes/methods. Is there a way to expose that kind of information to PyCharm, perhaps through a .py stub file?




#5160513 Unworkable project

Posted by TheComet on 14 June 2014 - 10:39 AM

I'd personally hit the "delete" button and blame a system glitch ...

That might actually work if they don't use version control and everyone is gullible enough. Not hard to imagine considering the circumstances, but it's a stupid move.




#5158753 Scott Meyers - The Last Thing D Needs

Posted by TheComet on 06 June 2014 - 12:29 PM

Still watching, but holy cow...He-Man hair biggrin.png

Sorry but I'm not sorry

 

ohgod.jpg

 

(however, I am sorry for reviving a thread that was at the bottom of the board. I hope that's ok)




#5156359 Scott Meyers - The Last Thing D Needs

Posted by TheComet on 27 May 2014 - 04:28 PM

http://www.ustream.tv/recorded/47947981

 

Great talk, I recommend watching it if you have the time.

 

It's a summary of some of the peculiarities found in C++, centered around the topic of how hard standardization is and what is to become of the C++ standard in the future.




#5156251 Physics and Animation (3D)?

Posted by TheComet on 27 May 2014 - 04:23 AM

I've little experience with physics simulation, and was wondering what the best approach is to mixing skeletal animation with physics along with some procedural animation.

 

It occurred to me that animations aren't bound to the physical limitations a ragdoll (for instance) would enforce. That is, an animation can very easily create infinite amounts of energy, which basically ends up destroying any purely physically simulated object on contact. An example of this behaviour can be observed in Skate 3.

 

I'm trying to simulate something like what Nintendogs did, where you can pet an animal with the mouse cursor. I want to support things such as moving an arm into a certain position, then have the pet stay like that, all while having the pet react to other physical objects. On top of that, the pet plays various animations blended together with procedural animation.

 

My approach would have been to use some form of PID controller to generate force inputs for the physics engine, depending on what the skeleton should be doing, and what it actually is doing. This would mean the pet would be a full ragdoll, and the animation would only influence the way it moved.

 

Would this be the best approach? Is there a library that already handles this? Can someone perhaps point me to some useful articles on the subject?




#5155251 Ogre3D Animation Help

Posted by TheComet on 22 May 2014 - 12:57 PM

The solution is below, and turned out to be pretty simple. It will copy a section of one animation (specified by startTime and endTime) into a destination animation, scaling it to take up the length of the destination animation.

 

// ----------------------------------------------------------------------------
void Entity::extractAnimation(Ogre::Animation* source,
                              Ogre::Animation* dest,
                              Ogre::Real startTime,
                              Ogre::Real endTime)
{
    Ogre::Real timeScale = dest->getLength() / (endTime - startTime);
    dest->destroyAllTracks();


    // loop through all animation node tracks in source and copy them to destination
    for(Ogre::Animation::NodeTrackIterator srcNodeTrackIt = source->getNodeTrackIterator();
        srcNodeTrackIt.hasMoreElements()
        ;)
    {
        Ogre::NodeAnimationTrack* srcNodeTrack = srcNodeTrackIt.getNext();
        unsigned short trackHandle = srcNodeTrack->getHandle();
        Ogre::NodeAnimationTrack* destNodeTrack = dest->createNodeTrack(trackHandle);


        // loop through all transforms of current source track and copy them to destination
        // if they are within the time frame specified
        for(unsigned short keyFrameHandle = 0;
            keyFrameHandle != srcNodeTrack->getNumKeyFrames();
            ++keyFrameHandle)
        {
            Ogre::TransformKeyFrame* srcKeyFrame = srcNodeTrack->getNodeKeyFrame(keyFrameHandle);
            if(srcKeyFrame->getTime() < startTime || srcKeyFrame->getTime() > endTime)
                continue;


            Ogre::Real scaledTime = (srcKeyFrame->getTime()-startTime) * timeScale;
            Ogre::TransformKeyFrame* destKeyFrame = destNodeTrack->createNodeKeyFrame(scaledTime);


            destKeyFrame->setTranslate(srcKeyFrame->getTranslate());
            destKeyFrame->setRotation(srcKeyFrame->getRotation());
            destKeyFrame->setScale(srcKeyFrame->getScale());
        }
    }
}

Example usage:

    this->extractAnimation(
            m_OgreEntity->getSkeleton()->getAnimation("Anim_1"),
            m_OgreEntity->getSkeleton()->createAnimation("walk", 0.6f),
            41.0f,  // walk begin frame
            71.0f   // walk end frame
    );


    m_OgreEntity->refreshAvailableAnimationState();
    m_WalkAnimState = m_OgreEntity->getAnimationState("walk");



#5152060 Variadic templates - Deducing member function signature?

Posted by TheComet on 07 May 2014 - 09:38 AM

Hi Juliean,

 

Thanks for the help! You're definitely on the right track. Unfortunately, PARAMS does have to be declared before the function signature, and since PARAMS is of variable length, it must be declared at the very end.

 

I played around with it a little more now and I've found a solution (doesn't quite comply to the original requirements I had, but it's fine too).

 

The template parameters for the class now only contain the listener:

template <class LISTENER_CLASS>
class GenericDispatcher

And I modified the dispatcher function to be:

template <class RET_TYPE, class... PARAMS>
void dispatch(RET_TYPE (LISTENER_CLASS::*func)(PARAMS...), PARAMS... params)
{
    for(auto it = m_Listeners.begin(); it != m_Listeners.end(); ++it)
        (it->second->*func)(params...);
}

If you pass the member function pointer as an argument, it allows the compiler to deduce its signature.

 

The entire code:

#include <iostream>
#include <string>
#include <map>

struct Listener
{
    virtual void doThing(int, int) = 0;
    virtual void doAnotherThing(float) = 0;
};

struct Foo : public Listener
{
    virtual void doThing(int a, int b)
    {
        std::cout << a*b << std::endl;
    }
    virtual void doAnotherThing(float a)
    {
        std::cout << a << std::endl;
    }
};

template <class LISTENER_CLASS>
class GenericDispatcher
{
public:
    void addListener(LISTENER_CLASS* listener, std::string name)
    {
        m_Listeners[name] = listener;
    }

    template <class RET_TYPE, class... PARAMS>
    void dispatch(RET_TYPE (LISTENER_CLASS::*func)(PARAMS...), PARAMS... params)
    {
        for(auto it = m_Listeners.begin(); it != m_Listeners.end(); ++it)
            (it->second->*func)(params...);
    }

private:
    std::map<std::string, LISTENER_CLASS*> m_Listeners;
};

int main()
{
    Foo a, b;
    GenericDispatcher<Listener> dispatcher;
    dispatcher.addListener(&a, "a");
    dispatcher.addListener(&b, "b");
    dispatcher.dispatch(&Listener::doThing, 6, 7);
    dispatcher.dispatch(&Listener::doAnotherThing, 4.32f);
    return 0;
}



#5147689 dllexport global variable

Posted by TheComet on 17 April 2014 - 11:11 AM

Usually you'll want to define a macro for doing this:

#ifdef COMPILING_DLL
#   define API __declspec(dllexport)
#else
#   define API __declspec(dllimport)
#endif

// NOTE: Might want to throw the above into an "export.h" file

extern "C" {
    API DWORD NvOptimusEnablement = 0x00000001;
}

Though you're probably better of defining it in the .cpp file as:

DWORD NvOptimusEnablement = 0x00000001;

And in your header file use:

extern "C" {
    API extern DWORD NvOptimusEnablement;
}

That way you're guaranteed that it will only be exported once.




#5147625 Writing model 3D Model data to a new file as a new format

Posted by TheComet on 17 April 2014 - 07:32 AM

You might also want to consider using a library to save you from writing your own exporter/importer.




#5147377 c++ oo syntax behind the scenes behavior

Posted by TheComet on 16 April 2014 - 10:06 AM

When you define/instantiate an instance of a class using the new operator, sizeof(ClassName) number of bytes are allocated on the heap, and a pointer pointing to the beginning of the instance is returned.

ClassName* instance = new ClassName(); // memory is allocated on the heap here
instance->doSomething();

When you define/instantiate an instance of a class on the stack, the memory is guaranteed to be allocated when you need it.

ClassName instance; // Memory is allocated on the stack here
instance.doSomething();

The VMT is typically stored by adding an extra private pointer member variable to the class, which points to a virtual table. Every instance of the class generally shares the same virtual table.

 

If you add more virtual functions, the class size does not grow though.

 

This can be shown with the following code:

#include <iostream>

class Foo
{
public:
    Foo() {}
    virtual ~Foo() {}
private:
    int a;
};

class Bar
{
public:
    Bar() {}
    virtual ~Bar() {}
    virtual void set( int a ) { this->a = a; }
    virtual int get( int a ) { return a; }
private:
    int a;
};

int main()
{
    std::cout << "sizeof(Foo): " << sizeof(Foo) << std::endl;
    std::cout << "sizeof(Bar): " << sizeof(Bar) << std::endl;

    return 0;
}

 

Foo and Bar have the same size, even though Bar has more virtual functions.




#5146301 Static as substitute of private members.

Posted by TheComet on 11 April 2014 - 09:30 AM


What do you mean "implicitly static"? If you have two compilation units that define variables with the same name in the global scope and none of them are static, you will get a "multiple definition" error when linking. There is no such thing as "implicitly static".

I was mistaken, sorry.






PARTNERS