How to move camera in webgl? - javascript

I started to learn webgl, but it's very hard, so I dont know a lot of things. How do I move the camera in the 3D space and how do I set, where to focus?

WebGL is quite low level and doesn't support cameras as such. If you want to see details please refer to this tutorial which is a part of a big tutorial series you might find helpful.
I would recommend you to have a look at three.js which is a lighweight 3D engine built on top of WebGL. See this HTML presentation for a nice introduction into this library.

Related

Interactive 3d in the shape of js frameworks

I'm planning on creating an interactive 3d application in js. My question is whether or not babylon.js or three.js supports interactivity? Can't seem to find any information on this, and the documentation doesn't help much either.
Note; by interactivity, I mean for the user to be able to draw elements on a given 3d scene.
I can't speak for babylon.js as I've never used it, but I do have some experience with three.js.
If by "draw elements" you mean creating or manipulating shapes/geometries on the fly based on user-input, then the following examples should prove that its definitely possible.
For instance, on the three.js docs page, there is a control-panel used for manipulating a CylinderGeometry() object in the top-right corner of the live-example.
An example of "drawing" from cursor-input using raycasting can be found on thee.js's examples page as well as another example where objects within the scene are draggable.
To be honest, the interactivity of your app is only limited by you.

Drawing a model from different viewpoints on HTML5 <canvas>

Well this is for a project I chose to do for my computer graphics class - drawing a grand piano that can be viewed from different angles.
I haven't yet begun the work, and I just completed lynda.com course on HTML5:Graphics and Animation with Canvas. I can see how one could make a cube, or a ball, those sorts of simple figures. But I don't know how I should proceed on my project. Defining each small surface one by one, sure will be very tedious. Should I learn some more? WebGL or something else? Or is the 'tedious' way an 'okay' way? What would you suggest?
"The different angles" implies that you want to model and render a three dimensional object.
Here is one recipe to success:
Design your model (grand piano) in any open source and free modelling application, like Blender
Then, learn basics of Three.js or similar WebGL framework which simplifies the complex process of rendering a 3D scene
Export your model from Blender and import it to your Three.js JavaScript.
It is possible to render objects to <canvas> on Three.js without WebGL, but using WebGL backend simplies the process a lot and I highly recommend sticking with WebGL.
Here are is one of Three.js examples showing some modeled cars from different angles (cameras).
HTML5 Canvas API is mostly useful for 2D graphics and does not suit for your purpose very well, as you have noticed with its limitations.
Use WebGL, Three.js aims to be very accessible. www.udacity.com have a course on 3d graphics that uses Three.js that is very good for beginning.
Real-time 3D graphics is basically about creating a 2d image that re-creates that effect of a 3d perspective and can be updated in real-time.
Going about this in a brute force way won't teach you anything about how this effect is achieved.

HTML5/JS - A good game engine which doesn't rely on Canvas?

I'm looking to build an RTS game built mainly in HTML/CSS. There would be a map, but I am unsure if to build it in Canvas or some other way.
The map needs to stretch out for different window sizes, so I was thinking maybe SVG.
I've literally found a ton of game engines, but they seem to mainly rely on canvas.
I guess my main priorities are:
sound
frame limiting
time traversal
AI
I'm looking for a game engine library to use in Javascript that lets me render DOM elements and not just canvas elements.
Try Crafty game engine. It lets you choose between canvas and DOM rendering. And it got lots of other good stuff.
BabylonJS is the best gaming engine right now. It supports geometry instancing which provides good performance to render large amounts of units on screen. Plus it comes with its own physics engine, supports WebGL, imports Blender models and ton of other great features.
http://www.babylonjs.com/

How to make 3D animation with Canvas

I have background on Canvas 2D context, but i want to perform a 3D animation like this one, is Three.js library the best choice to do such animation? Can you point me to some useful tutorial or documentation that may help. Thanx in advance.
That's one of the most common choices.
As WebGL enables OpenGL without the need for libraries, you might also do it with just Vanilla JS but that would be harder as WebGL doens't offer much more refinement over the raw and crude OpenGL.
Apart three.js, you could also try GLGE or PhiloGL but as Three.js is the most popular I would recommend to go for it if you have no specific requirement.
Looks like the demo you linked to is using a canvas library called Clay.js. Not one that I've personally heard about until now. For 3d in canvas the most popular one I know of it Three.js as you already mentioned. It has the benefit of supporting webGL as well (browser based openGL variant).
Three.js has limited documentation and some examples but outside of some books you may buy there isn't a lot of hand holding. You basically need to dive in and start coding. Here are some online resources that may help you get started (not necessarily all focused on THREE.js):
http://aerotwist.com/tutorials/getting-started-with-three-js/
http://learningthreejs.com/
http://learningwebgl.com/blog/
To make it easier to work with THREE.js Jérôme Etienne created a project called tQuery which you can think of kinda like jQuery. A wrapper to make it easier to get your hands dirty. Here's a video where he shows how to create a webGL game in 10 minutes.

Do you draw the entire object?

Hi I'm working on learning 3d game development and I'm starting with JavaScript and the html5 canvas and I was wondering if I were to have a 3d model do I draw the entire model(front, back, etc) and let the web browser decide what to render or should I try to just draw the sides that are in view of the camera? I ask this because I can see how it would be faster to do the latter of the 2 but that can get very complex and I'll need to do quite a bit more research to find how to do that.
Thanks!!
It's up to you, but it depends at least in part whether it's more expensive to spend the time clipping the model or just to render the entire thing dumbly.
Modern GPUs are pretty fast at drawing tons of geometry, so you often won't optimize the geometry sent to the card. However, it sounds like you're using the 2D canvas and writing your own rasterizer, so it may well be faster for you to do some quick optimization. Profiling and experimenting will turn up the right answer for your particular project.
If you're just learning I wouldn't worry overly about performance at this point but instead making sure you get the fundamental ideas and math down.

Categories