Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Lua Game Development Cookbook

You're reading from   Lua Game Development Cookbook Over 70 recipes that will help you master the elements and best practices required to build a modern game engine using Lua

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781849515504
Length 360 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Mário Kašuba Mário Kašuba
Author Profile Icon Mário Kašuba
Mário Kašuba
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Basics of the Game Engine 2. Events FREE CHAPTER 3. Graphics – Common Methods 4. Graphics – Legacy Method with OpenGL 1.x–2.1 5. Graphics – Modern Method with OpenGL 3.0+ 6. The User Interface 7. Physics and Game Mechanics 8. Artificial Intelligence 9. Sounds and Networking Index

Using vector math


The Box2D library uses two-dimensional vectors in a form of its own native data type called b2Vec2. It's used in many places of the Box2D library so it's better to stick with this one.

This data type can be used to specify the position in a 2D space, directional vector with unit size or a speed vector. Keep in mind that Box2D doesn't know the difference between the uses of this vector.

Getting ready

This recipe expects the user to have a basic knowledge of vector math.

The LuaBox2D library contains the b2Vec2 object interface called Vec2. You can create one simply by calling its constructor function. Almost all object constructors are available via the LuaBox2D interface:

local box2d = require 'LuaBox2D'
local Vec2 = box2d.Vec2

This will define a shortcut for the Vec2 object constructor.

How to do it…

You can create a new Vec2 vector object by calling the constructor in one of the following ways:

-- create zero vector
local vector1 = Vec2()
-- create a vector with x=1 and y=2
local...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime