00:00
00:00
Newgrounds Background Image Theme

Breakfast-Crow just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Z from X, Y, and rotation

3,288 Views | 55 Replies
New Topic Respond to this Topic

Response to Z from X, Y, and rotation 2012-07-28 16:31:22


At 7/28/12 04:25 PM, PMMurphy wrote: The earlier video you had was better then this one. But this one shows what your doing more and really explains a possible solution to your problem. Your using the x, y position of the charector and how it rotates to determine how to move the points of the trees and the enviroment around you.

Raycasting is the opposite, the pixels on my screen get shot out to the environment, and when it hits something, it returns to me the color.

SO basically. Take his code. Take your code. Mesh them together.

Well his code is suppose to be the "mesh" of it.
The way your thinking might sound good, but it doesn't really make sense from a code perspective.

I'll continue to fool around with the code though. :\


Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-28 16:39:35


Which falls back to my point earlier about inexperience. I have never dealt with rays, but i have programmed something that does the very kind of action you are trying to attain.

You need to work simple and have many functions. Modularization is the best way to code. Each one of your functions should do one task and one task only. If you had the rays working horizontal and vertical. Now all you have to do is get it working diagnal.

It really is that simple.

Response to Z from X, Y, and rotation 2012-07-28 16:47:59


At 7/28/12 04:39 PM, PMMurphy wrote: Which falls back to my point earlier about inexperience. I have never dealt with rays, but i have programmed something that does the very kind of action you are trying to attain.

Which is why you are here, right? :)


You need to work simple and have many functions. Modularization is the best way to code. Each one of your functions should do one task and one task only. If you had the rays working horizontal and vertical. Now all you have to do is get it working diagnal.

Well it's a sphere, so pretty much all of it is diagonal. If diagonally works, everything will work.
And that's what we're trying to figure out.


It really is that simple.

Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-28 17:00:40


At 7/28/12 04:08 PM, zanzlanz wrote:
Here's a video of the results of the change.
http://www.youtube.com/watch?v=50g_77Pw4cI

form what I can tell the rays are getting fucked up on the x axis, could you by any chance upload the raycasting part (not the rendering, just the part where you decide the direction of the raycast based on xS yS zS) on pastebin?

Response to Z from X, Y, and rotation 2012-07-28 17:03:08


thats not what i mean by diagnol.
hoizontal + vertical = diagnol.

Think of it that way. Watever you are doing horizontally to adjust your program, and wahtever you are doing vertically to adjust your program. Needs to be combined for anything that involves doing both.

I am an artist too so its easy for me to visualize things. also try to think simple and not complicated. Thinking complicated just leads you nowhere.

So basically. Whenever you need an action that goes horizontal with vertical at the same time. You need some kind of fuction that is a combination of the two working functions you already created. Your math and everything works its good to go. Or maybe its not. you never know.

its best to sit down when your confused like this and thouroughly debug your program and try to find any and all logical errors. You can have a logical error and it not effect how your program functions.

Response to Z from X, Y, and rotation 2012-07-28 17:11:24


form what I can tell the rays are getting fucked up on the x axis, could you by any chance upload the raycasting part (not the rendering, just the part where you decide the direction of the raycast based on xS yS zS) on pastebin?

http://pastebin.com/KkAGLePf
I hope you weren't expecting simple, easily-readable OOP code.


Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-28 17:23:08


BLAH i should of programmed all summer instead of doing art. I can't really help you anymore :(

Response to Z from X, Y, and rotation 2012-07-28 17:31:45


At 7/28/12 05:23 PM, PMMurphy wrote: BLAH i should of programmed all summer instead of doing art. I can't really help you anymore :(

It's okay! I appreciate you helping :)
At least you've improved your shading skills xD


Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-28 17:44:57


At 7/28/12 05:31 PM, zanzlanz wrote: It's okay! I appreciate you helping :)
At least you've improved your shading skills xD

