Notifications
Clear all

[Closed] Realtime feedback

Hey all,

I was wondering if someone could explain how to make raltime feedback happen on this little code snippet:


p1=$point001
p2=$point002
mydist=distance  p1 p2
$cone001.height=mydist

Basically i want the cone height to change anytime mydist changes. So if the user moves either point the mydist will update and change the height of the cone.

Thanks in advance…

9 Replies

Assuming you already have nodes in your scene named point001, point002 and cone001…

(
	p1=$point001
	p2=$point002
	theCone = $cone001

	htCtrl = float_script()
	htCtrl.addNode "point1" p1
	htCtrl.addNode "point2" p2
	htCtrl.addNode "cn" theCone

	htCtrl.SetExpression "(distance point1 point2)"
	theCone.height.controller = htCtrl
)

it’s not necessary to add the cone itself.

also it’s good to check that both points still a valid node. other case when you delete one of them the script controller throw an error.

Thanks for the help guys!

1 Reply
(@raytracer05)
Joined: 11 months ago

Posts: 0

No problem.
Denis is absolutely right on both counts though. I should be more careful when copying and pasting snippets.

Okay…thanks again for the help…but i think i’ve gone as far as i can with this script with my limited skills. I’ve somehow broken the script and i can’t figure out whats wrong. The script is as follows:


    (
    global BulletTrajectory_Dialog
    try(destroyDialog BulletTrajectory_Dialog)catch() --builds the dialogue box and tests to see if there is one open already
    	
    /*	DESCRIPTION:
    	-This script is designed to help visualize bullet trajectories and the error associated with them.  
    	VERSION:
    	-Version 0.11
    	AUTHOR:
    	-Dwayne D. Ellis
    	DATE:
    	-24/11/2012	
    */
    	
    rollout BulletTrajectory_Dialog  " BulletTrajectory | V 0.12"  --builds the rollout 
    (
    	group "RIG CREATION:"
    			(
    		
    				label cb_lbl1 "Create Bullet Trajectory Rig:" align:#left
    				button cr_button "CREATE"  width:100 height:36 align:#center toolTip: "Creat the Bullet Trajectory Rig."	enabled: true
    				
    				on cr_button pressed do
    					(
    						-- layer setup--
    						layer2 = layermanager.getlayer 1
    						layer2 = layermanager.newLayerFromName "Bullet Trajectory Rig"
    						layer2.showfrozeningray=false
    						layer2.isfrozen=false
    						layer2.wirecolor= blue
    						layer2.current=true
    						-- layer setup--
    						
    						-- control point setup--
    						bo_point =  Point pos:[0,0,0] isSelected:on  name: "Bullet_Impact_CTRLPoint" size: 2.5 centermarker:true box:true wirecolor: green		--bullet origin control point
    						bi_point =  Point pos:[5,0,0] isSelected:on  name: "Bullet_Origin_CTRLPoint" size: 2.5 centermarker:true box:true wirecolor: red		--bullet impact control point
    						-- control point setup--
    						
    						-- trajectory cone setup--
    						traj_cone = Cone pos:[0,0,0] isSelected:on heightsegs: 0 name: "Bullet_Trajectory_Cone" radius1: 0.0 radius2: .75  wirecolor: gray 
    						$.rotation.controller = LookAt_Constraint ()
    						$.rotation.controller.constraints.appendTarget bi_point 50.0
    						$.parent = $Bullet_Origin_CTRLPoint
    						$.rotation.controller.viewline_length_abs = off
    						$.rotation.controller.target_axis = 2
    						$.rotation.controller.upnode_axis = 1
    						$.rotation.controller.StoUP_axis = 1
    						-- trajectory cone setup--
    						
    						-- distance calculation from points --
    						(
    							
    							htCtrl = float_script()
    							htCtrl.addNode "point1" bo_point
    							htCtrl.addNode "point2" bi_point
    							htCtrl.addNode "cn" traj_cone
    							htCtrl.SetExpression "(distance point1 point2)"
    							traj_cone.height.controller = htCtrl
    						)
    						-- distance calculation from points --
    					
    						cr_button.enabled = false  --disable the button
    					)
    			)
    			
    	group "RIG CONTROLS:"
    			(
    		
    				spinner BO_spin "Impact Radius:" range:[0.0,1.0,0.0] type:#float tooltip: "Bullet Origin"  indeterminate: false 
    				spinner AE_spin "Origin Angle Error:" range:[0,90,0] type:#integer tooltip: "This value represents the Impact Angle Error:"  indeterminate: false
    				label rad2lab "Origin Error Radius:"style_sunkenedge:false width:95 height:16	align:#right	across: 2	
    				label rad3lab "radius2"style_sunkenedge:true width:92 height:16	align:#left
    				
    				on BO_spin changed val do
    					(
    						rcont1=traj_cone.radius1.controller
    						traj_cone.radius1 = BO_spin.value
    					)	
    					on AE_spin changed val do
    					(
    						the_height = distance bo_point bi_point
    						rcont2=traj_cone.radius2.controller
    						traj_cone.radius2 = (tan AE_spin.value) * the_height/2
    					)
    
    			)
    			
    	group "HELP:"
    		(
    			button get_btnhelp "HELP" width:100 height:40 align:#center toolTip: "Click for help."
    			on get_btnhelp pressed do
    			(
    			messageBox "| Description |

 -This script generates a bullet trajectory rig that helps visualize the origin angle error.

| General Usage | 

 -Click the create button to generate the rig. 
 -Move the control points to the bullet origin and impact positions, respectively. 
 -Adjust the Rig Control spinners to suit." title: "Bullet Trajectory | HELP"  beep: true
    			)	
    	)
    group "about:"
    	(
    		
    		label ab_lbl1 "Dwayne D. Ellis" align:#center
    		HyperLink homepage "www.dwayne-ellis.com" address:"http://www.dwayne-ellis.com" color:(color 0 18 64) hovercolor:(color 255 90 0) visitedcolor:(color 255 153 51) align:#center
    		
    	)	--end of third group
    )
    createDialog BulletTrajectory_Dialog width:235 style:#(#style_SysMenu, #style_ToolWindow) --removed the height, so as you add controls, it grows automatically
    )
    

