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 / How does NEWXVALUE, NEWYVALUE, and NEWZVALUE work?

Author
Message
2Beastmode4u
15
Years of Service
User Offline
Joined: 14th Feb 2011
Location: Loading...
Posted: 21st Jul 2011 23:04
As the title says, how do these commands work?


Cheers.

God help me, Please.
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 21st Jul 2011 23:30
Well, the help files on them explain them pretty good, but basically, you start with a location, then get a new location by giving the command an angle and a distance.

If you are only doing 2D instead of 3D, then you only need to calculate a new x and z value. The y value is not used, it is replaced by the z value.

2Beastmode4u
15
Years of Service
User Offline
Joined: 14th Feb 2011
Location: Loading...
Posted: 21st Jul 2011 23:38
Yes, but what is the equation it uses? Is it some intersect thing?


Cheers.

God help me, Please.
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 21st Jul 2011 23:53 Edited at: 21st Jul 2011 23:55
Not sure what you mean.

Here's an example...



It's just an easy way to calculate new coordinates, without using COS or SIN. A typical use might be where you know what angle your spaceship is pointed, and you know what velocity your spaceship is moving. These commands would give you the next location of your ship.

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Jul 2011 00:03
It's often used when moving something, like a sprite - you'd pass the current sprite coordinates, angle, and distance to move.

Newxvalue(100.0,45.0,1.0)
Newyvalue(100.0,45.0,1.0)

is the same as:

100.0+(sin(45.0)*1.0)
100.0+(cos(45.0)*1.0)

Health, Ammo, and bacon and eggs!
2Beastmode4u
15
Years of Service
User Offline
Joined: 14th Feb 2011
Location: Loading...
Posted: 22nd Jul 2011 01:53
Thanks guys. That equation was just what I needed.


Cheers.

God help me, Please.
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 22nd Jul 2011 14:18 Edited at: 22nd Jul 2011 14:19
@ Van B - if we're talking about sprites, then shouldn't newyvalue be newzvalue? When going from 3D to 2D, the new z coordinate is used for the 2D y coordinate.

Thus



TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Jul 2011 14:21 Edited at: 22nd Jul 2011 14:22
@ Rich Dersheimer

Correct. I'm not sure myself, but I think newyvalue does something like this:

y=newyvalue(100,45,1)

y=100+(sin(45-90)*1)


What do you need that for anyway? That command has been confuzzling me for a while now.

TheComet

Gencheff
16
Years of Service
User Offline
Joined: 12th Jun 2010
Location: UK by way of USSR
Posted: 22nd Jul 2011 14:52
TheComet,
Let's say I have a camera I can tilt up/down with the mouse and want it to zoom in/out with the scroll.

IF the scroll<0 then I'd use this to fix the camera's y position : newyvalue(camera position y(CurrentViewport),wrapvalue(camera angle x(CurrentViewport)),-5)
You could just use move camera instead though.

Samotnijat vylk nasred gorata.
-3D,2D Artist,Animator,Web developer and Programmer.
2Beastmode4u
15
Years of Service
User Offline
Joined: 14th Feb 2011
Location: Loading...
Posted: 29th Jul 2011 21:28
Quote: "What do you need that for anyway?"


Just for a script I was working on. Now I just need to know the equation for sin, cos, and tan.


Cheers.

God help me, Please.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Jul 2011 23:11
Quote: "[quote]What do you need that for anyway?"


Just for a script I was working on. Now I just need to know the equation for sin, cos, and tan.[/quote]

I mean, what do you need newyvalue for anyway as a command, not why you need it

Equation for cos, sin, tan?

cos

a^2 = b^2 + c^2 - 2bc*cos(alpha)
b^2 = a^2 + c^2 - 2ac*cos(beta)
c^2 = a^2 + b^2 - 2ab*cos(gamma)

sin

a/sin(alpha) = b/sin(beta) = c/sin(gamma)

tan

I forgot

TheComet

Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 30th Jul 2011 00:31
tan(alpha) = sin(alpha) / cos(alpha)

2Beastmode4u
15
Years of Service
User Offline
Joined: 14th Feb 2011
Location: Loading...
Posted: 29th Aug 2011 00:40
[Sorry for the bump]

So,

If I wanted to recreate the equations would they be this:

NEWXVALUE=
100.0+Current_X_Value(Equation for Sin*AngleValue)*1.0

NEWYVALUE=

100.0+Current_y_Value(Equation for Cos*AngleValue)*1.0

NEWZVALUE=

100.0+Current_y_Value(Equation for Tan*AngleValue)*1.0

I just an not sure what to put for the equations part. If anyone has an example, I'd be very great full.

Quote: "what do you need newyvalue for anyway as a command"


To set the camera of a 3D object.


Cheers.

God help me, Please.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 29th Aug 2011 04:29 Edited at: 29th Aug 2011 04:31
To find the equation for cos() and sin()?

Well... There's a problem. Cosine and sine are non-algebraic functions. That means that they cannot be expressed in any finite sequence of + - * / or power operators. They are called transcendental functions, because they "transcend" algebra.

If you're interested in how the approximations work... check out taylor series. If you want an algebraic function that's a good approximation of cosine and sine, the wikipedia article on taylor series has one.

In short: use the cos() and sin() functions.

[edit]
also, I don't think you're going the right direction for whatever it is you want to solve. Could you elaborate on what you're trying to do?


Why does blue text appear every time you are near?
Bluespark
15
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 29th Aug 2011 20:31 Edited at: 29th Aug 2011 20:33
Taylor series are only good very near the points that they are centered at, for cos() and sin(). I found that you can get very accurate results by using the mod operation since cos() and sin() are periodic functions.

Also, based on this:
Quote: "NEWXVALUE=
100.0+Current_X_Value(Equation for Sin*AngleValue)*1.0

NEWYVALUE=

100.0+Current_y_Value(Equation for Cos*AngleValue)*1.0

NEWZVALUE=

100.0+Current_y_Value(Equation for Tan*AngleValue)*1.0"


I would say that TC is trying to rewrite the functions for newxvalue, newyvalue, newzvalue.
The way TC is doing is is not correct, as they do not replicate the new value commands. Rather, this seems to be an incorrect attempt to generalize polar movement from 2D to 3D.
The correct generalization is spherical movement, where the equations you want to use involve TWO angles and a length.

inc x#,R*sin(Theta)*cos(Phi)
inc y#,R*sin(Theta)*sin(Phi)
inc z#,R*cos(Theta)

In this case, R, Theta, and Phi are floats (you may want to declare them as such at the beginning of the program).
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 30th Aug 2011 04:17
how about this simple radar:


or this one:

Login to post a reply

Server time is: 2026-07-10 12:02:33
Your offset time is: 2026-07-10 12:02:33