Move stuff, Save positions, Move again, then Move back to saved positions...

Blitz3D Forums/Blitz3D Programming/Move stuff, Save positions, Move again, then Move back to saved positions...

hollifd(Posted March) [#1]
What am I doing wrong here? I need to be able to move stuff around on the screen, save the positions X, Y, Z, Pitch, Yaw, and Roll in a Type field. Then I need to loop back thru the Type field and have my stuff move back to the saved positions. I am having troubles with the Pitch, Yaw, and Roll. Not all of the models are rotating to the saved positions and I am not sure why. Can anyone see what I am doing wrong?

Below is some example code. I can provide more if it helps.




TomToad(Posted March) [#2]
Why do you have Exit near the bottom? With that, you will only move one entity, then exit the For/Each loop and not process any more entities.


hollifd(Posted March) [#3]
My thinking is that once I find the entity that I want to change, I can exit the loop to save time searching for entities that I don't intend to change.

Basically, this program is not a game. I am simulating a machine that bends sheet metal. The user positions sheet metal parts, tooling, and machine stops at certain locations for each bend that is on a sheet metal part. Once the user has set all of these things for each bend, I want to provide a way for the user to "replay" all of the positions, one at a time to see his work. Once satisfied, the user can output all of these positions and I will write some code to take these positions and format a file that will be used to run the actual machine on the shop floor to make the parts.

I think this is a creative way to use Blitz3D. I have something wrong that is causing my "part" not to rotate to the correct orientation when I replay the steps. I am sure it is something simple. I just have not found the problem yet. I am not a programmer. I am just trying to improve the operations in my shop to attempt to get more done in the day with less effort.

Thanks,
David


Floyd(Posted March) [#4]
Perhaps parent/child relationships are getting confused. That's vague but I can't think of anything else.


hollifd(Posted March) [#5]
OK. I'll have another look. I am sure that I have something simple messed up. Just can't find it right now. I have a bunch of code junked together without a lot of organization. I have been coming up with ideas, writing some code and testing. I need to take some time to clean up my code and simplify things a bit. I'll walk away for a while, relax and come back to this problem later.

Am I thinking about this correctly? I want to allow the user to move things around however he wants. Then, I want to allow the user to "SAVE" all of these positions. To save, I am looking at each object, getting the X, Y, Z, Pitch, Yaw, and Roll values for each object and storing them. Later, I can ask the user what "STEP" he wants to view. Then, I look for this "STEP" in my TYPE data and move everything back to the X, Y, Z, Pitch, Yaw, and Roll locations. That should work...right?


RemiD(Posted March) [#6]
This may help :
http://www.blitzbasic.com/codearcs/codearcs.php?code=2944
(old code !!!)


hollifd(Posted March) [#7]
I am having the same problem with your code RemiD. I have something messed up. I am not sure if it is helpful or not without my models but I am listing my entire code below if anyone has the patience to find the needle in my haystack.

It is a little embarrassing to show my ugly code and lack of knowledge but I cannot find the problem. The problem is when I save the "part" object locations and then try to move the "part" back later, the part does not go back to the same rotation and I cannot see how to fix it. Seems like a simple thing to do but my code or logic has a mistake somewhere. Thanks to anyone for having a look.




Floyd(Posted March) [#8]
I quickly gave up on the full code, except for the definition of BendData.
You want to save information about each mesh at many steps. Simplified code looks like this.
Type BendData
	Field Entity	;Mesh
	; many fields omitted
	Field PartX#	;PartX
	Field PartY#	;PartY
	Field PartZ#	;PartZ
	Field PartPitch#;PartPitch
	Field PartYaw#	;Partyaw
	Field PartRoll# ;PartRoll
End Type


	;let's save the current step...S key

		For b.BendData = Each BendData
				; more code omitted
				b\PartX# = EntityX#(part)
				b\PartY# = EntityY#(part)
				b\PartZ# = EntityZ#(part)
				b\PartPitch# = EntityPitch#(part)
				b\PartYaw# = EntityYaw#(part)
				b\PartRoll# = EntityRoll#(part)
		Next

The For loop iterates over all the BendData types. But it does exactly the same thing for each one because part never changes inside the loop.
If I understand this you should be saving the current configuration for each entity by doing something like
				b\PartX# = EntityX#( b\Entity )				
				b\PartY# = EntityY#( b\Entity )  ; etc.



hollifd(Posted March) [#9]
When I save the positions of my "part", I am checking that the XYZPitchYawRoll values that I print to the screen match what I am storing in my TYPE fields. They match.

When I run the code to put my "part" back to the saved positions, the "part" XYZPitchYawRoll values that I print to the screen do not match the saved values.

I believe I am saving the values correctly but the code to move my "part" seems to have a problem. The other objects seem to work just fine. It seems only the "part" object is not working.

My saved Pitch is -90
My saved Yaw is -180
My saved Roll is 180

After running my simulateit code which should move the part back to the positions above is moving the part to the following positions...

My saved Pitch is -90
My saved Yaw is 180
My saved Roll is -180



Something in this code...
		If SimulateIt = 1 Then
			For b.BendData = Each BendData
				If b\SEQ% = CurrentStep% Then
					;NewXL# = (Float(b\XL$)  + Float(b\FO$) + Float(b\LGA$)) - XLeft#
					NewXL# = b\XL# - XLeft#
					XLeft# = XLeft# + NewXL#
					TranslateEntity LeftGageAssembly, 0, 0, NewXL#, True
					TranslateEntity LeftGageTower, 0, 0, NewXL#, True
		
					;NewXR# = (Float(b\XR$) + Float(b\FO$) + Float(b\RGA$)) - XRight# 
					NewXR# = b\XR# - XRight# 
					XRight# = XRight# + NewXR#
					TranslateEntity RightGageAssembly, 0, 0, NewXR#, True
					TranslateEntity RightGageTower, 0, 0, NewXR#, True
					
					NewZL# = b\ZL# - ZLeft#
					TranslateEntity LeftGageAssembly, NewZL#, 0, 0, True
					TranslateEntity LeftGageTower, NewZL#, 0, 0, True
					TranslateEntity LeftGageBase, NewZL#, 0, 0, True
					ZLeft# = ZLeft# + NewZL#	
									
					NewZR# = b\ZR# - ZRight#
					TranslateEntity RightGageAssembly, NewZR#, 0, 0, True
					TranslateEntity RightGageTower, NewZR#, 0, 0, True
					TranslateEntity RightGageBase, NewZR#, 0, 0, True
					ZRight# = ZRight# + NewZR#
		
					NewRL# = b\RL# - RLeft#
					TranslateEntity LeftGageAssembly, 0, NewRL#, 0, True
					RLeft# = RLeft# + NewRL#	
									
					NewRR# = b\RR# - RRight#
					TranslateEntity RightGageAssembly, 0, NewRR#, 0, True
					RRight# = RRight# + NewRR#
	
	
					DebugLog b\PartX#
					DebugLog b\PartY#
					DebugLog b\PartZ#
					DebugLog b\PartPitch#
					DebugLog b\PartYaw#
					DebugLog b\PartRoll#
					PositionEntity Part, b\PartX#, b\PartY#, b\PartZ#
					RotateEntity Part, b\PartPitch#, b\PartYaw#, b\PartRoll#    ;I believe something here is not working correctly, my part rotations are not getting back to my saved values
					
					SimulateIt = 0
					Exit
					
				End If
			Next
		End If




Floyd(Posted March) [#10]
Pitch = -90 or +90 can be problematic due to gimbal lock.

But is there really any problem here? +180 and -180 are two different names for the same angle. They both mean "half way around".


hollifd(Posted March) [#11]
All I know is...
I move my part to any location on the screen and I display the positions of the part on the screen as I move it around. I save the positions. Then I replay the positions and my part rotates to a new rotation... but it should not. Each time I save the step and replay it, the part rotates a little bit to a new rotation. Most of the time, the part seems flipped 180 degrees.

I feel bad keeping this post alive. I'll eventually figure out what is wrong. I just wanted to make sure my logic/goal is good...that I should be able to move stuff around, save all of the positions to a file or to a TYPE field(s) and then replay those positions whenever I want by searching for the "position" I want to replay and then position / rotate each object that I want to replay.


hollifd(Posted March) [#12]
OK. I stripped everything from my code except the bare basics and it now seems to work correctly. So I have something interfering and causing my troubles in my code. Thanks to everyone for looking at this. I'll get it figured out from here.

Thanks again,
David


RemiD(Posted March) [#13]
@hollifd>>try to use debuglog() to see what the get/saved/loaded/set pitch/yaw/roll values are, if i remember correctly, the yaw is between -180.0 and +180.0 but the pitch or the roll (i don't remember which one) is limited between a higher minimum value and a lower maximum value (which is confusing, i agree)

Also make sure that you use "true" for the last parameter of entityx(), entityy(), entityz(), entitypitch(), entityyaw(), entityroll(), positionentity(), rotateentity() so that the entity is not affected by the position/orientation of its parent.
http://www.blitzbasic.com/b3ddocs/command.php?name=EntityX
http://www.blitzbasic.com/b3ddocs/command.php?name=EntityPitch
http://www.blitzbasic.com/b3ddocs/command.php?name=PositionEntity
http://www.blitzbasic.com/b3ddocs/command.php?name=RotateEntity


hollifd(Posted March) [#14]
RemiD,
Thanks. I have it working much better now. Not sure what was wrong but after removing most of the code and starting over again, it is working much better now. I am rocking and rolling again. Thanks for hanging in there with me. I appreciate it.