Basically, its just supposed to update the two radii of the cone when the spinners change. I had it working, not quite sure why it isn’t now. I want to have the traj_cone.radius2 show up in the sunkenedge label as well…not sure how to do that. Actually there is a lot i would like to do with the script…mostly as a learning tool but i want to get it working first.

Thanks again for all the help…

Is this what you are trying to do?

 (
    global BulletTrajectory_Dialog
    try(destroyDialog BulletTrajectory_Dialog)catch() --builds the dialogue box and tests to see if there is one open already
    	
    /*	DESCRIPTION:
    	-This script is designed to help visualize bullet trajectories and the error associated with them.  
    	VERSION:
    	-Version 0.11
    	AUTHOR:
    	-Dwayne D. Ellis
    	DATE:
    	-24/11/2012	
    */
    	
    rollout BulletTrajectory_Dialog  " BulletTrajectory | V 0.12"  --builds the rollout 
    (
		fn getTMFromVector pt1 pt2 =
		(
			local z = normalize (pt2-pt1)
			local y = normalize (cross z [0,0,1])
			local x = normalize (cross y z) 
			matrix3 x y z pt1
		)
		
    	group "RIG CREATION:"
    			(
    		
    				label cb_lbl1 "Create Bullet Trajectory Rig:" align:#left
    				button cr_button "CREATE"  width:100 height:36 align:#center toolTip: "Creat the Bullet Trajectory Rig."	enabled: true
    				
    				on cr_button pressed do
    					(
    						-- layer setup--
    						layer2 = layermanager.getlayer 1
    						layer2 = layermanager.newLayerFromName "Bullet Trajectory Rig"
    						layer2.showfrozeningray=false
    						layer2.isfrozen=false
    						layer2.wirecolor= blue
    						layer2.current=true
    						-- layer setup--
    						
    						-- control point setup--
    						bo_point =  Point pos:[0,0,0] isSelected:on  name: "Bullet_Impact_CTRLPoint" size: 2.5 centermarker:true box:true wirecolor: green		--bullet origin control point
    						bi_point =  Point pos:[5,0,0] isSelected:on  name: "Bullet_Origin_CTRLPoint" size: 2.5 centermarker:true box:true wirecolor: red		--bullet impact control point
    						-- control point setup--
    						
    						-- trajectory cone setup--
    						traj_cone = Cone pos:[0,0,0] isSelected:on heightsegs: 0 name: "Bullet_Trajectory_Cone" radius1: 0.0 radius2: .75  wirecolor: gray
    						
    						-- distance calculation from points --
    						(
    							
    							htCtrl = float_script()
    							htCtrl.addNode "point1" bo_point
    							htCtrl.addNode "point2" bi_point
    							htCtrl.addNode "cn" traj_cone
    							htCtrl.SetExpression "cn.pos = point1.pos
 cn.transform = BulletTrajectory_Dialog.getTMFromVector point1.pos point2.pos
 (distance point1 point2)"
    							traj_cone.height.controller = htCtrl
    						)
    						-- distance calculation from points --
    					
    						cr_button.enabled = false  --disable the button
    					)
    			)
    			
    	group "RIG CONTROLS:"
    			(
    		
    				spinner BO_spin "Impact Radius:" range:[0.0,1.0,0.0] type:#float tooltip: "Bullet Origin"  indeterminate: false 
    				spinner AE_spin "Origin Angle Error:" range:[0,90,0] type:#integer tooltip: "This value represents the Impact Angle Error:"  indeterminate: false
    				label rad2lab "Origin Error Radius:"style_sunkenedge:false width:95 height:16	align:#right	across: 2	
    				label rad3lab "radius2"style_sunkenedge:true width:92 height:16	align:#left
    				
    				on BO_spin changed val do
    					(
    						rcont1=traj_cone.radius1.controller
    						traj_cone.radius1 = BO_spin.value
    					)	
    					on AE_spin changed val do
    					(
    						the_height = distance bo_point bi_point
    						rcont2=traj_cone.radius2.controller
    						traj_cone.radius2 = (tan AE_spin.value) * the_height/2
    					)
    
    			)
    			
    	group "HELP:"
    		(
    			button get_btnhelp "HELP" width:100 height:40 align:#center toolTip: "Click for help."
    			on get_btnhelp pressed do
    			(
    			messageBox "| Description |

 -This script generates a bullet trajectory rig that helps visualize the origin angle error.

| General Usage | 

 -Click the create button to generate the rig. 
 -Move the control points to the bullet origin and impact positions, respectively. 
 -Adjust the Rig Control spinners to suit." title: "Bullet Trajectory | HELP"  beep: true
    			)	
    	)
    group "about:"
    	(
    		
    		label ab_lbl1 "Dwayne D. Ellis" align:#center
    		HyperLink homepage "www.dwayne-ellis.com" address:"http://www.dwayne-ellis.com" color:(color 0 18 64) hovercolor:(color 255 90 0) visitedcolor:(color 255 153 51) align:#center
    		
    	)	--end of third group
    )
    createDialog BulletTrajectory_Dialog width:235 style:#(#style_SysMenu, #style_ToolWindow) --removed the height, so as you add controls, it grows automatically
    )

