Jump to content

  • Log In with Google      Sign In   
  • Create Account

Stragen

Member Since 18 Jun 2012
Offline Last Active Oct 28 2014 01:54 PM

Topics I've Started

RayPicking

21 August 2014 - 10:27 PM

Hello, Hoping that someone can give some guidance...
void MouseRayPicker(){
	//method 1, not sure if working.
	GLint viewport[4];
	GLdouble modelview[16];
	GLdouble projection[16];
	glGetIntegerv(GL_VIEWPORT, viewport);
	glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
	glGetDoublev(GL_PROJECTION_MATRIX, projection);

	// obtain the Z position (not world coordinates but in range 0 - 1)
	GLfloat z_cursor;

	glReadPixels(cursorPos.x, cursorPos.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z_cursor);

	// obtain the world coordinates
	GLdouble x, y, z;
	gluUnProject(cursorPos.x, cursorPos.y, z_cursor, modelview, projection, viewport, &x, &y, &z);
	

	fprintf(stdout, "Cursor target: %f, %f, %f .\n", x, y, z);
}
I'm using the above for generating a ray for picking objects in world space. At this time, i'm seeing the numbers generate ok when the cursor is precisely in the center of the screen, but if the cursor position changes as all the numbers go into large values that dont make a great deal of sense. (600,429,-560 for example) Can someone suggest where i'm going wrong?

Event/Action Management

18 August 2014 - 06:14 AM

I'm currently considering how i might approach a parameter based event management system.

 

My aim is to build it such that the actions that are executed on a particular event are able to be dynamic. This would essentially extend the event system that is used for input control, however my aim is to use a lot less case statements.

 

My initial thought was to build up a couple of string based maps so that parameters may be allocated against events, for example:

 

map<string,string> actionMap;

map<string,function> FunctionMap;

 

actionMap["onCollision"] = "doDestroy"

FunctionMap["doDestroy"] = <pointer reference to function to execute for destroying an object>

 

allowing for other parts of the code to call,

FunctionMap[ActionMap["onCollision"]](<object reference>);

 

I've already encountered some pitfalls with this approach, particularly the catches with using function pointers, and void* variables, and was curious to see what other people were doing in this kind of case?

 

Is there any real advantage in doing this compared to say, case statements against variables? Noting I'm hoping to have a few thousand objects at a time.

 


Container Selection

21 December 2013 - 04:50 PM

Just after some opinions,

 

I have a 2 element structure that I need to store, and am trying to consider the options available, and am not sure which approach i want to take, hopefully staying within the STD libraries.

 

The information being stored is a string name with an associated matrix. It needs to be searchable, but also referenced by index.

 

So far:

I've implemented this using a MAP, keyed by the string name, the search-ability is brilliant, however the need to access the index has come up.

 

I'm considering a struct based vector with searcher function, though i'd really like to avoid this if there is a more elegant solution available in library.

I've considered a list, however, the data needs to be randomly referenced, and when the index is already known i dont want to have to scan the entire list to get to the last reference (could be well over 5k references). Sets suffer from the same issue as maps, and arrays aren't intrinsically searchable or as expandable as i'd like.

 

I'm expecting that i'm not going to be able to avoid the Struct-Vector with search off the side, but if anyone has another idea, i'm all ears.

 

 


Collada Bone Matrix / Baked Transform Matrix

10 September 2013 - 06:28 PM

I've a quick query,

When looking at the visual_scene nodes within a typical DAE file, are the matrices referenced relative to the previous bone? or are they relative to the origin?

eg:
<node id="astroBoy_newSkeleton_deformation_rig" name="deformation_rig" type="NODE">
        <matrix>1 0 0 -0.33707 0 1 0 -0.127721 0 0 1 0 0 0 0 1</matrix>
        <node id="astroBoy_newSkeleton_root" name="root" sid="Bone1" type="JOINT">
          <matrix sid="transform">0.079633 -0.996824 0 0 0.992539 0.079291 -0.092624 0.057089 0.092329 0.007376 0.995701 2.6942 0 0 0 1</matrix>
          <node id="astroBoy_newSkeleton_spine01" name="spine01" sid="Bone2" type="JOINT">
            <matrix sid="transform">-0.915962 -0.140877 0.375723 0 0.152015 -0.988378 0 0 0.371356 0.057115 0.926732 0.460646 0 0 0 1</matrix>
