Is there a way to return more than 1 var from proc?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 11 November 2006   #1
Question Is there a way to return more than 1 var from proc?

Ok I have little problem here and i was wondering.. is there a way to return more than one variable from a procedure?

Let's say we have procedure (that is called from button) that is storing the current Translates, rotates and scale in a 3 different vector[] variables.. What i want those 3 vectors to be visible in other procedure (without calling the first procedure again)... So can i return 3 different vectors??

Other question is.. how i can make one procedure to be executet only once, when showing the UI..

The reason for this is i want a button that can store translates, rotates and scales for all selected objects in a vector[] and those vector[] to be visible in other procedure....

10x

Last edited by instruct9r : 11 November 2006 at 11:53 AM.
 
Old 11 November 2006   #2
you can make your procedure have 3+ vector arguments (that will get returned by reference) like this:

 
 proc myProc(vector $transl, vector $rotate, vector $scale)
 {
	...
	... code that calculates $transl, $rotate etc
	...
	...
 }
 
 proc myCallingProc()
 {
	// cause you declared the vars before the proc, these will get referenced by myProc
   
	vector $tr, $rot, $sc;
	myProc($tr,$rot,$sc);
     
	print $tr;
	print $rot;
	print $sc;
 }
 


hope this is what you asked

salut,
calin
 
Old 11 November 2006   #3
Cool

Thanks but i may not explaining this good...

ok let's say it this way
Is there a way to call a procedure only once and after that only to have access to the values that it returns (from another procedure) without calling it everytime.....
 
Old 11 November 2006   #4
If you want one single procedure to collect these values and you only want to call the procedure one you have a couple of different options.

You could have that procedure store your position, rotation, and scale in 3 different global variables. I wouldn't go for this because in my opinion too many global variables gets messy. That is just my personal opinion though. If it works for you, go for it.

What I would do is have the procedure return a float array where this first three positions in the array are the objects position, the second three rotation, and the last three scale. So if you had an object with the position of 3,4,9, a rotation of 23,89,45 and a scale of 1,1,1. The variable would read 3 4 9 23 90 45 1 1 1.

Or, if you are comfortable working with them, it wouldn't be hard to store the object's transformation matrix.
 
Old 11 November 2006   #5
Yep.. that i was thinking... to store them in a matrix because this way it may be like this

variable[0][3] = translates
variable[1][3] = rotates
variable[2][3] = scales

and this should work fine... BECAUSE i'm planing to have more than one object selected and in the way you explained with the array:
first 3 - translates
second 3 - rotates
third 3 - scales...

that's cool.. but it will be hard to get them back when i need them... i will have to do some weird loop

anyway i fix that thanks for the help
 
Old 11 November 2006   #6
Originally Posted by yashu:

    
    proc myProc(vector $transl, vector $rotate, vector $scale)
    {
   	...
   	... code that calculates $transl, $rotate etc
   	...
   	...
    }
    
    proc myCallingProc()
    {
   	// cause you declared the vars before the proc, these will get referenced by myProc
      
   	vector $tr, $rot, $sc;
   	myProc($tr,$rot,$sc);
        
   	print $tr;
   	print $rot;
   	print $sc;
    }
    


i don't think you can pass references like this - you'll need an array to get them to pass:


    proc myProc(vector $transform[])
    {
   	...
   	... code that calculates the $transform
   	...
   	...
    }
    
    proc myCallingProc()
    {
   	// cause you declared the vars before the proc, these will get referenced by myProc
      
   	vector $trans[];
   	myProc($trans);
 
 	print $trans;
  }
    


-sunit
__________________
hydralab
machine film
 
Old 11 November 2006   #7
return type as array or matrix

I suggest to return an array or matrix and give this values in a second global variable (array or matrix as well, same size etc) and call your function in terms of changes of its parameters.
The "dirty-plug" feature is only accessible in API- programming, cause only there you can set references and pointers and the algorithm is only accessible there as class. This is to update your function, node, etc automatically when you change any linked (plugged) value.

hope this helps

r1i
 
Old 11 November 2006   #8
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:09 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.