3

I'm currently working on a small game, just to kill time - I have been doing most of the rendering with CSS3 transforms, etc old code) (the code of this version is here)

So, now I'm trying to rewrite this into a more powerful way with the goal of allowing more stuff on the virtual world (efficient light, weather, shadows, day-night cycles, etc) in a less CPU-intensive way..

Anyway, the problem is my vast non-knowledge of 3D graphics, so with some trial and error I've managed to get new code) But still far from what I have currently achieved with CSS transforms, at this moment, this is what I have so far (code-wise), when it comes to the rewrite

The code which handles the game logic, is still the same, and I'm working on wrappers over three.js, these are in src/render, in particular, Camera:

  const camera = this.props.ctx.renderer.camera
  camera.position.set( lookAt[0]+20, 20, lookAt[1]+20)
  camera.lookAt(lookAt[0], 0, lookAt[1])

and in Renderer, I've got:

  let d = 15
  this.camera = new THREE.OrthographicCamera(-d, d, d, -d, 0.1, 1000)

  this.camera.position.set( 30, 30, 30 ); // all components equal
  this.camera.lookAt(new THREE.Vector3(0,0,0))

(d=20 still looks pretty different)

The code there is basically taken verbatim this answer

My current goal is basically to get a similar render to what I currently have with CSS3 transforms, using three.js.

Fixed it with manthrax's help

Code which solves this:

cube.rotation.x = Math.PI * -0.5

On the tiles

pailhead
  • 5,162
  • 2
  • 25
  • 46
Exio4
  • 41
  • 1
  • 5
  • 1
    There is a CSSRenderer in three that does what yr describing :) but if you already have assets n stuff, I'd humbly suggest going straight to 3d/webgl! – manthrax Jul 31 '18 at 23:33
  • I'm trying to steer away from CSS so I can potentially use shaders in the future, this is more of a future-proof rewrite (currently, the tiles are just plain colors, no textures yet) – Exio4 Jul 31 '18 at 23:37
  • I help moderate a three.js dev slack... Feel free to drop in and we can help walk you through the transition. :) https://join.slack.com/t/threejs/shared_invite/enQtMzYxMzczODM2OTgxLWE5OTU4OTYxZTZlODk1ZGNjODIyMDZlODM4ZmUyMzNiOWIxMmFjNTYwOTc4MjU0ZmNiODk5MzZiMGJhMTkzZWI – manthrax Jul 31 '18 at 23:42
  • There is also the concept of "skewing" the camera matrix which is the equivalent of a real world "tilt/shift" lens. When naively setting an orthographic camera to achieve this i think you're going to get some height shortening. You could skew this matrix and get a height of 1 to always be 1, or even do something like "cavalier projection". – pailhead Aug 02 '18 at 09:11
  • can you give me any resources for this? – Exio4 Aug 04 '18 at 14:48

0 Answers0