Jump to content

  • Log In with Google      Sign In   
  • Create Account

Stragen

Member Since 18 Jun 2012
Offline Last Active Yesterday, 09:36 PM

#5175929 OpenGL window is not visible.

Posted by Stragen on 24 August 2014 - 11:22 PM

You can also get rid of the console using "FreeConsole()" though this may be platform specific (in all likelihood it is) IIRC GlutInitWindowPosition is not a required call (i'm not doing it in my code) and if you leave it out it will default to the top left corner of the screen.


#5174903 Event/Action Management

Posted by Stragen on 19 August 2014 - 07:49 PM

So I thought I'd come back in here after having a tinker and give my outcomes.

#include <functional>
#include <vector>
#include <string>
#include <map>

template 
int idType(void)
{
	static const int id = typeid(varType).hash_code();
	return id;
}

class Variable{
public:
	template
	Variable(const varType& _in) : type(idType()){
		data = new varType(_in);
	}

	template
	const varType& GetValue(void) const{
		assert(type == idType());
		return *(const varType*)data;
	}
	
	int GetType(void) const{
		return type;
	}

private:
	void* data;
	int type;
};


int destroyObject(Variable targetID){
	if (targetID.GetType() == typeid(std::string).hash_code())
		fprintf(stdout, "%s to be destroyed\n", targetID.GetValue().c_str());
	else if (targetID.GetType() == typeid(int).hash_code())
		fprintf(stdout, "%i to be destroyed\n", targetID.GetValue());
	else
		fprintf(stdout, "ERROR: EVENTMGT - destroyObject passed invalid variable\n");

	return 0;
}

int createObject(Variable targetID){
	//will be passed 2 values, both will be strings...
	if (targetID.GetType() == typeid(std::string).hash_code())
		fprintf(stdout, "%s to be created\n", targetID.GetValue().c_str());
	else
		fprintf(stdout, "ERROR: EVENTMGT - destroyObject passed invalid variable\n");

	return 0;
}

int testUpdate(Variable value){
	int newValue = 5;

	return newValue;
}

class EVENTMANAGER{

	std::map funcMap;
	std::map actionMap;
	//onCollide callAction doDestroy;
	//function* funcArray[1];

	
public:
	EVENTMANAGER(){
		funcMap["doDestroy"] = destroyObject;
		funcMap["doCreate"] = createObject;
		funcMap["testUpdate"] = testUpdate;
		actionMap["onCollision"] = "doDestroy";
	}

	void functionRun(std::string s){
		std::string strings[2];
		int targetId = 2;
		Variable returnVal = funcMap.at("testUpdate")(targetId);
		targetId = returnVal.GetValue();

		std::string string = "this is a string";
		Variable arg = string;
		(funcMap.at(actionMap.at(s)))(arg); //could simply pass the string variable, rather than casgint a Variable type to a string.

		//example of passing string to function, needs to be explicitly defined and passed as string.
		//[Variable arg = "this is a string"] will assume that the variable type is char* and char* is not a valid type.

		//std::string string = "this is a string";
		//fprintf(stdout, "%s is set to arg\n", arg.GetValue().c_str());
		//(funcMap.at(actionMap.at(s)))(string);
		
		//example of passing float to function
		//Variable argf = "1.0f";
		//(funcMap.at(actionMap.at(s)))(argf)
		
		
	}

};

As you outlined Juliean, the code you put up was somewhat non-functional, particularly had issues with the type identification in the first block.

 

Opted to try the typeid inbuilt function to use the hash code to track the variable type, though i've read there are some issues with this, particularly cross platform however its more of an issue using the name member from what i understand.

 

I've taken on the point of using <functional>, and toyed with the idea of using a Variable return type, for a Variable input.

 

I had thought about using STD::Vector though thought that this might be redundant, and when i played with it, there was a little bit more effort to pull the variable arguments out, but it completely worked, though its probably better using the vector vs passing a vector.

 

Its surprising how powerful this kind of templated class and function is, and from the research i've been doing, a lot of people simply say its not possible... which is really surprising that this is as simple as it is.

 

[edit] Borked formatting [/edit]




#5174432 Event/Action Management

Posted by Stragen on 18 August 2014 - 06:58 AM

Thanks for the responses so far... attempting to digest them.

 

I'm liking the look of std::function and was surprised that I've not seen that before... is this new with c++11?




#5108912 How to compute the bounding volume for an animated (skinned) mesh ?

Posted by Stragen on 13 November 2013 - 03:18 AM

If you are really needing to create an AABB, you will have to generate it based on the largest X,Y,Z value of the post scaled, translated, and rotated model. Its more important to do it against the post rotated model as you need the X,Y,Z based on where it lies after rotation, the result could then be scaled and translated. This will still need to be done each animation step as this is going to change where the BB is going to lie based on the location of the verticies changing each step.

 

You probably shouldn't bother with the generation of the maxes prior to transforming the model if you're not concerned with the OBB, so once you've transformed it calculate based on the same process that you did when calculating the 'OBB' the first time.

 

If you calculate the model maxes prior to the translation/scale/rotate you will get the maxes based on the model only in model space, and applying the same transformation will result in a OBB in world space.

 

Just to consider, below is an example of where an AABB is going to give you something that doesnt look right for the volume taken up by an object.

 

boundingboxexample2.png

 

The blue boxes are the same size, the AABB box has been cast in red on the box on the right.

The OBB for the blue box on the right will be the same space as the blue box.

 

If you go to investigate collision detection later down the track, AABB's are great for quick culling for proximity, OBB's create better accuracy for your final pass.




#5108620 How to compute the bounding volume for an animated (skinned) mesh ?

Posted by Stragen on 12 November 2013 - 01:11 AM

 

Calculate the bounding volume after the geometry data has been formed and manipulated, if you're basing the bounding volume on the 'at rest' pose or what ever your first keyframe is then you're going to be losing accuracy in the space filled by the volume.

In fact I calculate the AABB in model-space, then I convert it to OBB to transform it in world space, then I calculate the final AABB

 

Why are you calculating two AABB's?

 

The AABB in model space should be the same volumetricly as the OBB, albeit the OBB is translated and rotated to be aligned to the facing of the object, the AABB in world space from the OBB will have large areas of 'empty' space, thereby negating the advantage of calculating an OBB. If your intent is to only ever use Axis Alligned, then calculating an AABB straight up would save you a tonne of time and could be done by calculating the max x,y,z post the scale, translate and rotate for any step in the animation.

 

Just to add something, the image below is what i expect that your concern is.

 

boundingboxexample.png

 

Left hand image is the model at the da Vinci Pose (the T pose), the right hand is the model with its arms up.

 

Your concern, as i understand it, is that your binding box (the black boxes) is not changing from frame to frame.

Am i on the right track?




#5108238 Create a parser for blender.obj file to use in Opengl

Posted by Stragen on 10 November 2013 - 03:02 AM

I'll disagree with the idea of dropping investigation into writing your own parser, this is IMO and mileage may vary but:

 

Parsing data, and doing it efficiently can be difficult, but the lessons you learn from doing this are invaluable.

 

Learning the tradeoffs between string functions vs char pointer arrays, the costs of vectors vs malloc'd arrays, the various different ways of reading data, and the most important of all, how to accurately benchmark your code, were all major lessons i took away from doing parsing myself that get hidden away in the guts of AssImp and other libraries.




#5108237 How to compute the bounding volume for an animated (skinned) mesh ?

Posted by Stragen on 10 November 2013 - 02:53 AM

Calculate the bounding volume after the geometry data has been formed and manipulated, if you're basing the bounding volume on the 'at rest' pose or what ever your first keyframe is then you're going to be losing accuracy in the space filled by the volume.




PARTNERS