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 / How NewXValue(), NewYValue() and NewZValue() work?

Author
Message
Bulleyes
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 11th Dec 2002 07:21
How NewXValue(), NewYValue() and NewZValue() work? The help just says that it move a point in 3D space at certain angle, but which angle? As far as I know, a translation in 3D space needs 3 angles to completely specified its direction.

Can anyone elaborate more on this function for me? Some code snippet to better illustrate this function will be much appreciated.

Thanks!
Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Kensupen
21
Years of Service
User Offline
Joined: 19th Sep 2002
Location: United States
Posted: 11th Dec 2002 10:03
Here's the quick version...
newx=newxvalue(currentxposition,angletomove,distancetomove)

currentxposition is the current X position ov your object or where to start from.

angletomove is the angle to face to get the new X position.

distancetomove is how far from the starting point to calculate for the new X position.

A small example:
This will make a box and a ball.
Using NEWXVALUE and NEWZVALUE, it will put the ball 40 units in front of the box at any angle you face the box.



Hope this can help you understand these a bit more.

-Kensupen
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 11th Dec 2002 12:45
just to add a lil to what Ken said...
the functions basically take the worry of angles out of the equasion for you. Rotating a point in space is quite difficult with pure code for the beginner programmer.

So basically this function will do this hard calculation allowing you to concentrate on other things

Anata aru kowagaru no watashi!
actarus
21
Years of Service
User Offline
Joined: 29th Aug 2002
Location: 32 Light Years away
Posted: 11th Dec 2002 14:34
It's not that hard,use sin/cos on the Yangle to get the same results by yourself

Just remember that you're standing on a planet that's evolving
And revolving at nine hundred miles an hour!
Shadow Robert
21
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 11th Dec 2002 14:44
yeah lol but not alot of people know the math behind using Sin & Cos - kinda wonder what they teach in schools nowadays

Anata aru kowagaru no watashi!
Bulleyes
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 11th Dec 2002 14:49
Ok, I am kinda get it... but still confused though. Sorry.

I can see from the example that by using the NewXValue() and NewZValue(), it actually move current position in (X, Z) at the specified angle. From what I understand, the angle is measure at the XZ plane.

I try to play around with NewXValue(), and NewYValue() to do simillar thing on the XY plane, but does not work as it supposed to be.

Can anyone give some practical example on the use of NewYValue()?

Is there any case that all three functions, i.e. NewXValue(), NewYValue(), and NewZValue() are used all together?

I understand the trigonometry math behind rotation using sine and cosine, if someone could explain me that three functions in terms of trigonomery math equation, I guess I could understand it as well.

Thanks a lot!

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Hilmi2k
21
Years of Service
User Offline
Joined: 29th Nov 2002
Location:
Posted: 11th Dec 2002 21:03
I studdied all that at school, but it has been 8 years, you tend to forget.

The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 12th Dec 2002 00:17
Here is some code I wrote just now to look at the new#value commands.



(theta is rotation on xz plane, phi is rotation from xz plane, standard polar coordinates but using db's odd theta=0 point)

The best way I could see to match the movement was by using:
x#=newxvalue(x#,theta#,thrust#)
y#=newyvalue(y#,phi#,thrust#)
z#=newzvalue(z#,theta#,thrust#)

in place of:
x#=x#+(sin(theta#)*cos(phi#)*thrust#)
y#=y#-(sin(phi#)*thrust#)
z#=z#+(cos(theta#)*cos(phi#)*thrust#)

which doesn't actually work, since nowhere does the newxvalue take account of phi, when it should. In conclusion, I can't immediately think of a program which could use all three together and get the movement right. I tend not to use them anyway, my trigonometry is good enough.
Dark_Programmer
21
Years of Service
User Offline
Joined: 10th Dec 2002
Location:
Posted: 12th Dec 2002 02:32
Ok take a look at that :

If Upkey()=1

XTest# = Newxvalue(X#,CameraAngleY#,10)
ZTest# = Newzvalue(Z#,CameraAngleY#,10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#


ok lets go trough it!!

**********************************************************
first line of code is:
If Upkey()=1

Im sure ya now that ! It looks if the player is pressing the up arrow.
*********************************************************
second and third lines of code:

XTest# = Newxvalue(X#,CameraAngleY#,10)
ZTest# = Newzvalue(Z#,CameraAngleY#,10)

Ok what it does is that it stores in XTest# or ZTest# the Newxvalue or the Newzvalue, wich are THE NEW VALUES!!!
for the new player camera angle.X# is the x coordinate, Z# is the z coordinate, CameraAngle is the angle of the camera and 10 is the value of the translation we want to make.

***********************************************************
last lines of codealmost finished!!!)Hurray!!

If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#

What it does: The first line of code checks if the player is still on the matrix. If he is, 2 lines of code occur. Their function is to store the new position that we got with NewValue(remmenber???) in X# and Z#!!

Hurray ! Youre finished.

I hope that helped you being less mixed up and now you should be able to do the same thing with downkey and the others. And oh i forgot!

*************Turning the camera*****************

If Leftkey()=1


XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#-90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#-90),10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#


Ya should understand this after all tha things ive shown you

anyways if you dont just reply to me!!

Dark Programmer

Bulleyes
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 12th Dec 2002 10:59
Thanks a lot! I haven't read it thoroughly yet. But thanks for all the effort on trying to help me. I really appreciate that.

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 14th Dec 2002 16:38
Here are the trig versions of the commands:

x=NEWXVALUE(x,a,d)
x=x+sin(a)*d

x=NEWYVALUE(x,a,d)
y=y+sin(a)*d

x=NEWXVALUE(x,a,d)
z=z+cos(a)*d

if you want to move along all axis at the same time then you need this code:

a1=x and z angle
a2=y angle

x=x+cos(a1)*d*sin(a2)
y=y+sin(a1)*d
z=z+cos(a1)*d*cos(a2)

this is because you need to find how much you need to go along the x and z plain and then divide it between the x and z values using the second angle.

Correct me if im wrong

Login to post a reply

Server time is: 2024-04-19 23:59:49
Your offset time is: 2024-04-19 23:59:49