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 / Circular movement

Author
Message
Bulsatar
13
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 1st Dec 2011 04:26
Hello Everyone,

Ok, so my goal is to have an object revolve around an imaginary center point that travels down the screen. I looked up circle equations and tried adapting them to my project...so, here is the equation I used (pretty standard...)
(x-h)^2+(y-k)^2=r^2
...and then used a math solver to figure out the x and y cuz I didn't want to spend the 5 minutes doing it myself and go this for the x.
x_component = h+(sqrt(-(ry)^2+(2*k*ry)+(mag+20)^2-(k)^2))
y_component = k+(sqrt(-(rx)^2+(2*y*rx)+(mag+20)^2-(h)^2))
mag is the radius, ry and rx are the top and left position of the object on the screen respectively.
ok, used these for the left/top positions of my object and...it shoots right off the screen...

I have variables that track the imaginary center and increment the y axis (this works)
I have variables for the top left corner of the object (this works)
Need an equation for the top left corner of the object that will orbit around the imaginary center at a radius of the variable mag.

All help is greatly appreciated!!!
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Dec 2011 05:10
Your a secret nuclear physacist arent you lol wish I could come up qith maths that complex... But sadly I was only in the top 3rd class in my school for 4 years running... Hope another molecular mathematiciat can help you here...

sorry for my poor maths jokes...

My main point here is... Can you go into deeper detail on the squation pretty please ?

Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 1st Dec 2011 06:04 Edited at: 1st Dec 2011 06:04
Sin and cos. Nuff said. (There are examples in the pre-created darkbasic projects I think.)

-------------------------------------------------------------
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 1st Dec 2011 07:24 Edited at: 1st Dec 2011 08:11
depends what you mean by "revolve" and what plain were talking:

2D (x and y only):
If you mean simply "ring a ring a rosey", use ROTATE SPRITE in conjuction with OFFSET SPRITE. Then rotating the sprite will revolve around the point the way earth revolves around the sun.



You can also draw your sprite diagonally on an alpha background. The distance between your image and the top left corner determines your radius when revolved with ROTATE SPRITE. You don't need to use OFFSETs in this example however your image will not turn and the revolution radius will be constant.

3D: (x, y, z)
now it comes down to HOW you want it to revolve. We'll assume for this excercise you wish the object to revolve around a point while maintaining the same height. Anyway, here is the basic code. You need to extrapolate on it and customize it. (Excuse me if my formatting is messy, I'm on my mobile).



EDIT: PC back online, code commented and re-formatted. Enjoy.
EDIT 2: Added a 2D example using ROTATE SPRITE.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Dec 2011 08:15
Quote: "Sin and cos. Nuff said."

I don't think so.

Here's what I came up with. I'm a bit to tired to explain the maths behind it but I'm sure if you look into the unit circle and basic trig functions you'll find an answer.



TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Dec 2011 09:59
Quote: "I don't think so."


But you just solved it with cos and sin

Additionally you can extend Hodgey's example to work with an ellipse:



TheComet

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Dec 2011 12:00
Quote: "But you just solved it with cos and sin"

I know, I know but just saying it isn't quite enough, gotta show 'em how it's done.

Nice extention btw.

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st Dec 2011 13:23
Hi there. Here's another example




Cheers.

I'm not a grumpy grandpa
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Dec 2011 13:29 Edited at: 1st Dec 2011 14:01
Me like chafari... I can almost fully understand his code there...

EDIT

heres what I got ... attached pic in a link here below... as it was a little wide so did not want to stretch the thread...

Code that I used to get the backdrop effect haha {backdrop off}

also had to introduce [sync rate 60] to slow things down a bit lol...

http://www.akaneaya.co.uk/tgcforum/DOWNLOADS/circularmovement.JPG

{also a weird thing happened today... just while compiling this... I got my first BSOD since I started using Win7 and I got it around 2 weeks prior to official release so that tells you something... it was a win32k error... anyone else got this?...I am posting this here as it could be related lol... will check the event logger later if I can be bothered}

I am still struggeling to understand the use of something spinning out of control lol

EDIT

[BSOD was my gpu overheating from being on so long... time to RMA lol]

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st Dec 2011 14:00 Edited at: 1st Dec 2011 21:30
Quote: "Me like chafari... I can almost fully understand his code there..."


It is intended to be understandable for everyone

Here is another version.



Cheers.

I'm not a grumpy grandpa
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Dec 2011 14:03 Edited at: 1st Dec 2011 14:04
Quote: "Parameter for 'rgb' do not match 'Red Value,Green Value,Blue Value' at line 12."


EDIT

I am considering getting a NV Quadro gpu... maybe an entry level one for now with 1.5GB memory...

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st Dec 2011 14:08
@MrValentine

If you meant to my last piece of code, can you writte the line of code....it works to me

Cheers.

I'm not a grumpy grandpa
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Dec 2011 14:14 Edited at: 1st Dec 2011 14:16
I recoded it with standard rgb(rnd(100) etc etc

using backdrop off brought interesting results... see below... but if you could reverse the pointers this would look AMAZING!!!



EDIT

notice the strange object at the top? whats that?

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 1st Dec 2011 14:19 Edited at: 1st Dec 2011 14:20
MrValentine.

You were right !!, I made a mistake in this line:



it should be:


It looks nice you spiral




Cheers

I'm not a grumpy grandpa
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 1st Dec 2011 14:54
thanks... so can someone explain the implementation of this script to a game or app?

Bulsatar
13
Years of Service
User Offline
Joined: 19th Apr 2011
Location:
Posted: 2nd Dec 2011 04:11 Edited at: 2nd Dec 2011 04:12
WOW!! I didn't expect this kind of response

I used your guys suggestions to lead me to my answer. I was hung up on the angle until I realized all I had to do was increase it arbitrarily...didn't matter what I sent to it as long as I made it increase...

Here is a function that I used to move multiple different objects in any kind of pattern I choose (including complex patterns if I base the top/left corner of the object off of the imaginary center point and send back information recursively).

Thanks for the help and have fun with the code
(uses a couple of UDTs also provided for readability.)

UDTs:


Actual function (equpass is a global variable of type equ_info):
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 2nd Dec 2011 18:28
Quote: "Your a secret nuclear physacist arent you lol wish I could come up qith maths that complex..."


Nothing nuclear there, those are just some simple trigonometric maths To briefly explain how it works...



These are the formulas you need to know to calculate everything in a right-angled triangle:

a/b = tan(alpha)
a/h = sin(alpha)
b/h = cos(alpha)


To briefly explain how the above examples use this, we have a radius and an angle (alpha). The radius is the exact same value as h in the above triangle. And from that info, we would like to calculate the length a and length b.

So if we change around those formulas above so we can solve for a and b, we get:

a = sin(alpha) * h
b = cos(alpha) * h


And that is essentially what the examples do. We increase the angle value alpha, and multiply the cos/sin of it with h to get a and b.

Additionally, the examples work with an offset so we can place the center point somewhere on the screen. This is no big deal, here we just have to add the positions of the center point to our equations:

a = sin(alpha) * h + PositionX
b = cos(alpha) * h + PositionY


And that's exactly what we're seeing in the initial example from Hodgey:

SmallCircle.x = (cos(SmallCircle.angle) * SmallCircle.distance) + BigCircle.x
SmallCircle.y = (sin(SmallCircle.angle) * SmallCircle.distance) + BigCircle.y


TheComet

Login to post a reply

Server time is: 2024-11-22 11:10:00
Your offset time is: 2024-11-22 11:10:00