• 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
EmptyVoid

Converting a 2D Sphere Coordinate Into a 3D Normal.

12 posts in this topic

You know when you make a 3D sphere how your making 2D circle and changing its radius by a sine wave that means you have a 2D coordinate like latitude and longitude. I need to make it in to a 3D normal how do I do this is there any site that that would tell me how? if so please give me a link. or if you have any ideas or can help me describe this better.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by EmptyVoid
You know when you make a 3D sphere how your making 2D circle and changing its radius by a sine wave that means you have a 2D coordinate like latitude and longitude. I need to make it in to a 3D normal how do I do this is there any site that that would tell me how? if so please give me a link. or if you have any ideas or can help me describe this better.
A Google search for 'spherical coordinate conversion' should turn up some good references. Meanwhile, here's the 'spherical to Cartesian' function from the CML:

/* Convert spherical coordinates to Cartesian coordinates in R3 */
template < typename E, class A > void
spherical_to_cartesian(E radius, E theta, E phi, size_t axis,
SphericalType type, vector<E,A>& v)
{
typedef vector<E,A> vector_type;
typedef typename vector_type::value_type value_type;

/* Checking */
detail::CheckVec3(v);
detail::CheckIndex3(axis);

if (type == latitude) {
phi = constants<value_type>::pi_over_2() - phi;
}

value_type sin_phi = std::sin(phi);
value_type cos_phi = std::cos(phi);
value_type sin_phi_r = sin_phi * radius;

// Note: cyclic_permutation() computes i, j, and k as follows:

// i = axis
// j = (i + 1) % 3
// k = (j + 1) % 3

size_t i, j, k;
cyclic_permutation(axis, i, j, k);

v[i] = cos_phi * radius;
v[j] = sin_phi_r * std::cos(theta);
v[k] = sin_phi_r * std::sin(theta);
}



The 'axis' argument indicates which cardinal axis (0 = x, 1 = y, 2 = z) should be considered 'up', and the 'type' argument determines whether 'phi' should be interpreted as latitude or colatitude.
0

Share this post


Link to post
Share on other sites
I have little clue what you're talking about in most of your post. However, for a sphere, the normal at a certain point is just the vector from the origin to that point normalized.

edit: somehow didn't notice above post.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
Original post by EmptyVoid
You know when you make a 3D sphere how your making 2D circle and changing its radius by a sine wave that means you have a 2D coordinate like latitude and longitude. I need to make it in to a 3D normal how do I do this is there any site that that would tell me how? if so please give me a link. or if you have any ideas or can help me describe this better.
A Google search for 'spherical coordinate conversion' should turn up some good references. Meanwhile, here's the 'spherical to Cartesian' function from the CML:

*** Source Snippet Removed ***
The 'axis' argument indicates which cardinal axis (0 = x, 1 = y, 2 = z) should be considered 'up', and the 'type' argument determines whether 'phi' should be interpreted as latitude or colatitude.


Wow just looked and man I've been getting very helpful posts lately I didn't look until now because I thought it would be "just google it" or something but this is really helpful thanks. and yeah I don't make much since to my self most of the time sorry I just have bad communication skills.
0

Share this post


Link to post
Share on other sites
OK... I don't really understand. This is as much as I can guess



float* spherical_to_normal(float x, float y)
{
float v[3];
v[0] = sin(x);
v[1] = y;
v[2] = cos(x);
return v;
}

float* normal_to_spherical(float x, float y, float z)
{
float v[2];
v[0] = //don't know what goes here
v[1] = //don't know what goes here
return v;
}




[EDIT]

[Edited by - EmptyVoid on July 16, 2007 8:21:47 PM]
0

Share this post


Link to post
Share on other sites
Quote:
Original post by EmptyVoid
*** Source Snippet Removed ***
What language is that?

Anyway, I posted code earlier for converting spherical coordinates (e.g. latitude and longitude) to Cartesian coordinates (e.g. a '3D normal'). Was that not what you were looking for?
0

Share this post


Link to post
Share on other sites
It's C++ what language are you using? and yes that was exactly what I was looking for also I realized I need the opposite a 3D coordinate to a 2D one sorry my bad.

[Edited by - EmptyVoid on July 16, 2007 6:06:38 PM]
0

Share this post


Link to post
Share on other sites
Returning the address of a temporary doesn't even work. That's really bad c++.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by EmptyVoid
It's C++ what language are you using? and yes that was exactly what I was looking for also I realized I need the opposite a 3D coordinate to a 2D one sorry my bad.
Here's the function for converting in the opposite direction:

/* Convert Cartesian coordinates to spherical coordinates in R3 */
template < class VecT, typename Real > void
cartesian_to_spherical(const VecT& v, Real& radius, Real& theta, Real& phi,
size_t axis, SphericalType type,
Real tolerance = epsilon<Real>::placeholder())
{
typedef Real value_type;

/* Checking */
detail::CheckVec3(v);
detail::CheckIndex3(axis);

size_t i, j, k;
cyclic_permutation(axis, i, j, k);

value_type len = length(v[j],v[k]);
theta = len < tolerance ? value_type(0) : std::atan2(v[k],v[j]);
radius = length(v[i], len);
if (radius < tolerance) {
phi = value_type(0);
} else {
phi = std::atan2(len,v[i]);
//phi = type.convert(phi);
if (type == latitude) {
phi = constants<value_type>::pi_over_2() - phi;
}
}
}

Also, as alluded to earlier, the code you posted appears to contain several syntax and programming errors.
0

Share this post


Link to post
Share on other sites
Is that better? also I don't know what most of those functions do can you make that with the C++ math library "math.h" as I said not very good with C++ more of a VB person. if not how do I use the code above is it a function? or is it some from of cool data type converter that I had no idea C++ could do? also this is the error I get when I run the code:

------ Build started: Project: nam, Configuration: Debug Win32 ------
Compiling...
nam.cpp
c:\documents and settings\steven batchelor\my documents\visual studio 2005\projects\nam\nam\nam.cpp(16) : error C2061: syntax error : identifier 'SphericalType'
Build log was saved at "file://c:\Documents and Settings\Steven Batchelor\My Documents\Visual Studio 2005\Projects\nam\nam\Debug\BuildLog.htm"
nam - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


[Edited by - EmptyVoid on July 16, 2007 8:29:56 PM]
0

Share this post


Link to post
Share on other sites
Quote:
Original post by EmptyVoid
Is that better? also I don't know what most of those functions do can you make that with the C++ math library "math.h" as I said not very good with C++ more of a VB person. if not how do I use the code above is it a function? or is it some from of cool data type converter that I had no idea C++ could do? also this is the error I get when I run the code:

------ Build started: Project: nam, Configuration: Debug Win32 ------
Compiling...
nam.cpp
c:\documents and settings\steven batchelor\my documents\visual studio 2005\projects\nam\nam\nam.cpp(16) : error C2061: syntax error : identifier 'SphericalType'
Build log was saved at "file://c:\Documents and Settings\Steven Batchelor\My Documents\Visual Studio 2005\Projects\nam\nam\Debug\BuildLog.htm"
nam - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If you're new to C++ (and/or programming in general), you might have some trouble trying to adapt those functions. Yes, the code is standard C++, but there are some external dependencies, so you won't be able to compile the code as is. What you'll have to do instead, most likely, is examine the functions to see how the conversions are being performed, and then re-write your own code using the same steps.
0

Share this post


Link to post
Share on other sites
Converting from (latitude, longitude) to (x,y,z) is not hard:

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

That's your normal (and also the point itself, if the sphere is centered at (0,0,0) and has radius 1).

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