I’ve deleted your lookat controller and extended the float expression to move and rotate the cone towards the second point. I should also credit Bobo as my getTMFromVector function is based on his post here.

DISCLAIMER
If you are a hitman and are using this to plan your next hit then I will not be an accessory to any charges that you may face.

Haha…not a hitman! This to help visualize bullet trajectories in forensic viz. Actually the cone height seemed to be working fine…its the radius stuff that wasn’t updating. They both throw up errors when changing the spinner value.

Sorry I thought you wanted the cone to fit between the two points.

The reason it was throwing an error is the scope in which the nodes are created is not the same as where you are trying to change their radii. I’m still not absolutely sure how this is supposed to work but declaring the variables local to the rollout solves the scope problem.

(
    global BulletTrajectory_Dialog
    try(destroyDialog BulletTrajectory_Dialog)catch() --builds the dialogue box and tests to see if there is one open already
    	
    /*	DESCRIPTION:
    	-This script is designed to help visualize bullet trajectories and the error associated with them.  
    	VERSION:
    	-Version 0.11
    	AUTHOR:
    	-Dwayne D. Ellis
    	DATE:
    	-24/11/2012	
    */
    	
    rollout BulletTrajectory_Dialog  " BulletTrajectory | V 0.12"  --builds the rollout 
    (
		local traj_cone
		local bo_point
		local bi_point
		
		fn getTMFromVector pt1 pt2 =
		(
			local z = normalize (pt2-pt1)
			local y = normalize (cross z [0,0,1])
			local x = normalize (cross y z) 
			matrix3 x y z pt1
		)
		
    	group "RIG CREATION:"
    			(
    		
    				label cb_lbl1 "Create Bullet Trajectory Rig:" align:#left
    				button cr_button "CREATE"  width:100 height:36 align:#center toolTip: "Creat the Bullet Trajectory Rig."	enabled: true
    				
    				on cr_button pressed do
    					(
    						-- layer setup--
    						layer2 = layermanager.getlayer 1
    						layer2 = layermanager.newLayerFromName "Bullet Trajectory Rig"
    						layer2.showfrozeningray=false
    						layer2.isfrozen=false
    						layer2.wirecolor= blue
    						layer2.current=true
    						-- layer setup--
    						
    						-- control point setup--
    						bo_point =  Point pos:[0,0,0] isSelected:on  name: "Bullet_Impact_CTRLPoint" size: 2.5 centermarker:true box:true wirecolor: green		--bullet origin control point
    						bi_point =  Point pos:[5,0,0] isSelected:on  name: "Bullet_Origin_CTRLPoint" size: 2.5 centermarker:true box:true wirecolor: red		--bullet impact control point
    						-- control point setup--
    						
    						-- trajectory cone setup--
    						traj_cone = Cone pos:[0,0,0] isSelected:on heightsegs: 0 name: "Bullet_Trajectory_Cone" radius1: 0.0 radius2: .75  wirecolor: gray
    						
    						-- distance calculation from points --
    						(
    							
    							htCtrl = float_script()
    							htCtrl.addNode "point1" bo_point
    							htCtrl.addNode "point2" bi_point
    							htCtrl.addNode "cn" traj_cone
    							htCtrl.SetExpression "cn.pos = point1.pos
 cn.transform = BulletTrajectory_Dialog.getTMFromVector point1.pos point2.pos
 (distance point1 point2)"
    							traj_cone.height.controller = htCtrl
    						)
    						-- distance calculation from points --
    					
    						cr_button.enabled = false  --disable the button
    					)
    			)
    			
    	group "RIG CONTROLS:"
    			(
    		
    				spinner BO_spin "Impact Radius:" range:[0.0,1.0,0.0] type:#float tooltip: "Bullet Origin"  indeterminate: false 
    				spinner AE_spin "Origin Angle Error:" range:[0,90,0] type:#integer tooltip: "This value represents the Impact Angle Error:"  indeterminate: false
    				label rad2lab "Origin Error Radius:"style_sunkenedge:false width:95 height:16	align:#right	across: 2	
    				label rad3lab "radius2"style_sunkenedge:true width:92 height:16	align:#left
    				
    				on BO_spin changed val do
    					(
    						rcont1= BulletTrajectory_Dialog.traj_cone.radius1.controller
    						BulletTrajectory_Dialog.traj_cone.radius1 = BO_spin.value
    					)	
    					on AE_spin changed val do
    					(
    						the_height = distance BulletTrajectory_Dialog.bo_point BulletTrajectory_Dialog.bi_point
    						rcont2= BulletTrajectory_Dialog.traj_cone.radius2.controller
    						BulletTrajectory_Dialog.traj_cone.radius2 = (tan AE_spin.value) * the_height/2
    					)
    
    			)
    			
    	group "HELP:"
    		(
    			button get_btnhelp "HELP" width:100 height:40 align:#center toolTip: "Click for help."
    			on get_btnhelp pressed do
    			(
    			messageBox "| Description |

 -This script generates a bullet trajectory rig that helps visualize the origin angle error.

| General Usage | 

 -Click the create button to generate the rig. 
 -Move the control points to the bullet origin and impact positions, respectively. 
 -Adjust the Rig Control spinners to suit." title: "Bullet Trajectory | HELP"  beep: true
    			)	
    	)
    group "about:"
    	(
    		
    		label ab_lbl1 "Dwayne D. Ellis" align:#center
    		HyperLink homepage "www.dwayne-ellis.com" address:"http://www.dwayne-ellis.com" color:(color 0 18 64) hovercolor:(color 255 90 0) visitedcolor:(color 255 153 51) align:#center
    		
    	)	--end of third group
    )
    createDialog BulletTrajectory_Dialog width:235 style:#(#style_SysMenu, #style_ToolWindow) --removed the height, so as you add controls, it grows automatically
    )

here is a way how to do some simple trace (trajectory).


 fn bulletTrace bullet tracePoints:10 offset:1f = 
 (
 	for k=1 to tracePoints collect
 	(
 		p = point name:("tp_" + formattedprint k format:"03d") size:3 wirecolor:yellow
 		c = p.pos.controller = Position_Expression()
 			
 		c.AddVectorNode "pos" bullet offset:(-k*offset)
 	
 		c.SetExpression "pos"
 		p
 	)
 )
 delete objects 
 b = geosphere name:"bullet" radius:1 segments:2 baseType:2 smooth:off wirecolor:blue isselected:on
 pp = bulletTrace b
 

the PRO solution is to use particles.