Rig is the origin, root is a transform from the origin, spine01 is a transformation from the root?

or each a transformation from the origin?

Feedback - Benchmarking XML Reading

29 July 2013 - 05:00 AM

Guys and Girls,

 

Looking for some feedback on a XML reader that i've thrown together, simply put, it reads the file in, verbose, and using vectors recreates the structure of the XML file into memory, which can then be searched...

 

I am using a COLLADA file as a benchmark, particularly the larger of the two files contained in the rar at this location: http://www.wazim.com/Downloads/AstroBoy_Walk.rar, for clarity purposes using astroBoy_walk_Max.DAE.

 

The file is 1.5mb decompressed, comprises of ~14000 lines of xml structured data.

 

Currently based on my basic benchmarking, i'm reading the file and creating the structure in, on average 9.5 seconds, i feel this is too slow especially if i plan to read in a number of these files... to be fair though this is a marked improvement over my first effort that took on average 45 seconds to read the same file.

int PopulateNode(std::string fC){
		//get line
		int lStart = 0, lEnd = 0, tagsOpen = 0;
		std::vector<XMLNODE*> nodeStack;
		nodeStack.push_back(this);
		while(((lStart = fC.find_first_not_of(" ", lStart)) != -1) && ((lEnd = fC.find("\n", lStart)) != -1)){
		//do{
			//lStart = fC.find_first_not_of(" ", lStart);
			//lEnd = fC.find("\n", lStart);
			std::string curLine;

			curLine = fC.substr(lStart,lEnd-lStart);
			
			if (curLine.at(0) != '<'){
				//no open tag found, but there is data on the line... approach as though elements of the node.
				nodeStack.back()->elements.push_back(XMLELEMENT("value",curLine.substr(lStart, lEnd - lStart- 1)));
			}else{
				switch (curLine.at(1)){
				case '/':
					{
						//close tag
						std::string closetag;
						nodeStack.pop_back();
						tagsOpen--;

						break;
					}
				case '?':
					{
						//question mark found
						std::string qnMark;

						break;
					}
				default:
					{
						//not closed/not question
						int bSBoundS = 0;
						int bSBoundE = curLine.find('>', bSBoundS);

						std::vector<std::string> tempStrVec = SubStrDelim(curLine.substr(bSBoundS+1, bSBoundE-bSBoundS-1),' ');

						std::string closeTag = std::string ("</").append(tempStrVec.at(0));
						std::string selfClose = "/>";

						if(!nodeStack.back()->nodeType.empty()){
							nodeStack.back()->childNodes.push_back(XMLNODE());
							nodeStack.push_back(&nodeStack.back()->childNodes.back());
						}

						nodeStack.back()->nodeType = tempStrVec.at(0);
						
						
						if (tempStrVec.size() > 1){
							for(int i=1; i<tempStrVec.size();++i){
								nodeStack.back()->elements.push_back(XMLELEMENT(tempStrVec.at(i)));
							}
						}


						int closeTagPos = curLine.find(closeTag);
						int selfCloseTag = curLine.find(selfClose);

						if(closeTagPos != -1){
							nodeStack.back()->elements.push_back(XMLELEMENT("value",curLine.substr(bSBoundE+1, closeTagPos-bSBoundE-1)));
						}

						if((closeTagPos == -1) && (selfCloseTag == -1)){
							//no close tag on line.
							nodeStack.back()->childNodes.push_back(XMLNODE());
							nodeStack.push_back(&nodeStack.back()->childNodes.back());
							tagsOpen++;
						}else{
							nodeStack.pop_back();
						}

						break;
					}
				}
			}
		
			lStart = lEnd +1;
		}//while(lStart < fC.size() && lEnd != -1);

		return 0;
	}

In this case the input is a Char* / std string from a full file read to memory.

 

I appreciate this might not be the most tidy, or error safe code, i'm working on getting it reading first then adding in some error trapping as i'm using the errors (if any are generated) to stop me in my tracks as i'm doing this rapid style.

 

To head off questions of "why not use a library out there?", i'm using this as a learning experience, and would like to learn ways of improving my own code over using someone elses...

 

So i'd like to ask for some C&C, pointers, or even just an idea on how long it takes others to read in this same file to see if my expectations are being unfair.

 

Thanks.


PARTNERS