LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to simulate car driving along sinus shaped curve?

I want to import a picture of a car and make it move along different curves (sinus, triangle etc.) in an xy-graph like in a video game. How do I, in the easiest way, make the car tilt so that it looks as if it's actually driving on the road?
0 Kudos
Message 1 of 11
(4,622 Views)
I made a very simple vi that shoud sow you the way, how to do this.
Draw your picture in a paint programm, copy and paste it on the front
panel of an blank vi. Create a control like a boolean, right click on the
control, choose advanced, customize. In this new window paste your picture
over the control. Close this window and choose replace.

Hope it helps

Greetings

Tom
0 Kudos
Message 2 of 11
(4,605 Views)
Thank you, Tom, for your answer!
Actually I had already reached that far, so my problem now is to rotate (tilt) an object. But if I don't find a way to do this I guess I can always choose a symmetric object...
0 Kudos
Message 3 of 11
(4,598 Views)
You can do this with a 2-d model of a car. Represent the car with a 2d matrix with the points representing x,y verticies of the car model. Make the verticies relative to the center of the car, this way you can draw the car as a vector graphic and not a simple bit-image. Now you can pass the 2-d vector model through a rotation matrix then translate the coordinates to simulate motion and tilt. This is a flexible (but math intensive) method for graphics. Using vector graphics, rotation scale, and translation are easy and the model of the car can be developed to evolve with more detail as needed. This approach is used in modern video games, icon, bitmapped graphics were left in the 80's with the Atari. OpenGL and DirectX scale this approach to 3-d and add material and light effects to boot.

-Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 4 of 11
(4,583 Views)
Additional advantages to vector based graphics are that they have unlimited poses (rotations) while bitmapped icons require a copy saved to memory for each pose. Also when drawing a vector image, scaling and rotation effects can incorperate antialliasing right into the render engine. You can use a picture control to draw the morphed (rotated and translated model).
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 5 of 11
(4,584 Views)
I'm guessing the level of expertise it would take to do this is probably beyond what you really want to be dealing with, but here's a suggestion with the given assumption that you may not find an easier way (and if you do--please use it by all means!). Manipulating graphics is math, all math, and nothing but math. If it's not, it still is, and the only reason it wouldn't be is if someone else has done the math for you--probably what you're looking for.

If it were me I'd use a picture control. You can draw anything in a picture control, any way you want to. In the simplest of implementations, you can load a bitmap from a file and place it on the image wherever you want. Also using a picture control, you can do your drawing (as in, rendering the image--putting the background and bitmap overlays together) in memory--before it's updated to the screen, so that when it is updated, it looks smooth. Back to the problem though...

If you read a bitmap from disk it's just an array of numbers. What you would have to do then is matrix math (not for the faint of heart I guess if you're not too math-oriented, but not impossible either). Rotating the image and placing it on the display would just be a matter of rotating the points in the matrix. Probably easier said than done, but better than no forseeable solution.

Another option less flexible but also much less complex would be to have a limited number of rotated bitmaps that you use... that might work well also. All work done rotating the images would be done beforehand. Pull your image into any kind program (there are lots of them) that can rotate and save a set of images. This would let you index an array of images by rotation angle and place that image at the desired location. Granted... if you want it to be at some odd rotation angle then the first option might work better, but this would work for a simple game or display. Otherwise you wind up having to make a bunch of images to get any angle you want--ie, the # images = 360 / angle -> # images goes up drastically the smaller the angle difference between pictures. That would also take more memory to hold them all, as compared to the first option where you're just rotating an array and coming up with another array.
0 Kudos
Message 6 of 11
(4,564 Views)
Rotating a small image is simple, you can probably adapt my code shown here for your purpose.

Basically, you would create a picture control and a 2D array containing the background terrain. Now you would rotate and translate the small image using my code and replace the relevant array elements with the car image for each frame display. 🙂
Message 7 of 11
(4,559 Views)
Here is an example of a car that can be rotated in vector graphics, I only spent a few minutes on it so sorry about the crude graphics. It will however show you scale translation and rotation in a 2d rigid body with verticies about a center of mass. You can use this as a starting point to get very good quality fast graphics in a picture control. 2d graphics are very easy and need little math to understand (dont really need to know matricies since the solved equation can be used for a transformation).

Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 8 of 11
(4,537 Views)
A few notes on my attached vi:

1. Picture controls have an origin of 0,0 at the top left corner. The Y axis gets larger as you go down the screen, this is the opposite of the common geometric world coordinates. You can add a geometric world transformation by inverting all Y points, Y= -Y, and centering the world by adding half height and half width of the picture control to the X and Y coordinated of each point. Again this is just a crude demonstration of the power of vector graphics. I can update and clean up the code if needed but probably not until the weekend. Good luck coding.
-Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 9 of 11
(4,534 Views)
Thank you all for your answers! I'm about to improve my application!

/Nina
0 Kudos
Message 10 of 11
(4,381 Views)