• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
FuraProject

3d Angle of facing issues

5 posts in this topic

Hello,

Recently, i've finished my studies, and since i am a bit unenployed now, decided to get back to my hobby. I am having a trouble with my 3D project, at first, everything seemed fine, but after i started implementing "projectiles", buggs started popping up.

First of, heres the code bit that determines angle i am facing. Note that in code it should be angleZ not Y.
[code]
public static float angleX;
private float rotationSpeed;

xRel = Mouse.getDX(); // relativnes from last cursor position

if (xRel > 0)
{
angleY += rotationSpeed * xRel/2;
if (angleY >= 360)
angleY = 0;
}
if (xRel < 0)
{
if (angleY <= 0)
angleY = 360;
angleY -= rotationSpeed * (xRel * -1)/2;
}
[/code]

Then theres this class
[code]
public final class Utils {
public static float angleConst = 100/90;
public static float angleMod = 0;

private static int quarter;
private static int procValue;
private static float placeHolder;

public static float normalizeAngle()
{
placeHolder = angleY + angleMod;
if (placeHolder > 360)
placeHolder -= 360;
else if (placeHolder < 0)
placeHolder += 360;
return placeHolder;
}

public static void setMows()
{
quarter = (int) (normalizeAngle() / 90.0f);
procValue = (int) (normalizeAngle() - 90 * quarter);

switch(quarter)
{
case 0:
mowX = 1 * ((procValue*angleConst)/100);
mowY = 1 - mowX;
mowX *= -1;
break;
case 1:
mowY = 1 * ((procValue*angleConst)/100);
mowX = 1 * (1 - mowY);
mowY *= -1;
mowX *= -1;
break;
case 2:
mowX = 1 * ((procValue*angleConst)/100);
mowY = 1 * (1 - mowX);
mowY *= -1;
break;
case 3:
mowY = 1 * ((procValue*angleConst)/100);
mowX = 1 - mowY;
break;
default:
break;
}
}
[/code]

And when i press for example S this is what happens
[code]
case 's':
angleMod = 180;
setMows();
x += mowX; y += mowY;
break;
[/code]

Long story short, whenever i rotate myself, and press walking button, setMows is called, which sets mowX and mowY, sort of "vector" that is latter used when i make a step, to calculate my new x and y. Problem is, that this logic is bad and i need some sort of other algorithm. Here is a picture that illustrates "bad" things. It was done by standing in the midle rotating 360 and placing a "stick" on the ground. Start point is x and y, end point is x + mowX * staticNumber and y + mowY * staticNumber.
Problem is that its not
a) Circle
b) It has blind spots

Maybe someone could redirect me towards some sort of better algorythms? I am not entirely sure i am posting in propper section, tho it seems like a begginer problem.

Thanks in advance.

[url="http://imageshack.us/photo/my-images/26/badthings.png/"][img]http://img26.imageshack.us/img26/5555/badthings.png[/img][/url]
0

Share this post


Link to post
Share on other sites
I don't understand what you are doing in setMows. If you want to convert an angle to a vector, use (cos(angle), sin(angle)). Be sure to pass the angle in radians.

Better yet, the vast majority of the times you don't need angles at all: Use vectors directly and you can avoid having any special cases for wrapping around 360.
1

Share this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1326709343' post='4903179']
I don't understand what you are doing in setMows. If you want to convert an angle to a vector, use (cos(angle), sin(angle)). Be sure to pass the angle in radians.

Better yet, the vast majority of the times you don't need angles at all: Use vectors directly and you can avoid having any special cases for wrapping around 360.
[/quote]

Could you give some sort of example on that?

Thing is, i do not understand those vector thingies and how to use them, thus i had to create my own method to determine where should my character walk when i press buttons.
What setMows() does is that it determines quarter i am looking at (360/4), then i take procValue, which is from 0 to 90. By knowing quarter i am facing, and angle (procValue), i can adjush X and Y accordingly.
This for example
[code]
case 3:
mowY = 1 * ((procValue*angleConst)/100);
mowX = 1 - mowY;
[/code]

Splits 1 step into % values of X and Y i should add, when i am doing next step. But this calculation is also wrong.
0

Share this post


Link to post
Share on other sites
I already told you how to convert an angle to a step in the x direction and a step in the y direction: Use cosine and sine respectively.
1

Share this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1326729815' post='4903270']
I already told you how to convert an angle to a step in the x direction and a step in the y direction: Use cosine and sine respectively.
[/quote]

Hell yes! Thanks! This magic works indeed.

- Ray
0

Share this post


Link to post
Share on other sites
Hi again.

Maybe someone could give me a hand in how to calculate vector if i am shotting for example. I need to use X, Y, Z.

For X and Y i use
[code]
angleInRads = Math.toRadians(horizontalAngle);
mowX = (float) -sin(angleInRads);
mowY = (float) cos(angleInRads);
[/code]

But if i want to use Z, i have to use verticalAngle too, thus calculations of both mowX and mowY must change + calculation of "mowZ" must appear.


Edit: Solved this up, took few hours, but was worth it. If anyone will be searching this and will stumble upon my problem, just look up into "Spherical Geomtry".

My sollution was in
[code]
(float) -(Math.sin(radY)*Math.cos(radX)),
(float) (Math.cos(radY)*Math.cos(radX)),
(float) (Math.sin(radX)),
[/code]

where radX is verticalAxis and radY is horizontalAxis (some name fixing upcoming!)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0