The math is at least theoretically accurate.
I feel compelled to ask just one more thing, what is your coordinate system?
Basically where does each axis point, the code I gave you assumed that zS is pointing up and yS is pointing forward, if it's the other way around then all you have to do is swap zS and yS and it should work.

Response to Z from X, Y, and rotation 2012-07-28 17:57:23


yea :(

Also i talked to my advisor, and he told me to not try to program past my education. In other words wait until i learn everything i need to learn in class during my BS. So i try not to program using anything that i havn't been taught yet. The reason he said was because someone can learn how to program on their own and learn it will. But the way its designed and taught in a classroom is better and more suited for success. But there are obviously still programmers who succeed just by learning stuff on their own :).

But yea, if you ever plan to take computer science or game development or whatever you plan to do in college. Just thought i would put that information out there for ya.

Also, that doesn't mean its not a bad idea to explore things and learn what the BS doesn't offer. But the basics and certain disciplines on how to handle problems and other various aspects need to be practiced and addressed first.

Ok i'm done. I ramble alot and talk alot, espsly about CS stuff i can go on for days.

Response to Z from X, Y, and rotation 2012-07-28 18:06:59


I feel compelled to ask just one more thing, what is your coordinate system?

Basically where does each axis point, the code I gave you assumed that zS is pointing up and yS is pointing forward, if it's the other way around then all you have to do is swap zS and yS and it should work.

Yes (I hope), you're right, Y is outwards.
I've already tried swapping the coordinates numerous time but it just tilts the entire screen like it should.

This is so dumb! The answer should be so obvious!

Also i talked to my advisor, and he told me to not try to program past my education.

I love programming and no one's going to tell me to quit. Unless your advisor has good reasons for that, I recommend you continue programming (if it's your passion?).


Also, that doesn't mean its not a bad idea to explore things and learn what the BS doesn't offer. But the basics and certain disciplines on how to handle problems and other various aspects need to be practiced and addressed first.

People say I'm good at programming but I think it's just because I'm better at critical thinking. My code is always sloppy and it usually takes me many tries to add a new feature to a game until I get it just right.


Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-28 18:17:33


At 7/28/12 06:06 PM, zanzlanz wrote: People say I'm good at programming but I think it's just because I'm better at critical thinking. My code is always sloppy and it usually takes me many tries to add a new feature to a game until I get it just right.

You learn how to avoid those problems and do those things better in the classes you take. They teach you proper ways to code how to make things readable what is good code what is by code. Why its good code why its bad code. They tell you typical things people do and why they do it and discuss why those methods are not good.

What he meant was. If you have to ask yourself what your going to use while your writing the code. As in software, data structures, algorithms. Then you are not yet prepared to attempt that program. Before you write a program you should be able to put it down on paper and fully write out everything you want to do. You should have all algorithms you want to use already picked out and ways you use them. You should have all data structures and also you should have a good blueprint and design of how you want your program to function and operate.

They say the coding part is the easy part.

Response to Z from X, Y, and rotation 2012-07-28 18:47:24


At 7/28/12 06:17 PM, PMMurphy wrote: You learn how to avoid those problems and do those things better in the classes you take. They teach you proper ways to code how to make things readable what is good code what is by code. Why its good code why its bad code. They tell you typical things people do and why they do it and discuss why those methods are not good.

Take that advice with a grain of salt, it's meant for the people that left on their own would end up on the first page of this website. His message wasn't necessarily to stop programming, but rather to adopt a form of critical thinking and to make you understand that you are going to make mistakes the first few times you try to do something.
In reality nothing beats experience, and while your teacher has a lot of it backing his claims, you most likely need to earn it and the only way to do that is by programming out of your bounds, making mistakes and correcting them.

Response to Z from X, Y, and rotation 2012-07-28 18:52:14


ANYWAY,

When you start the world with rotX and rotY at 0, you'll see a plus-shape (It's shown in that video I posted earlier).
Does this mean the X and Z axes are stretching?


Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-28 18:55:37


I still program stuff that i am not capable of doing. I do tons of side projects. I currently working on a RTS game, and im trying to put together a research team.

