DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • SaaS in an Enterprise - An Implementation Roadmap
  • AI-Driven RAG Systems: Practical Implementation With LangChain
  • Injecting Implementations With Jakarta CDI Using Polymorphism
  • STRIDE: A Guide to Threat Modeling and Secure Implementation

Trending

  • Exploring Intercooler.js: Simplify AJAX With HTML Attributes
  • Security by Design: Building Full-Stack Applications With DevSecOps
  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  • Prioritizing Cloud Security Risks: A Developer's Guide to Tackling Security Debt

A Rubik's cube implementation in Three.js

By 
Cedric Beust user avatar
Cedric Beust
·
Jul. 15, 14 · Interview
Likes (0)
Comment
Save
Tweet
Share
9.6K Views

Join the DZone community and get the full member experience.

Join For Free

in 2003, i took the time to put together a page that explains how to solve the rubik’s cube with a set of formulas that are easy to memorize. the idea was not necessarily to solve the cube quickly (it takes about 50-60 seconds to solve the cube with this approach) but to make it easy for anyone to beat the cube with little effort, as opposed to the hundreds of formulas that speed cubists have to memorize to remain competitive.

back then, i used a java applet that represents a cube with formulas and then playing these formulas to explain to the reader how exactly they work. as everybody knows, java applets have fallen out of favor even more today than they already were ten years ago, so i’ve been wanting to update my page with more modern technologies for a while, especially if these technologies don’t show a scary warning to everyone who reaches my web site.

i finally took the time to update my page and i reimplemented the entire cube animation in javascript with three.js. here is how it looks like today .

while it’s easy to find rapidly implemented rubik’s cubes in three.js , i couldn’t find anything that came remotely close to what i needed, namely, being able to configure a cube directly from the html page along with the formula, and playing this formula at the click of a button. three.js turned out to be a great match for this, with the perfect amount of abstraction and power. and with three.js came a few free bonus tools, such as being able to move the cube around and also effortlessly zooming in and out. of course, it’s equally trivial to modify the size of the cube, the position of the camera, the field of view, and just as easy to add more fancy stuff such as lighting, shadows and fancy materials.

the implementation is open source but i want to write some proper documentation before publishing it.

overall, the experience was fairly pleasant. my relationship with javascript is stormy at times (i’m planning to rewrite this in dart at some point to compare) but in the end, using both idea and eclipse to write the code (switching between both to compare) and with the chrome debugger in a separate window, the productivity level is pretty high.

implementing the cube itself was the most interesting part: there are so many ways you can model a rubik’s cube that such a problem is a software designer’s dream. i must have had three different iterations of the data model before i settled on the version you see now (and i’m already thinking of ways i could improve it).

three.js has come a long way since i gave it a try two years ago. the web is still filled with incorrect information referencing an old api that has since then changed, but it’s very intuitive and, most importantly, it allowed me to completely avoid having to deal with the webgl madness. i don’t know if it’s my brain that’s just not wired for this, but i have tried to read countless opengl tutorials over the past years and every time, i give up after an hour, my eyes glazing over the intricate, effect-littered, abstraction empty details of opengl. the api is probably too low level for someone like me with just a passing interest for gory graphical details.

my knowledge of computer graphics and animation is abysmal overall, so this was a great opportunity to move myself out of my comfort zone and force myself to confront problems that i usually never encounter, such as finding tricks to counter floating point rounding errors and revising matrix multiplications and other miscellaneous linear algebra and 3d geometry concepts such as quaternions and gimbal locks .

Implementation

Published at DZone with permission of Cedric Beust, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • SaaS in an Enterprise - An Implementation Roadmap
  • AI-Driven RAG Systems: Practical Implementation With LangChain
  • Injecting Implementations With Jakarta CDI Using Polymorphism
  • STRIDE: A Guide to Threat Modeling and Secure Implementation

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!