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 Discussion / Problems with Newxvalue, Newyvalue and Newzvalue

Author
Message
Algae Man
22
Years of Service
User Offline
Joined: 11th Nov 2002
Location: Canada
Posted: 16th Sep 2003 04:49
At first glance this might seem like a newbie question. But I wouldn't consider myself a newcomer to DarkBASIC, so just hear me through. I'm not quite sure how to word this, but:

I understand how you use newxvalue and newzvalue to calculate new coordinates based on angle and distance. I can make an object "fly around" another object in a circle with these commands. But newyvalue has always puzzled me. I can get an object to move around in a circle along the x/z plane, but I can never get it to move in a circle along the x/y or z/y planes. It just goes up and down in a sinusoidal way. Can someone please explain to me how to project a coordinate by any given angle? I'm not sure if this post makes any sense. It's hard to word. If you think you understand what I'm asking, please post.

Thanks in advance.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Sep 2003 12:03 Edited at: 16th Sep 2003 12:03
This returns coordinates to rotate around an object as if it were positioned at x0,z0, on the Y-axis.
x = cos(angle) * radius
z = sin(angle) * radius

Add the center object's coordinates to the x and z values, offset values.
x = cos(angle) * radius + offset_X
z = sin(angle) * radius + offset_Z

To rotate around the Z-axis, switch z with y:
x = cos(angle) * radius + offset_X
y = sin(angle) * radius + offset_y

And to rotate around the X-axis, switch x with y:
y = cos(angle) * radius + offset_Y
z = sin(angle) * radius + offset_Z
Algae Man
22
Years of Service
User Offline
Joined: 11th Nov 2002
Location: Canada
Posted: 17th Sep 2003 01:26
Thanks Phaelax, but that wasn't really what I was asking. It was my fault; I didn't word my question correctly. You showed me how to project new coordinates for rotation around each plane (xz, xy, zy). With your forulas, I can only rotate along one plane at a time. What I wanted to know was how to rotate around a point along all planes simultaneously. I mean, with your calculations I can rotate around in two dimensions, but I want to know how to rotate around in three dimensions.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Sep 2003 22:39
ah, ok. That would require matrices. I'm still working at that myself. Look into some of these resources, and maybe you can figure it out from there.
http://www.geocities.com/SiliconValley/2151/matrices.html

Basically, what you want to look up is transformation matrices. Sry I can't help you better.
Algae Man
22
Years of Service
User Offline
Joined: 11th Nov 2002
Location: Canada
Posted: 18th Sep 2003 03:14
Thanks Phaelax, it looks like that link you gave me has lots of useful information. I'm a bit upset that I have to go to matrices and all that complicated stuff (which I currently know nothing about). But maybe I'll learn something!
=C=
22
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 18th Sep 2003 19:28
Hi Algae Man,

I took the time and dug out an old piece of code I used. I am sure I did find it in the old DB website, if not on a website linked to it.

Study the code in the function It negotiates with two angles and a zoom for the x,y and z value respectivly to position object 1000 in relation to an object, called the observed object.

The main loop does read the mouse movement and alters the position of the object 1000, as well as clicking status

It does have a lock problem being with EULER Maths. What you can do is find a way to avoid and resolve the lock in the function.



I hope it helps to see what's going on there...

I know how it feels to be working with something for a long time and still feel a newbie. sometimes we postpone our in depth study of a subject just for the sake of using, prototyping and getting something up and running quick. And then we worry how it works.

Isn't it weird?

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
Algae Man
22
Years of Service
User Offline
Joined: 11th Nov 2002
Location: Canada
Posted: 22nd Sep 2003 00:18
Thanks =C=, that was exactly what I was looking for, except with your code, the object rotates around it's own x axis. Do you know how I can make the object just rotate aaround global x and y axes?

It might make it more clear if I tell you what this is all for. I'm trying to get a bunch of spheres to rotate around a central point. You use the up/down keys to make them all rotate around the x axis, and the left/right keys to rotate around the y axis. I implemented your code (the three sin/cos maths lines which were the heart of your code), and I got the spheres to all rotate. It was fine when they rotated around the y axis, but when I wanted them to rotate around the x axis, they each rotated around their own x axes. How do I make them all rotate around global axes?
Dmitry K
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 22nd Sep 2003 20:20
Try this code:

Algae Man
22
Years of Service
User Offline
Joined: 11th Nov 2002
Location: Canada
Posted: 5th Oct 2003 23:06
Thanks Dmitry, but same problem. Each of the balls rotates around it's own x axis. I've made an animation with milkshape to illustrate what I'm trying to acheive. I'll try to upload it soon so people reading this can see what I mean.
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Oct 2003 23:37
Maybe this will help...

Imagine your desired position is on the earth's surface, you would describe it as latitude and longitude. So to rotate around the earth vertically (North Pole to South pole for example) , you would alter the latitude. This angle is +90 to -90, with zero being the equator. In addition, you can choose to do this via America, Britain or China by changing your longitude. This is 0 to 360.

To work out your latitude and longitude in terms of x,y and z...

x = r*cos(longitude)*cos(latitude)
y = r*sin(latitude)
z = r*sin(longitude)*cos(latitude)

Any good to you ?

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php

Login to post a reply

Server time is: 2025-05-20 20:08:23
Your offset time is: 2025-05-20 20:08:23