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 8872533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:14:34+00:00 2026-06-14T18:14:34+00:00

The code below gets all of the positions and angles of the objects from

  • 0

The code below gets all of the positions and angles of the objects from the physics engine, and updates each object accordingly. It slows down once there is a lot of activity among the objects.

I know it is NOT the physics engine because I have the exact same thing written using OpenGL, but I can’t use it for my specific application.

int bodyId = 0;
foreach (Shape shape in shapes)
{
    //Don't update sleeping objects because they are sleeping.
    //Waking them up would be terrible...
    //IGNORE THEM AT ALL COSTS!!
    if (physics.IsSleeping(bodyId))
    {
        ++bodyId;
        continue;
    }

    //Rotate transform
    RotateTransform rot = new RotateTransform(physics.GetAngle(bodyId));
    rot.CenterX = shape.Width / 2;
    rot.CenterY = shape.Height / 2;

    //Set the shape to rotate
    shape.RenderTransform = rot;

    //Body position
    Point bodyPos = physics.GetPosition(bodyId);
    Canvas.SetLeft(shape, bodyPos.X - shape.Width / 2);
    Canvas.SetTop(shape, bodyPos.Y - shape.Height / 2);

    ++bodyId;
}

I want to know if there is a more efficient way in doing the above, broken down into a couple questions.

  1. If I call Canvas.SetLeft, and Canvas.SetTop is there ever a time that the UI will start rendering inside the loop? Or if that isn’t clear, how exactly do the Canvas.SetLeft and Canvas.SetTop functions work?

  2. Would it be better to use a TranslateTransform since I am already using a RotateTransform?

  • 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-14T18:14:35+00:00Added an answer on June 14, 2026 at 6:14 pm
    1. Yes, SetTop() and SetLeft() are called every time for every element you have. If you wanted to make the everything more efficient I would do the following. First you use an update function that updates the logic, i.e. you calculate where your objects should be, afterwards you handle the drawing by just looping through the objects and only use setLeft() and setTop() once instead of every update.
    2. Yes, it will save you one operation.

    Maybe there is something else that could be optimized. Instead of using a matrix operation like RotateTransform() which is very CPU intensive, you could save a lot of computing power by saving the current rotational status in the shape object. Also using vectors would probably help you improve performance.

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

Sidebar

Related Questions

The code below gets the information i require from my database but is not
The code below gets a list of all the .csv files in a directory.
The code below gets the username/password and runs it thru the backend.php script. <?php
The code pasted below gets an exception on the line that says... InputStream in
I have below is the html code for TD which gets appended after matching
Code below is used to save PostgreSql database backup from browser in Apache Mono
This code below allows me to find the word error in all my files
The code below is the comments template from my functions.php in WP. It outputs
please refer to the code below. $dArr = '<script>document.write(volunteerDist);</script>'; $dArr gets the value of
In the Code below I am trying to recreate scanf to read everything from

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.