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.

DarkBASIC Professional Discussion / Using Sin() and Cos() and I'm lost

Author
Message
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 10th Jun 2011 04:25


In the function, I can make all objects translate correctly except for object k. It doesn't work, even though I've done the math and it should.

Ich liebe Hundepfeifen; du hast wohl keine gehört.
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 10th Jun 2011 08:22
Okay I updated because I figured it out, but now I'm trying to make the corner parts translate using my new formula and they're off by a bit. Can anyone help me?



Ich liebe Hundepfeifen; du hast wohl keine gehört.
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 10th Jun 2011 08:30
Nevermind, I resolved it by multiplying the cos/sin by sqrt(2) to make the length one.

Ich liebe Hundepfeifen; du hast wohl keine gehört.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Jun 2011 12:58
Quote: "Nevermind, I resolved it by multiplying the cos/sin by sqrt(2) to make the length one."

The square root of 2 is about 1.41...

Could you show us what you did, it doesn't sound quite right to me but I'm not sure I understood you correctly?

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Jun 2011 15:07
Quote: "it doesn't sound quite right to me "

Me either, but since he said it works for him now I didn't bother replying.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Jun 2011 15:31
Me likewise.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 10th Jun 2011 16:27
Quote: "Nevermind, I resolved it by multiplying the cos/sin by sqrt(2) to make the length one."

just to say what everyone else is thinking:

cos(n)^2+sin(n)^2=1
means the distance from the origin to a point (cos(n),sin(n)) is 1.


Why does blue text appear every time you are near?
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 10th Jun 2011 17:18
Sorry for the confusion. What I've done in this program is position each object around the origin using the cosine and sine as x and z coordinates, making sure that each object's specific location is scaled back by the sine or cosine of a different angle but still based on the origin object's location. When positioning the corner object at cos(object angle y(l)-135),1,cos(object angle y(l)-135), it positions it where the specific coordinates are 1/sqrt(2),1,1/sqrt(2), which are each less than one. So I multiplied both the x and z coords by the standard angle's reciprocal, sqrt(2)/1 or just sqrt(2).

I now have it set up in my full game, but I'm having a worse issue with clearing the variables. They stick around, and I don't know how to keep that from happening because of how new I am to this.



Ich liebe Hundepfeifen; du hast wohl keine gehört.
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 10th Jun 2011 17:34
Okay I know that didn't make a ton of sense.

The way this program works is it looks at the rotation of the object at the center, and uses its cosine and sine to appropriately move the objects around the center object. When using basic object numbers it works great, but using variable I now have a problem. Here's my test code when I was working out the kinks.



It's all the same except the rotation of the specific object around its own axis is based on its own axis, and I'm using object numbers instead of variables. For this cube, I need to use variable so how do I do that without it thinking the same thing over and over?

Ich liebe Hundepfeifen; du hast wohl keine gehört.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Jun 2011 00:43
I don't understand the question.

What exactly is wrong?

Quote: "without it thinking the same thing over and over"


What "same thing"?
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 13th Jun 2011 23:06
I don't know what's wrong with me, I can't seem to word it right...

If I declare in my loop a variable a-zz for all 27 cube objects, it for whatever reason holds on to some of those variable names and doesn't move the cubes accordingly.

When I get to my home PC I'll try it again but with 26 cubes surrounding the only one with a constant position rather than rebuild over and over. Maybe I'll try an array. Wish me luck.

Ich liebe Hundepfeifen; du hast wohl keine gehört.
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 14th Jun 2011 05:27
Goddamnit. All that I had to do was remove the "phy update" command in my main loop, since I wasn't calling phy start at the beginning. Somehow that fixed everything.

Ich liebe Hundepfeifen; du hast wohl keine gehört.
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 14th Jun 2011 07:26


Run that, and remove the comment slashes before make cube in the for next loop, replacing the slashes on the "load object 'cube.x'" command so yours doesn't get off track trying to find an object that isn't there.

The only four modules that 'work' right now are the three arrows on the left, and the one on the top closest to you. Right click an arrow to change its direction, then click it to rotate the row/column in that direction.

Right now its screwy, and I've been wracking my brain trying to fix it. Does anyone have a suggestion?

Ich liebe Hundepfeifen; du hast wohl keine gehört.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jun 2011 12:24
Quote: "Run that"


Could you supply the media so we can actually run it?
SJPro
23
Years of Service
User Offline
Joined: 3rd Jul 2003
Location:
Posted: 14th Jun 2011 19:20
Is it possible to explain your problem a bit more abstractly from your code?

From the sounds it are you trying to rotate 27 objects around a central object in a circle shape?

www.freewarehub.net
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 14th Jun 2011 20:51
I'll just include the media. I'm trying to make a rubik's cube and failing really, really hard.

Here's a rar of the entire project file. I realize after so many posts that it may seem like I'm trying to get other people to write this thing for me, but I'm just looking for suggestions. I'm very beginner, and I think there's something wrong that I can't see.

Ich liebe Hundepfeifen; du hast wohl keine gehört.
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 14th Jun 2011 21:34
Okay, so instead of checking object positions and assigning objects a variable arbitrarily during the main loop I'm going to place a set of nine object position checks next to each "do-until" loop to check only nine objects before rotating them.

This thread has become a journal of me transitioning from idiot to a minutely less stupid idiot. Wish me luck!

Ich liebe Hundepfeifen; du hast wohl keine gehört.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jun 2011 22:40 Edited at: 14th Jun 2011 22:46
Quote: "This thread has become a journal of me transitioning from idiot to a minutely less stupid idiot."


Welcome to the club.

Thanks for the media. I'll see if I can guess what's supposed to happen.

Edit

Just tried the download. Nice (ignoring the obvious bugs). It's quite clear what should happen now. I'll see if I can spot the problem. It would be good to get this problem sorted - I then won't need to buy a new cube (many moons ago my son took my original cube apart ...).
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jun 2011 23:21 Edited at: 15th Jun 2011 00:51
Had a quick look at the code.

The first thing I would do would be to remove all the comparisons of floats with exact values. That might not be the cause of your problem but it could be. If your object position is stored internally as (x, y, z) = (0.999999,0,1) then the computer wouldn't recognize this as actually (1,0,1). It would also make the code more readable if you did something like this:



That way you can be sure you are comparing integers with integers and accidental float precision problems won't happen.

Edit

Quote: "Using Sin() and Cos() and I'm lost"


So am I. I can't see what's wrong either.

You only need the front 9 objects to see the problem. If you just rotate the front 9 and print out the object numbers they should just rotate and keep the same relative positions - but they don't. If you rotate the front just once it looks OK - but the values of a, d, g, j, m, p, s, v and y show that something has gone wrong immediately. It looks like a very simple error somewhere but I can't see it yet.

I suggest you remove everything that isn't needed to show the problem (I've removed all the code referring to rotating the top centre and bottom layers for example) and carefully study what's left. Print out a few numbers and see why they are wrong.
Fresser
19
Years of Service
User Offline
Joined: 16th Aug 2006
Location:
Posted: 15th Jun 2011 04:51
Thanks for the tips, I can't thank you enough. I'll be trying this out when I get to my home PC.

Ich liebe Hundepfeifen; du hast wohl keine gehört.

Login to post a reply

Server time is: 2026-07-10 22:54:00
Your offset time is: 2026-07-10 22:54:00