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 / Help on getting a cube to rotate correctly

Author
Message
Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 10th Feb 2004 02:28 Edited at: 10th Feb 2004 03:06
Hey everyone. I need some help here. I've set up some code to make a cube rotate, following the mouse. Basically, it's similar to a turret. Later, i'll add some code to make the cube fire bullets. The cube will face the same direction the mouse faces, and thus, you can aim by putting the mouse over the target. But i'm having some trouble. The cube seems to bob itself every time i try to move in certain locations, and when you face certain directions, it wont aim correctly

The code is in DBP

Controls:
Move the mouse around the screen to move the cube
Move the mouse to the edge of the screen to scroll around.

If anyone could help me, or explain the reason why this is occuring, your help would be greatly appreciated.

Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 11th Feb 2004 02:23
*bump* is there noone there to help me?
theDK
20
Years of Service
User Offline
Joined: 20th Jan 2004
Location:
Posted: 11th Feb 2004 02:48
a quick tip ... I'm a newnie so don't expect much of me in terms of coding ...
There is the facedemo that comes with DBP and it seems it could help with what you want ...
C:\Program Files\Dark Basic Software\Dark Basic Professional\Projects\FaceDemo
take a look at the code ... bye
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 11th Feb 2004 07:48
This looks like a mathematical issue to me.

I think I can help with this but because I have friends staying with me at the moment I won't have time to help until they leave at the weekend. If you don't mind waiting until Sunday, and assuming nobody else intervenes in the meantime, I'll look at this in detail then.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 14th Feb 2004 06:22
Thanks! Anyways... i've figured out the problem, but i dunno how to implement a solution. heh.... i accidentally assumed in my code that the z axis will always be the distance axis between the cube and the point in space that it's aiming at. Lol. same goes for all the other axis, such as the verticle axis, and the horizonal axis. i forgot that my cube rotates.

Anyways.... now that i know that, it still doesn't help me. I have no idea to implement a solution. I've tried a few things, but it usually just makes the rotating worse. Still help me please? Geometry wasn't one of my strong points. Sin cosine, tan, it gives me all a headache. ^_^ Algebra is definitely more fun.

Thanks Alot!
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 15th Feb 2004 05:15
I haven't forgotten you Mr. Epsilon. I've been slightly derailed here in that today (Sunday) I have had to come into the office to prepare a talk I am scheduled to give on Tuesday. I'll get to work on your problem just as soon as I get out of this place and back to my flat.

I hate working 6+ days a week. Its not pleasant.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 16th Feb 2004 16:44
@Final Epsilon

Ok I had a play around with your code this evening. I think I've got something roughly what you want worked up. I'll need it to test it further tomorrow night though. I'll get back to you then.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 17th Feb 2004 00:55 Edited at: 17th Feb 2004 00:56
yay. ^_^ thanks alot!
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 17th Feb 2004 18:05
@Final Epsilon

I'm not sure what timescale you are working to so I thought I'd attach the code to the point I've got it as of now (midnight on Tuesday night HK time). As you can see, basically it does what you want.

However, it uses the point object command to move the cube "turret" object. I don't like the point object command so I am working on a set of commands to replace the point object command and rotate the cube using dot product calculations.

I'll try to post these as soon as I get them working properly. In the meantime, I hope the attached is helpful.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 17th Feb 2004 21:17 Edited at: 17th Feb 2004 21:17
Thanks Alot!!!

I'm not really working on any timeline. ^_^ Just taking my time. I look forward to seeing your new set of commands. ^_^

Once again, thanks alot!
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 18th Feb 2004 16:27
Ok here is a revision of the code to get rid of the point object command.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 18th Feb 2004 17:59
And here is a further revision of the code to dump the aiming sphere and instead allow the user to click on one of the boxes and make the turret move around to point at it.

However:

1. so far the turret is only rotating in the X/Z plane (and its got a long-way-around-interpolation problem which I've yet to sort out); and

2. its not yet rotating through Y angles

Those are a job for this Sunday afternoon - I'm afraid I'm not going to be able to get back to this mini project beforehand.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 19th Feb 2004 01:18 Edited at: 19th Feb 2004 01:24
Thanks. You've been a great help ^_^ Time to go analyze your code and see what you did.

The turret code is going to be used for the turret on a tank. The basic setup of the game will be similar to the DB tank demo, except the turret can rotate all 360 degrees, and it's controlled by the mouse. Hopefully, if all goes well, i'll be able to make the turret "shoot" bullets. ^_^ With the state my code was in, the player would miss everytime he fired. :-P Oh... and i'll also probably replace the tank with a hovercraft.

Thanks alot!
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 19th Feb 2004 07:06
Is the world in which your tank is placed using the convention whereby the X/Z plane is the ground and the Y axis is height?

If so, the last set of code I posted almost does what you want. All you will need then is some further code to make the turret pitch up and down.

I'll try and help with this on Sunday.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 20th Feb 2004 22:34
^_^ i finally got a chance to look at some of the code. Maybe i misinterpreted what you were trying to do with the aiming cubes, but it seems that the aiming sphere is more what i'm looking for.

The mouse is supposed to control the turret. Wherever the mouse points, the turret aims towards. The turret will always follow the mouse. So, the game is very similar to an FPS, except for the fact that it's in 3rd person, and you drive a tank.

Sorry if i didn't explain what i needed clearly. ^_^ But, some of your code has been a great help! Thanks alot.

I will be gone this weekend, so i wont get a chance to see anything if you post it, until sunday night.

Thanks!
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 22nd Feb 2004 14:37
Hi Final Epsilon

The idea behind the aiming cubes was simply to produce some code that rotated a turret to point at a DBPro object which the user has selected by clicking on it.

I think theres a slight problem with your idea. Its that I don't think you're quite thinking 3 dimensionally. The problem is that the 2d screen position of your mouse pointer is equivalent to an infinite number of 3d world space coordinates.

To visualise this imagine a line going from the camera's position through the 2d coordinates of the screen which correspond with the mouse pointer's 2d screen position. Now project that line forward into 3d space and backwards through the camera into 3d space. That gives you an infinitely long line in 3d space. Now any specific point on that theoretically infinite line is where your want your turret to look at. But you need some kind of convention to decide exactly what point on that imaginary line you do want to aim at. Thats why I wrote the sphere aimer - this is one possible solution.
Anyway, until you decide how to deal with this issue I can't really help you further. The ball is now in your court. Shout if you'd like further help though.

Cheers

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 22nd Feb 2004 14:41
I'll add the sphere aiming code to the codebase and code snippets forum as well so that others can use it - with equal credit shared between us naturally.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Final Epsilon
20
Years of Service
User Offline
Joined: 26th Jan 2004
Location: CA, USA
Posted: 23rd Feb 2004 02:39
ah. Thanks. ^_^ I was thinking about having the distance coordinate determined by the current object under the aiming cursor by using the pick object command. When you moved the cursor to aim at various objects, the distance would adjust to the target.

Anyways, thanks for all your help. Your code has helped me alot.
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 24th Feb 2004 07:32
I'm glad I helped! I look forward to seeing your game in due course!

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home

Login to post a reply

Server time is: 2024-09-21 22:26:24
Your offset time is: 2024-09-21 22:26:24