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

How to calculate the points of a triangle strip from a line?

5 posts in this topic

Hello everyone,

I have the points for a vehicle trajectory in 3D space now I want to make a triangle strip that shows the vehicle trajectory.
Like in [url="http://imageshack.us/photo/my-images/200/ribbon.png/sr=1"]this image[/url] I have the line, now I need the strip.

My main question is how to calculate the x(width) and z(depth) since depending on slope it's not as simple as adding half the width of the segment.
Since I have two points in the line and the slope, I should be able to calculate what is the point at D distance from the line points. I just can't put my finger on the math.

Can anyone help me out?
0

Share this post


Link to post
Share on other sites
I think the reason that you are struggling is mainly because you do not have sufficient information on the trajectory. Besides the direction of the line, there is a freedom of movement in the rotation around the line. For instance, you could imagine a plane doing a "barrel roll" while staying on the same trajectory line, resulting in a nice double helix like effect for what you want to achieve.
Seeing as how you want to follow a vehicle, I would advice storing the complete transformation per point, instead of just the position. If you only want to reproduce this effect, then adding a "side" vector would be sufficient.

Imagine adding a small XYZ axis system on each point [b]p[/b][sub]i[/sub] in your trajectory, where one vector [b]f[/b] points in the direction the vehicle is headed, one vector [b]u[/b] points up from your vehicle and the third vector [b]s[/b] points to the left (or right) side of the vehicle. Ideally, these vectors should be normalized. If you have trouble obtaining them, please let us know.
Given these vectors, finding the points along the sides of your trajectory is suddenly trivial: [b]L[/b][sub]i[/sub] = [b]p[/b][sub]i[/sub] + a [b]s[/b], and [b]R[/b][sub]i[/sub][b] = [/b][b]p[/b][sub]i[/sub] + a [b]s[/b], for Left and Right, where a is half the width of the trajectory.
The order for the triangle strip would then look something like: [b]L[/b] [sub]0[/sub] - [b]R[/b][sub]0[/sub] - [b]L[/b][sub]1[/sub] - [b]R[/b][sub]1[/sub] - [b]L[/b][sub]2[/sub] - [b]R[/b][sub]2[/sub] - etc...

Hope it's a little clear. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by Ignifex
1

Share this post


Link to post
Share on other sites
Thank you so much for your answer!

I have a few questions though. Sorry if they are very basic.

The data I have acess to is (using your notation) Pi, Pi+1 and Phi or the Roll angle.
I know that f = (Pi+1)-Pi
For u, the idea was to rotate the unitary y vector according to Phi. But I don't remember how to apply a rotation to a vector.
Finally, for s, I was planning to calculate the normal of f and u.

How do I rotate?
0

Share this post


Link to post
Share on other sites
When approaching the rotation through angles, the yaw-pitch-roll system is probably the most intuitive. Once you know these angles, finding any vector is relatively easy.

As you mentioned, you already have a roll angle. The yaw and pitch can then be computed from your forward vector [b]f[/b], using it's x, y and z components. This is a little rough and you should be careful when the x and z components are both 0, but the computation is as follows:
yaw = atan2( -x, -z )
pitch = atan2( y, sqrt( x[sup]2[/sup] + z[sup]2[/sup] ) )

Given these angles, I believe it's fastest to compute [b]s[/b] using some rotation matrices. For yaw-pitch-roll, the rotation is applied as YPR * vector, or ZYX * v. Given a simple vector (-1, 0, 0), it's components will be:
x = - (cos(yaw) *cos(roll) + sin(yaw) * sin(pitch) * sin(roll))
y = - (cos(pitch) * sin(roll))
z = - (cos(yaw) * sin(pitch) * sin(roll) - sin(yaw) * cos(roll))

Note that I assumed you use the OpenGL eye space coordinate system, since you mentioned y is pointing up. I follow the right hand rule for the rotations, also the roll. A (small) positive roll angle turns a plane left, a positive pitch goes up and a positive yaw is also left. Edited by Ignifex
1

Share this post


Link to post
Share on other sites
I see.

I actually have yaw-pitch-roll, just didn't know it was easier.
I'll use Pi for location and your system for the vectors.


Is this written in any kind of tutorial/book/crash course?
0

Share this post


Link to post
Share on other sites
What I have described is all Linear Algebra and the use of rotation matrices. You can pick up any introduction level book on the topic, which should also include transformations as a part of matrix multiplication.
As for online sources, wikipedia might be a good place to start. Wolfram is good reference material, but it might not have the best introductions.

For real world applications such as this one, it usually helps to make a drawing of what you are trying to do. Draw the vehicle as it heads in a all 0 angle direction, then consider what rotations should be applied and in what order. Rotations in 3D is often a bit of a pain, but it gets better with some practice.
Also, using a math library will really help to clean up your code and you can avoid writing out rotations by hand like I showed.
1

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