Most of the stuff i am going to be doing in my RTS game or research team si going to be graduate stuff. So i am making a huge list of books i want to buy to learn from.

But i am taking it slow and not jumping right in if im not too comfortable and waiting for new lessons in class. If it's something i am going to be learning soon in class i may or may not look into learning it early. I should. But i prolly wont.

But my project that i have in mind that i want to create is really complex and is going to take a lot of discipline, study, dedication and hard work.

I want to make an RTS AI that functions like cleverbot. But can operate for any video game installed to it and learns from game to game.

Basically, before i start coding something i make sure i understand what im doing. I don't just start doing crazy stuff and getting confused. If i have a plan, whether its a good one or not, then i will tackle it and improve on it as i go.

Response to Z from X, Y, and rotation 2012-07-29 05:10:03


I think I got it.
Basically what happens there is that the way rays are projected they describe a cone instead of a frustrum which is why it looks that way.

This should be it:
xS = Math.sin((xPixel+xRot)/180*Math.PI);
yS = Math.sin(yPixel/180*Math.PI);
zS = Math.cos((xPixel+xRot)/180*Math.PI);

yS2 = yS * cos((yPixel + yRot)/180*Math.PI) - zS * sin((yPixel + yRot)/180*Math.PI)
zS2 = yS * sin((yPixel + yRot)/180*Math.PI) + zS * cos((yPixel + yRot)/180*Math.PI)

this should project the rays in a frustrum and then rotate the frustrum up/down

Response to Z from X, Y, and rotation 2012-07-29 09:18:04


xS = Math.sin((xPixel+xRot)/180*Math.PI);
yS = Math.sin(yPixel/180*Math.PI);
zS = Math.cos((xPixel+xRot)/180*Math.PI);

yS2 = yS * Math.cos((yPixel + yRot)/180*Math.PI) - zS * Math.sin((yPixel + yRot)/180*Math.PI);
zS2 = yS * Math.sin((yPixel + yRot)/180*Math.PI) + zS * Math.cos((yPixel + yRot)/180*Math.PI);

>.> Why isn't this working?
I like your idea of using a frustrum. A lot. But that didn't quite work. (Kinda made it worse).


Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-29 10:00:53


At 7/29/12 09:18 AM, zanzlanz wrote:
xS = Math.sin((xPixel+xRot)/180*Math.PI);
yS = Math.sin(yPixel/180*Math.PI);
zS = Math.cos((xPixel+xRot)/180*Math.PI);
>.> Why isn't this working?
I like your idea of using a frustrum. A lot. But that didn't quite work. (Kinda made it worse).

If you step through the spherical coordinates solution you see that the x coordinate is dependant on the y which indeed was to be expected, but it's not what we want because humans don't see like that, you equations were correct from the start, they only lack the part where you con make them turn up and down.

That is controlled exclusively by the zS and yS components, so basically what you need to do right now is rotate them by a certain degree which is easily done using matrix multiplication like so
|| x' || = || cos a -sin a|| || x ||
|| y' || || sin a cos a || || y ||

which in turn gets you
x' = x * cos a - y * sin a
y' = x * sin a + y * cos a

where a is the degree you are turning it by
there was a flaw in my initial suggestion
yS2 = yS * Math.cos((yPixel + yRot)/180*Math.PI) - zS * Math.sin((yPixel + yRot)/180*Math.PI);
zS2 = yS * Math.sin((yPixel + yRot)/180*Math.PI) + zS * Math.cos((yPixel + yRot)/180*Math.PI);

should be
yS2 = yS * Math.cos((yRot)/180*Math.PI) - zS * Math.sin((yRot)/180*Math.PI);
zS2 = yS * Math.sin(( yRot)/180*Math.PI) + zS * Math.cos((yRot)/180*Math.PI);

because there is no sense in including the position of the pixel on screen in this rotation, you already have the ray direction, you just want to alter them all to point upwards

If this doesn't work either I'm going to try and hack something together see if I can get it right.

