Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
selecting models
Topic Started: Nov 17 2007, 07:19 PM (960 Views)
spiff88
Advanced Member
[ *  *  * ]
im working on an object placement editor like loading models putting where u want them then saving in U3D format, ive come across my first problem selecting the model so u can edit properties im trying to just select the object based on if its in the middel od the screen im not sure how to do this so plaease advice.
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
Please see this post.
That code uses the mouse coordinates and it checks if a specific model is under the cursor, so it should help ;).
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
how am i spposed to use this
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
In the following line of code, you need to replace "ModelID" with the ID of the model object you want to select:
Code:
 
distance=GetDistanceToModel(ModelID,x,y,z+height,dirx,diry);

Then the variable "Clickable" will indicate whether or not that object is under the cursor. If it is, then PointX/Y/Z will give you the coordinates of the point on the model object that the cursor is over (in case you need them to move the object, for example).

Either call this code in the camera Step Event or inside a "with (camera)" statement, if you need to use it in another object event.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
u explained pretty good on what it does but im still confused on how basically check if its selected so while its selected u can move it with the arrow keys and rotate, ect..
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
Well, when you found out (through the variable "Clickable") that the model object is under the cursor, also check if the left mouse button is pressed for example. If that's the case, set a local variable "selected" (or whatever you like) of that object to true. Then when you select another object in the same way, you can set the "selected" variable (of that previously selected model) to false again. And then it's a matter of checking the "selected" variable of each model to see which one is selected.
Alternatively, you could also assign the ID of the selected model itself to a global.SelectedObj variable.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
what about dealing with multiples of the same object, because the only way i figure u can load a model is through one object, so won't it select all the same objects?
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
Then you can either store the ID's of all the instances in an array (or ds_list) and put the following part of the code in a for-loop to cycle through all instances:
Code:
 
for (i=0; i < ModelCount; i+=1)
{
distance=GetDistanceToModel(ModelID[i],x,y,z+height,dirx,diry);
if (distance < 100000)
{
  Clickable=true;
  PointX=x+sin(degtorad(diry))*cos(degtorad(dirx))*distance;
  PointY=y+cos(degtorad(diry))*cos(degtorad(dirx))*distance;
  PointZ=z+height-sin(degtorad(dirx))*distance;
}
else Clickable=false;
}

or you can use that part inside a "with (ModelObject)" statement:
Code:
 
with (ModelObject)
{
ID=id;
with (camera)
{
distance=GetDistanceToModel(ID,x,y,z+height,dirx,diry);
if (distance < 100000)
{
  Clickable=true;
  PointX=x+sin(degtorad(diry))*cos(degtorad(dirx))*distance;
  PointY=y+cos(degtorad(diry))*cos(degtorad(dirx))*distance;
  PointZ=z+height-sin(degtorad(dirx))*distance;
}
else Clickable=false;
}
}

Each instance can have its own local "selected" variable.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
for the last one 2 questions- do i have to setup the id in the model object or does it do it automatically in the code already and with the ID's to have to change those to the object model names(bare with me here, its a little confusing)
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
In the "with ()" version, you only need to replace "ModelObject" with the name of the object. Nothing else has to be changed.
But I forgot to mention that you need to add the following to the top of that code:
Code:
 
var ID;

Otherwise "ID" will not be known inside the "with (camera)" block.

If you are going to click on objects to select them, then it will be more efficient to place the entire code in the Left Pressed Event of the camera (instead of the Step Event). In that case, you can also replace each occurrence of the "Clickable" variable with "ID.selected".
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
i know this question will be a drag but one thing still has got me is that so now know which individual model is clickable based on its id where do i go from there im still confused with how u actually "select" an object based on id when its clicked
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
Okay so now you are able to set the "selected" variable of each object instance, based on whether or not it was clicked upon, right?
The next step is to perform the desired action (rotating, moving, etc.) with only the object that has its "selected" variable set to true. So you have to add a piece of code to an event of an object of your choice that searches for that selected object and performs the action, like this:
Code:
 
with (ModelObject)
{
 if selected
 {
   //perform action here
 }
}

where "ModelObject" once again needs to be replaced with the name of the object.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
no actually making the object selected
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
If the particular object instance has its "selected" variable set to true, then it is selected. It may not be visibly so, or do anything to indicate that fact, but if that's what you want, you have to make it so. And that's achieved by following the advice I gave you in my previous post. You can give it a different color, or make it brighter, change its size etc. using that code.
It's selected in the sense that it has its "selected" variable set to another state (true) than all the other instances (false), so now you have to use that info to manipulate only that instance.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
spiff88
Advanced Member
[ *  *  * ]
ur not getting the question i already how to make it look selected im having trouble understanding how to switch the selected variableto make the model selected u already gave on how to check if its clickable so then what, what do i do next
Offline Profile Quote Post Goto Top
 
Go to Next Page
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply