Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / detection of mouse on side A or B on a cube/block, how?

Author
Message
T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 2nd May 2010 00:25
how can i detect where my mouse is on side A or B or any face of a block/cube?
i tried with this but thats seems not precise enough:



is there some alternative code what i can use? (if there any)

help is appreciated

*happy coding on his 3D Sandbox Editor*
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 2nd May 2010 02:15
I`m not familiar with using vectors but first thing i get in my head was some dummy objects infront of each side of the cube.Plains for example with the same size of cube`s side.You can hide them and check if mouse is on dummy A or dummy B.Also if there is some changes in movement or rotation of the actuall object you need to apply it to dummy objects too.I`m just not sure if there is any build in commands that can tell you witch side you are working with.Possibly there isn`t any.

I`m not suggesting this method for something than can become more and more complicated in time.And there can be better way to do this.

There can be few ways to do the job.What you need really is the way that involves less coding, because it save time, it`s not too complicated and provide much performance.I allways bet on performance, you never knew how much free power you`ll need in future.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 2nd May 2010 13:49
ty, for your quick answer

Quote: "some dummy objects infront of each side of the cube.Plains for example with the same size of cube`s side"


yes thats what i thought too. but then i thought it will be complicated. but if theres no further alternative i have to stick on your idea.

luckily theres no rotation/movement involved.

if theres someone else who think different on it, i really like to hear that too

*happy coding on his 3D Sandbox Editor*
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 2nd May 2010 18:33
You can wait for someone to join here with another idea, but what i think accordingly to what you said that there is no movment or rotation involved is that you can completly abandon the cube and instead build it from plains positioned in such way that they can form it.This can be complicated too, but maybe better way to do the job.What you`ll use the cube for?

Where there is a will, there is a way.
I often edit my posts, that`s who i am
T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 2nd May 2010 20:31
well iam gonna try to explain it:

iam making a editor where you can only click/snap on a blue connector. (you know Construx? thats what my editor is about)
now i can click on a face of a blue connector and not always is the beam positioned on the right position. thats why i try to find a solution for this.



but its not one connector there are many of them. and thats making it complex... and dont know how to solve that.

hope you understand it a little, if not i try it in the next post.

*happy coding on his 3D Sandbox Editor*
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 4th May 2010 01:45 Edited at: 4th May 2010 03:19
I`m not familiar with Construx but maybe get the main idea.You maybe consider on my suggestion, but using many connectors make the task hard and extremely insane.

There is maybe solution.With the plains idea in mind you can make check for object behind the mouse "pick object" involved.If the object is a connector you move plains on it.If your mouse hover on another connector object you move the plains again.This eliminate the need of plains on every connector to exist at any time, but just when they are needed.At any moment you`ll need maximum of 6 plains, assuming you can rotate the camera and view the connector from any angle.

I can try to make a demo, but it`s late now and there is no design of what i need to do in my head.I`ll try prima vista.The real deal tommorow maybe.

EDIT: Try this code to see if it gona work for you like this.
Before compiling it be sure to make 1 image in paint exactly black and if you want you can do it 1x1 pxl.



Where there is a will, there is a way.
I often edit my posts, that`s who i am
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 4th May 2010 04:57


I was sure that would work, but you're right, pick vector doesn't seem to be accurate enough (or is returning the actual location of the object :/) Man... I was bored so I made a program of my own to do this. Whole code:


I guess trying to math this one out would be too annoying. Without using a plugin, I think dummy objects + pick object is the way to do this. I g2g for now but when I get back to my computer i'll try to implement something.


T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 4th May 2010 11:59 Edited at: 4th May 2010 19:42
@luskos

wow nice and simple that should do it, iam gonna try to implement that in my program today. if i get it work/not work i will post it in this thread.


@neuro fuzzy

i try to understand your code, but i dont understand... on the other hand i learned from your code about types and memblocks and some other stuff. maybe i should rewrite some of my code...


EDIT:

luskos, after many trial and error, i got it working now and its working perfectly!

many many thanx to you luskos!

*happy coding on his 3D Sandbox Editor*
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 5th May 2010 02:24 Edited at: 5th May 2010 11:58
It`s normal to work because i design it to be simple.

After i post the code i realised that it`s not actually what i was intended to show you, it`s just not that advanced, but it was too late so i just post it as it is.I wanted to make few cubes which can show you it`s actually working.It was writen with the idea to be plug and play code.

And it`s normal to understand me better than NeuroFuzzy because i think he is more profisient coder and i`m still learning.He is good, really.But his code is somehow complicated, which he must be aware helping to newbies.I think his snippet here is more a show-off than help.This is hobby for me and i realised that i am good enough to enterain myself and help others.

You can still show here your modifications on the code here, i`m curious if you do them the same way i would.