Response to Z from X, Y, and rotation 2012-07-29 10:38:52


yS2 = yS * Math.cos((yRot)/180*Math.PI) - zS * Math.sin((yRot)/180*Math.PI);
zS2 = yS * Math.sin(( yRot)/180*Math.PI) + zS * Math.cos((yRot)/180*Math.PI);

because there is no sense in including the position of the pixel on screen in this rotation, you already have the ray direction, you just want to alter them all to point upwards

Yes that makes sense. I was slightly confused.

Haha you're a genius! This works very nicely, but instead of tilting up, it rotates the camera.
I think what we're looking for a zRot. I think that's my fault for not doing that right.

But wow! You will definitely get tons of recognition for your help (if you want).

If this doesn't work either I'm going to try and hack something together see if I can get it right.

I appreciate the help :)


Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-29 10:41:36



Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-29 11:01:53


Okay okay wait.

It rotates fine with this:
y' = y*cos q - z*sin q
z' = y*sin q + z*cos q

But when I turn left/right, the rotation will rotate the camera, like it was turning along a different axis.

So you were right, but the axes themselves aren't rotation.

I also tried this:

double xS2 = (float) (worldX-screenWidth/scale/2)/(screenWidth/scale);
double yS2 = (float) (worldY-screenHeight/scale/2)/(screenHeight/scale);
double zS2 = 1;

yS = yS2 * Math.cos((float) (yRot)/180*Math.PI) - zS2 * Math.sin((float) (yRot)/180*Math.PI);
zS = yS2 * Math.sin((float) (yRot)/180*Math.PI) + zS2 * Math.cos((float) (yRot)/180*Math.PI);
xS = xS2;
				
zS = zS * Math.cos((float) (xRot)/180*Math.PI) - xS * Math.sin((float) (xRot)/180*Math.PI);
xS = zS * Math.sin((float) (xRot)/180*Math.PI) + xS * Math.cos((float) (xRot)/180*Math.PI);
yS = yS;

But it stretches infinitely outwards when I turn 90 degrees.


Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-29 11:21:46



Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-29 12:17:57


At 7/29/12 11:21 AM, zanzlanz wrote: http://www.youtube.com/watch?v=cfBpZs53Dt8

Here's a video

That happens because after you first rotate the axis the reference system gets changed so indeed it seems like you are rotating on another axis.
The solution for this one is to toy with the way the rotations are made

Response to Z from X, Y, and rotation 2012-07-29 12:27:19


The solution for this one is to toy with the way the rotations are made

How is this possible >.< How frustrating! You've been such a big help, but this is starting to annoy me.


Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-29 14:20:52


SOLVED!

double xS2 = Math.sin((((float) (worldX-screenWidth/scale/2)/(screenWidth/scale))*75)/180*Math.PI)*3;
double yS2 = Math.sin((((float) (worldY-screenHeight/scale/2)/(screenHeight/scale))*45)/180*Math.PI)*3;
double zS3 = 3;

yS = yS2 * Math.cos((float) (yRot)/180*Math.PI) - zS2 * Math.sin((float) (yRot)/180*Math.PI);
double zS3 = yS2 * Math.sin((float) (yRot)/180*Math.PI) + zS3 * Math.cos((float) (yRot)/180*Math.PI);
				
xS = xS2 * Math.cos((float) (xRot)/180*Math.PI) - zS3 * Math.sin((float) (xRot)/180*Math.PI);
zS = xS2 * Math.sin((float) (xRot)/180*Math.PI) + zS3 * Math.cos((float) (xRot)/180*Math.PI);

Thank you so much for your help Kiwi! I couldn't have done this without you.
I feel dumb for not seeing this before, but the 2 changes in the Z axis were causing conflicts. >.<


Hi, you! You're awesome, probably! <3 Have a great day!

Response to Z from X, Y, and rotation 2012-07-29 14:49:02


At 7/29/12 02:20 PM, zanzlanz wrote: SOLVED!

Congrats and cheers xD