Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:14:21+00:00 2026-06-13T10:14:21+00:00

I am developing a small library as a basis for some applications. As I

  • 0

I am developing a small library as a basis for some applications. As I am about to create a scenegraph (2D) I am wondering which of the following approaches looks more promising under the view of performance, maintainability, easy to use etc.

  1. I could give each drawable element a matrix where I perform translation, rotation and more.
  2. I could do everything on the canvas instead of the elements.

The first solution has a disadvantages: For primitive elements like circles, where I can’t pass a matrix in the draw call, I must access the translated values from the matrix like this:

private float get(int index) {
    final float[] values = new float[9];
    getValues(values);
    return values[index];
}

public float getX() {
    return get(Matrix.MTRANS_X);
}

public float getY() {
    return get(Matrix.MTRANS_Y);
}

So on every draw call I create a float array for each getter call (one for getX(), one for getY()). Assuming that I have plenty of elements on the screen, this could lead to a memory and performance impact.

The second approach has the disadvantage of “negative” thinking. If I want an element be drawn at point 100/100 I must translate the canvas to -100/-100 as I would draw on 0/0. If I restore the canvas after that, the result would be the element be drawn on the wanted 100/100. I am not sure if this negative thinking would result in a heavy impact on code maintainability and decreased understanding (never even started to think about introducing bugs by simply forgetting to negate something…).

Does someone have a tip which way should be preferred?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:14:22+00:00Added an answer on June 13, 2026 at 10:14 am

    It seems that indeed both solutions must be combined.

    My assumption on the second approach is totally wrong. If I translate an element to 100/100, the point of origin will be changed to 100/100. The same applies, of course, to the canvas. The negative thinking was total nonsense of me.

    The combined result will be the following:

    1. Each element that will be drawn, has his own Matrix which contains rotation, translation and scale.
    2. The canvas will be saved via save(), with the provided method concat(Matrix matrix) the matrix of the element can be applied. The drawing will be done and the canvas will be restored with restore().
    3. Each drawable Element which is the parent of other drawables will loop over the children and save, concat and restore in the same way.

    This enables the implementation of a 2D scene graph without any big implementation work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing some library in C that can be used by various user applications.
I'm developing a small OOP/RAII library that wraps Win32's mixerXXX API functions. I'm writing
I've just started developing a small C++ program using GraphViz's graph library and noticed
I am currently developing a small simulation utility, using the Task Parallel Library to
I have a little experience developing small command-line applications with Python. I want to
I am developing a small app in which I want a background service to
I'm developing a small haskell program that uses an external static library I've developed
I am developing a small application in Java. I am using Java2D Library for
I'm developing some image processing software in C++ on Intel which has to run
I' developing a small android maze game and I'm experiencing a strange effect which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.