This is finished version of my code.If you strugle to make it work you can still look at it.There is few lines remended and slight changes at positioning of plains arround the cube, just to see them clear because they overlap with cubes when are precisely positioned on each side of it.

It was 5min work, if i wasn`t so tired last night i could save you some time you spend on making it work.

And finally i`m glad to help you!

Where there is a will, there is a way.
I often edit my posts, that`s who i am
T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 5th May 2010 12:05 Edited at: 5th May 2010 12:13
Quote: "After i post the code i realised that it`s not actually what i was intended to show you"


it was enough for me, i had a few ideas, but you completed it.

Quote: "You can still show here your modifications on the code here, i`m curious if you do them the same way i would."


i only changed the CubeX CubeY CubeZ and the others to my own. i really didnt understand why the
was in there so i removed that.

and i change the location of the plains with:



then i use your code:



and then place the beam on the right position:



this was in a few if then else statements so i only show you the important thing.

Quote: "It was 5min work, if i wasn`t so tired last night i could save you some time you spend on making it work."


no problem, i learn the most of trial and error

*happy coding on his 3D Sandbox Editor*
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 5th May 2010 12:16
Quote: "complicated, which he must be aware helping to newbies.I think his snippet here is more a show-off than help."


I got carried away... I meant to have a function that found which side of the cube it was on, and then make a separate system... but then the code kinda became too engrained with the other code and... meh. Still, I got it working, if you want to take a look at the code:



But you might want to ignore that. Actually... some of it is unnecessarily over-complicated. I think here's a great way to do what you want, and it's what the code I wrote uses:
1. create six planes around the connector cube (one on top, bottom, sides, whatever, with corresponding rotation
2. hide the connector cube
3. use pick object, and find which plane the mouse is clicking
4. now you know which plane it is, use it's direction to build another connector in that direction
5. delete the six planes, and show the connector cube.

All the complications in my code rise from finding the cube's direction, and building another connector in that direction. I just like using funny data structures for some reason... it's mainly to avoid writing the same thing over again (like large chunks of code similar but with a couple values changed).

I think I'm going to tidy up my code a lot... Maybe try and write a tutorial of it, actually. I feel unhelpful

Oh right, the giant weird array lookup things in the do loop in my code is just there because I didn't want to make six, just three... so I did a bunch of weird stuff to determine the direction. Totally unnecessary.

Quote: "maybe i should rewrite some of my code..."

the types and memblocks stuff I was using isn't necessary... as long as you're using arrays, or something that can be expanded to multiple objects, you're good ta go!


T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 5th May 2010 12:49
Quote: "as long as you're using arrays, or something that can be expanded to multiple objects, you're good ta go!"


ehm, to be honest, i dont use arrays... maybe some of my code is long, but i understand it. maybe later on, if i am what more experienced i will rewrite some of it. its a learning process what never stops.

*happy coding on his 3D Sandbox Editor*
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 5th May 2010 16:39
For example:


What this line do in my code is to position the left side of the cube(which is the left relative to point of view, you can say it`s right side if the camera was at oposite direction, whatever)

position object is clear i think, so the CubeX is the x position of the connector, CubeY and Cube z are y and z positions.

I made CubeSize with the idea that you may need diferent size connectors, so multiplying of CubeSize by .5 we position the plain exactly on the cube`s side no matter how big it is.If this was missing the plain is positioned at center of the cube.The name maybe is not most proper, because just Size sounds better and it can be easly linked to plain size too.I do not use divide by 2 because as i know it`s slower, but it would be the same.-1 after all this is just for test purpose, because plains overlap with the cube sides if they are exactly on them there is no problem to remove it.Because you actually may not need plains visible anyway.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
T4r4ntul4
14
Years of Service
User Offline
Joined: 1st Jan 2010
Location: close to my pc
Posted: 5th May 2010 18:44
ok ty that cleared up

*happy coding on his 3D Sandbox Editor*
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th May 2010 23:21
I just sorta skimmed the thread but I think you can just find th dot product of your point of interest with th normal of th side you're checking. A positive value is one side, a negative value means its on the other side. Not sure if this helps but maybe it'll start a solution.


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 7th May 2010 01:37
it's not just one side that's the problem though, it's all six sides of a cube, and get pick vector doesn't seem to be accurate enough (or something) to check with maths.


luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 7th May 2010 01:47 Edited at: 7th May 2010 01:48
Phaelax don`t skimm it he have the solution with the 6 dummy plains now.Look my post above from 4th there is the code.It`s not something advaced, but it`s good workaround i think.

Where there is a will, there is a way.
I often edit my posts, that`s who i am

Login to post a reply

Server time is: 2024-09-28 16:25:34
Your offset time is: 2024-09-28 16:25:34