• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

304 Neutral

About johnmarinelli

  • Rank
  1. Hey guys,   So I am messing around with the Curiously Recurring Template Pattern, and was wondering:   is there a way to access a 'base class' that uses CRTP to call functions?   for example: template<typename C> class Entity { private: //helper function for polymorphic functions C* getChild() { return static_cast<C*>(this); } public: Entity() {} void paint() { getChild()->display(); } } //... //another question: can vectors hold templated types? template<typename T> std::vector< Entity<T>* > entities; int main() { for(auto i : entities){ i->paint(); } } i'm trying something similar and it's not working.   this is the only stackoverflow question i could find that is related: http://stackoverflow.com/questions/16527673/c-one-stdvector-containing-template-class-of-multiple-types   Note: I'm not actually deving, but am playing around with the CRTP to learn it.  Otherwise I'd strongly adhere to KISS
  2. Sam's Teach Yourself Data Structures And Algorithms in 24 Hours.    Don't be put off by title - I think it's  a great introduction to DS & A, and its implementations are in C++.  It goes over the common sorts, trees/balanced trees, and hashing.   All the other books that people posted are quality, but I (personally) don't think they're suitable for a first DS & A book.
  3. Concept for making a state manager

    It looks like you're on the right track to me - however, I'm confused as to why you would make a StateManager class with a vector of states in it?  Couldn't you just put a BaseState* in your world object, and then in your world.update you call BaseStatePointer->update(), etc?   It just looks like a (possibly) unnecessary level of encapsulation to me, but your big picture seems good.  This article really helped me understand state machines; although it's implemented with SDL, I think you'll be able to grasp it:   http://lazyfoo.net/articles/article06/index.php
  4. Wow, I really didn't expect this thread to get so many replies!  My apologies for not responding earlier, this week has been really busy.   @NightCreature83, very useful link!  I'm excited to go through the archives.   @_greyfox() & Khatharr, I have learned a very small amount of Assembly, but only for a class.  Although knowing relatively little about it, I do feel like I have a better handle of what's going on when I'm debugging. I thrive off of self-learning, and the book you recommended looks ideal for my situation.  I'll be buying that one along with Stroustrups' book.   @Álvaro, well, until reading this thread, my honest answer would be one of "shallow knowledge" .  I've always found that designs involving generally uncommon tools (like 'volatile' in C++), are best avoided unless really needed; however, I do appreciate the question and the knowledge that comes with its answer. It's exactly what I'm looking for!
  5. Hello,   So after going through these slides (they're very interesting, btw!  I suggest you go through them), I realized that my knowledge of C/C++ isn't as deep as I thought.    Does anyone with a very concrete understanding of C/C++ have any advice for becoming more like the girl character?  Any book recommendations/practices?  I know that simply programming every day is the first step, but I'd like to supplement my programming with any extra information I can get.
  6. Alright, thanks!  I'm not very familiar with websites (obvioiusly), but I'll keep your idea in mind when I'm ready to get a domain name.
  7. Hi all,   Right now, I'm working on my portfolio presentation.  I plan on buying my own website domain and all that, so I'd like to put unrelated content on the website (for example, I'm a musician, so I want to post sheet music and mp3s) up as well.   My only concern is that may be seem unprofessional; however, I'd much rather have all my content on one website rather than pay for two websites.   What are your thoughts? Thanks!
  8. I'm fully aware that there are plenty of editors - I'd just like to write a really simple one myself.   @DekuTree64, could you explain more about transferring the SDL buffer to a map window?
  9. Hi all,   As the title suggests, I plan on making a pretty simple 2D level editor with SDL for rendering and wxWidgets for the GUI.   I've used SDL before, but I haven't used wxWidgets.   The biggest question to me is which library should handle the window?  I imagine that I should let wxWidgets handle the window and let SDL render inside - would this be too complicated?   I'm open to any alternative suggestions.   Thanks!
  10. Hi all,   I have a couple simple applications built with OpenGL and SDL respectively.  I built them in VS2010, and would like them to work on the mac and unix OS.   I'm following the CMake tutorial on this site, but so far it seems like CMake is more for programmers sharing code across different platforms - am I wrong in this assumption?  How can I use CMake to make a release build work on an OS other than Windows?
  11. Hi everyone, I know this question has been asked a few times before, but I still can't get my program to work.   I'm working on an Asteroids clone in OpenGL, and I'm starting off by simply getting my spaceship to move around.  I also have 4 quads set up in each respective corner so I know if the movement is working or not.   However, it seems like I'm moving the quads around, and not my spaceship.  Here's the code: void renderScene() { glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); gSpaceship.render(); glPopMatrix(); glPushMatrix(); //move to bottom right corner glTranslatef(SPACE_WIDTH / 2.f, SPACE_HEIGHT / 2.f, 0.f); glBegin(GL_QUADS); glColor3f(0.f, 1.f, 0.f); glVertex2f(0.f, 0.f); glVertex2f(50.f, 0.f); glVertex2f(50.f, 50.f); glVertex2f(0.f, 50.f); glEnd(); //move to bottom left corner glTranslatef(-SPACE_WIDTH, 0.f, 0.f); glBegin(GL_QUADS); glColor3f(0.f, 0.f, 1.f); glVertex2f(0.f, 0.f); glVertex2f(50.f, 0.f); glVertex2f(50.f, 50.f); glVertex2f(0.f, 50.f); glEnd(); //move to top left corner glTranslatef(0.f, -SPACE_HEIGHT, 0.f); glBegin(GL_QUADS); glColor3f(1.f, 1.f, 1.f); glVertex2f(0.f, 0.f); glVertex2f(50.f, 0.f); glVertex2f(50.f, 50.f); glVertex2f(0.f, 50.f); glEnd(); //move to top right corner glTranslatef(SPACE_WIDTH, 0.f, 0.f); glBegin(GL_QUADS); glColor3f(1.f, 0.f, 1.f); glVertex2f(0.f, 0.f); glVertex2f(50.f, 0.f); glVertex2f(50.f, 50.f); glVertex2f(0.f, 50.f); glEnd(); glPopMatrix(); glFlush(); glutSwapBuffers(); } and heres' gSpaceship.render(), and consequently, JTexture.render(): void Spaceship::render() { //mGraphics is a JTexture //m_xPos and m_yPos start out in the center of the 4 quads mGraphics.render(m_xPos, m_yPos); } void JTexture::render(GLfloat x, GLfloat y) { if (mTextureID != 0) { glTranslatef(x, y, 0.f); glBindTexture(GL_TEXTURE_2D, mTextureID); glBegin(GL_QUADS); glTexCoord2f(0.f, 0.f); glVertex2f(0.f, 0.f ); glTexCoord2f(1.f, 0.f); glVertex2f(mTextureWidth, 0.f ); glTexCoord2f(1.f, 1.f); glVertex2f(mTextureWidth, mTextureHeight); glTexCoord2f(0.f, 1.f); glVertex2f(0.f, mTextureHeight); glEnd(); } } also, I'd like to eventually be able to rotate the texture and move in the direction its facing; I know how to rotate a texture, but I know I will be very lost when it comes to moving in a direction thats not axis-aligned.  How does one go about this?   Thanks a lot!
  12. Of course it's a simple answer! Thanks very much!
  13. Hello everyone,   I'm working on a little exercise program that takes a matrix and a vector and performs algebra on them. I'm using templates for both my 4x4 matrix class and my vector4 class. My matrix4x4 class serves as a parent to specific types of matrices, like a translation matrix.   The program gives me an error when I instantiate a matrix4x4 class with no parameters and try to operate on it, even though I fill the values of the object in an empty constructor: vector4<T> translateVector(const matrix4x4<T> matrix, const vector4<T> vector) { matrix4x4<T> tempMatrix(); for (int row = 0; row < MAX_LENGTH; ++row) { for (int column = 0; column < MAX_LENGTH; ++column) { tempMatrix[row][column] = (matrix[row][column] * vector[row]); //I get errors on this line and the one below newVector[row] += tempMatrix[row][column]; } } } //in matrix4x4.h: template <typename T> class matrix4x4 { public: T values[MAX_LENGTH][MAX_LENGTH]; matrix4x4() //when using this ctor, the compiler tells me I need to have a pointer to complete object type { for (int i = 0; i < MAX_LENGTH; i++) { for (int j = 0; j < MAX_LENGTH; j++) { values[i][j] = 0; } } }; T* operator[](int index)     {         assert (index > -1 && index < MAX_LENGTH);         return values[index];     }; However, I fixed the problem by simply adding this ctor to the matrix4x4 class:   matrix4x4(T x) //this does exactly the same thing as empty ctor, just has a parameter { for (int i = 0; i < MAX_LENGTH; i++) { for (int j = 0; j < MAX_LENGTH; j++) { values[i][j] = 0; } } }; I feel like this is a bad patch to a larger problem I should address, but I'm not sure what that problem is or how to fix it. Is it just a part of C++ to consider a templated object with an empty ctor to be "incomplete"?
  14. Hi all,   I'd like my app to let the user take or choose a picture, have that picture saved in the memory, and be able to edit the picture via the URI.   Here's a general outline: In the main activity: take a picture or choose a picture from library, and send the URI to editing activity public void openCamera(View view) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); } public void openLibrary(View view) { Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, LIBRARY_PIC_REQUEST); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { Uri path = data.getData(); Intent intent = new Intent(this, StickerActivity.class); intent.putExtra(EXTRA_MESSAGE, path); startActivity(intent); } In editing activity: drawClass is a custom View class protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_editing); drawClass = (DrawClass) findViewById(R.id.myDrawClass); Bundle retrievedExtras = getIntent().getExtras(); int stickerType = retrievedExtras.getInt(StickerActivity.SELECTED_MESSAGE); Uri picturePath = retrievedExtras.getParcelable(MainActivity.EXTRA_MESSAGE); drawClass.setStickerType(stickerType); ..... in drawClass.java: drawClass extends screen, and I'm currently able to view the picture that the user chose by resizing the image.  However this makes the image skewed and uneven; I'd like to have the picture be the same resolution and dimensions as the preview is. private Bitmap getResizedBitmap(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = ((float) this.viewWidth) / width; float scaleHeight = ((float) this.viewHeight) / height; // create a matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // recreate the new Bitmap Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false); return resizedBitmap; } public void setChosenPicture(Bitmap bitmap) { this.chosenPicture = this.getResizedBitmap(bitmap); } So, right now I'm successfully displaying a resized version of the chosen picture to fit the whole screen, which makes it skewed and awkward.  I'd like to retrieve the same picture that gets displayed in the preview after taking a picture, send it through an activity, and display it on a custom view.   Also, I plan on making buttons such as "Save"and "Clear" at the bottom of the picture in a small horizontal frame (for example, 1/10th of the screen height and all of the screen width); would I have to make another View class on top of the drawClass to do this?
  15. Hi all,   I have an Activity that will have many different ImageButtons.  I want the user to be able to select one as his choice (it's a sticker app), and continue to the next activity with this choice.   My question is, is there a way to implement only one onClick() method for all the buttons, and distinguish which button the user chose by an ID?  for example, if the user selects button2, can I somehow pass the id of button2 to the onClick method in the activity?   The reason for doing this is to prevent repetitive code; the other way to do it is to implement an onClick() method for each sticker, which I think would turn out ugly.   Thanks!
  • Advertisement