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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:59:19+00:00 2026-05-28T05:59:19+00:00

Context: I’m making a simple solar system simulation in c++/OpenGL. Research: I’ve tried searching

  • 0

Context: I’m making a simple solar system simulation in c++/OpenGL.

Research: I’ve tried searching but I only ever find articles on widgets and flash and HCI stuff.

Problem: I’d like the user to be able to click on an actor, and then maybe deselect, or select something else. Maybe select multple actors at once. If the actor is destroyed, I’d like the selection to go away. I’d like the actor to know it’s been selected.

I know how to get the mouse coordinates, and how to see if a click happened on this actor or that actor, or the closest actor. What I don’t have any experience doing is modelling the interaction. I can think of something like CSS’s model of active, hover, and pressed, so some sort of state, I guess. But then I get into the problem of ownership, and what happens if that actor is deleted or needs to be deleted? Should there be some sort of observer?

Obviously I don’t understand the problem enough to try and solve it for my purposes. I have no experience with callbacks or events or whatever. Can anyone point me to some articles, guides, or similar help?

  • 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-05-28T05:59:20+00:00Added an answer on May 28, 2026 at 5:59 am

    If you are using smart pointers for your actors (e.g. boost::shared_pointer) then you can solve the ownership problem easily by using weak pointers for your selection. For example:

    std::set<boost::weak_pointer<Actor> >  selected_actors;
    

    You just need to be aware that any pointer you retrieve from that set might be invalid, but Boost pretty much forces you to check that.


    For the actor to know when it’s selected, I would just make some virtual member functions that are called by your selection code, e.g.:

    class Actor {
    public:
      ...
      virtual void on_selected() { }
      virtual void on_deselected() { }
      ...
    };
    

    If you also need the actor to keep track of whether it’s selected, do it like this:

    class Actor {
    bool selected;
    public:
      Actor() : selected(false) { }
      ...
      void selected() { selected = true; on_selected(); } // not virtual
      void deselected() { selected = false; on_deselected(); } // not virtual
      ...
    protected:
      ...
      virtual void on_selected() { }
      virtual void on_deselected() { }
    };
    

    Hope that helps!

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

Sidebar

Related Questions

Context: I notice that the major databases support only the Gregorian calendar. Thus, it
Context: I'm working with a relatively simple winforms application, written in VB.NET on the
Context I would like to integrate [MediaWiki][1] as a helping tool to my system.
I'm making a simple page using Google Maps API 3. My first. One marker
Context I want to display Twitter and Facebook buttons on my new site. But
Context: I'm in charge of running a service written in .NET. Proprietary application. It
Context: So, I am attempting to build a ridiculously complex domain model. Talking with
Context: I have a WPF App that uses certain unmanaged DLLs in the D:\WordAutomation\MyApp_Source\Executables\MyApp
Context : programming a c/c++ win32-mfc library How to know whether we are in
Context PHP 5.3.x Overview After doing a code-review with an associate who uses both

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.