SetPosition from Cursor, slow!!! (on bottom half of screen)

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
2camjohn2

SetPosition from Cursor, slow!!! (on bottom half of screen)

Post by 2camjohn2 »

In my program there is a drag and drop feature which allows you to drag objects from the 2d library on to the 3d world.

It is a simple method that is called during the main loop, it uses getRayFromScreenCoordinates and a triangle selector to determine where, on the floor the mouse is pointing, then calls the setPosition method to put the object in the right place.



My problem is:

When dragging objects into the top half of the screen it is perfect.
But when I drag into the bottom half of the screen it becomes very jerky and unresponsive to the position of the mouse.




I cant think what is causing this problem, nevermind how to fix it. I dont see how the results returned from getCursorPosition (ie the Y value of the cursor) can affect the speed of the calculations for setting the position of a model in 3d space.

Any help would be greatly appreciated...

Thanks in advance,
John
Guest

Post by Guest »

maybe do:

OnMouseButtonDown-->Select Object

Drag to location

OnMouse ButtonUp--> Perform computations and drop object
2camjohn2

Post by 2camjohn2 »

That is pretty much what I am doing.

My drag and drop methods appear to be working fine.


My problem is with the drag method, which checks to see if a component is selected, and if it does it positions a node, which represents that component at the point on the floor in 3d world where the mouse is pointing.

I am thinking it is a 3d maths issue related with calculating the ray, or where it hits the floor that is the problem.

But I am really stuck for ideas so thanks alot for helping.

John
2camjohn2

Post by 2camjohn2 »

EDIT

In the above post, I meant to write "my select and drop methods appear to be working fine". My drag method, clearly isnt.

Thanks again
John
Guest

Post by Guest »

To put it another way:

Select Object

Do not drag object-- move mouse

Position object at new location.

Like point and click.

Maybe if you had provided some clue as to how you are
doing this or at the least a visual aid, you would have gotten better
answer to your question.
Guest

Post by Guest »

Hi

Sorry I thought I was being perfectly clear on what I am doing.






This code is executed between beginScene and endScene if the user is dragging the model in the 3d world.

Code: Select all

	
void dragModel()
	{

		//create a ray, from the camera through the cursor into the scene
		cpos = cursor->getPosition();

		line3d<f32> trace = colManager->getRayFromScreenCoordinates(cpos);
		vector3df intersection;
		triangle3df tri;

		if (colManager->getCollisionPoint(trace, tris, intersection, tri))//if line collides with a triangle
		{

			if (node)//if node is already drawn
			{

				node->setPosition(vector3df(intersection.X,0,intersection.Z));

			}
			else
			{
				switch(componentNumber)
				{
					case 0:
						{
							mesh = smgr->getMesh("mesh1.3ds");
						
						}
						break;
					case 1:
						{
							
							mesh = smgr->getMesh("mesh2.3ds");
						}
						break;
					case 2:
						{
							
							mesh = smgr->getMesh("mesh3.3ds");
						}
						break;
				}

				
				node = smgr->addAnimatedMeshSceneNode( mesh );



				node->setMaterialTexture( 0, driver->getTexture("../../media/can.bmp") );

			}
		}

	}

I hope that helped
2camjohn2

Post by 2camjohn2 »

oops that post above was me...
2camjohn2

Post by 2camjohn2 »

Can anyone find a problem in my code??

Surely its not a bug in the engine!!! :roll: :roll: :roll:
Mike

Post by Mike »

Presumably the terrain is displayed in the bottom half of the screen? If so, then it's probably choking trying to the collision detection every frame.
2camjohn2

Post by 2camjohn2 »

The terrain is displayed on the entire screen not just the bottom half. (apart from a small toolbox window which can be positioned anywhere on the screen)

Dragging the object is perfectly smooth on the top part of the screen, however when the object being dragged is in the bottom half of the screen it is unacceptably jerky.



I cant see any way to do this where collision detection is not done every frame, as I need to know whether the mouse pointer is over the terrain or not.


I dont understand why its perfectly fine when the mouse is in a certain position and then extremely slow when the mouse is in another position.
Mike

Post by Mike »

What resolution is Irrlicht running in? Have you tried different resolutions? What hardware are you running on? What graphics card are you using?
Mike

Post by Mike »

If you have any Windows binaries I could download, I could try to run them on my super-duper PC in a few days and see if I get the same problem.
2camjohn2

Post by 2camjohn2 »

Thanks for the help Mike,

I am running an AMD Athlon XP 1800 1 gig of ram and Gefore Ti 4400


I have just compared 1024x768 in 32million colours with 800x600 in 16 million colours and they are both equally jerky (in certain places, while smooth in others).



The thing that gets me is that in some places on the screen it is perfectly smooth, in others very laggy. This suggests to me that it is a bug in the code not a performance issue.

However I am an irrlicht newbie that is why I look to this forum for guidance.
I check this post every couple of hours hoping someone has responded, because I do not know what to do about this problem.

Thanks
John
Mike

Post by Mike »

How about compiling with debug and using a profiler? It may show where the performance hit is - be it in the Irrlicht library or in your code.

Without trying the exes and seeing the problem, I'm at a loss as to what may be wrong. Wish I could be more helpful. :(
2camjohn2

Post by 2camjohn2 »

Mike,

It appears as though my compiler doesnt support profiling.

I am just looking for another one now..




Failing that I will make an exe and put it on here.

Thanks for the response
John
Post Reply